|
|
@@ -1,29 +1,122 @@
|
|
|
import { NodeUpdateType } from './constants.js';
|
|
|
|
|
|
+/**
|
|
|
+ * Management class for updating nodes. The module tracks metrics like
|
|
|
+ * the elapsed time, delta time, the render and frame ID to correctly
|
|
|
+ * call the node update methods {@link Node#updateBefore}, {@link Node#update}
|
|
|
+ * and {@link Node#updateAfter} depending on the node's configuration.
|
|
|
+ */
|
|
|
class NodeFrame {
|
|
|
|
|
|
+ /**
|
|
|
+ * Constructs a new node fame.
|
|
|
+ */
|
|
|
constructor() {
|
|
|
|
|
|
+ /**
|
|
|
+ * The elapsed time in seconds.
|
|
|
+ *
|
|
|
+ * @type {Number}
|
|
|
+ * @default 0
|
|
|
+ */
|
|
|
this.time = 0;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * The delta time in seconds.
|
|
|
+ *
|
|
|
+ * @type {Number}
|
|
|
+ * @default 0
|
|
|
+ */
|
|
|
this.deltaTime = 0;
|
|
|
|
|
|
+ /**
|
|
|
+ * The frame ID.
|
|
|
+ *
|
|
|
+ * @type {Number}
|
|
|
+ * @default 0
|
|
|
+ */
|
|
|
this.frameId = 0;
|
|
|
- this.renderId = 0;
|
|
|
|
|
|
- this.startTime = null;
|
|
|
+ /**
|
|
|
+ * The render ID.
|
|
|
+ *
|
|
|
+ * @type {Number}
|
|
|
+ * @default 0
|
|
|
+ */
|
|
|
+ this.renderId = 0;
|
|
|
|
|
|
+ /**
|
|
|
+ * Used to control the {@link Node#update} call.
|
|
|
+ *
|
|
|
+ * @type {WeakMap}
|
|
|
+ */
|
|
|
this.updateMap = new WeakMap();
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Used to control the {@link Node#updateBefore} call.
|
|
|
+ *
|
|
|
+ * @type {WeakMap}
|
|
|
+ */
|
|
|
this.updateBeforeMap = new WeakMap();
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Used to control the {@link Node#updateAfter} call.
|
|
|
+ *
|
|
|
+ * @type {WeakMap}
|
|
|
+ */
|
|
|
this.updateAfterMap = new WeakMap();
|
|
|
|
|
|
+ /**
|
|
|
+ * A reference to the current renderer.
|
|
|
+ *
|
|
|
+ * @type {Renderer?}
|
|
|
+ * @default null
|
|
|
+ */
|
|
|
this.renderer = null;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * A reference to the current material.
|
|
|
+ *
|
|
|
+ * @type {Material?}
|
|
|
+ * @default null
|
|
|
+ */
|
|
|
this.material = null;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * A reference to the current camera.
|
|
|
+ *
|
|
|
+ * @type {Camera?}
|
|
|
+ * @default null
|
|
|
+ */
|
|
|
this.camera = null;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * A reference to the current 3D object.
|
|
|
+ *
|
|
|
+ * @type {Obbject3D?}
|
|
|
+ * @default null
|
|
|
+ */
|
|
|
this.object = null;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * A reference to the current scene.
|
|
|
+ *
|
|
|
+ * @type {Scene?}
|
|
|
+ * @default null
|
|
|
+ */
|
|
|
this.scene = null;
|
|
|
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Returns a dictionary for a given node and update map which
|
|
|
+ * is used to correctly call node update methods per frame or render.
|
|
|
+ *
|
|
|
+ * @private
|
|
|
+ * @param {WeakMap} referenceMap - The reference weak map.
|
|
|
+ * @param {Node} nodeRef - The reference to the current node.
|
|
|
+ * @return {Object<String,WeakMap>} The dictionary.
|
|
|
+ */
|
|
|
_getMaps( referenceMap, nodeRef ) {
|
|
|
|
|
|
let maps = referenceMap.get( nodeRef );
|
|
|
@@ -43,6 +136,14 @@ class NodeFrame {
|
|
|
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * This method executes the {@link Node#updateBefore} for the given node.
|
|
|
+ * It makes sure {@link Node#updateBeforeType} is honored meaning the update
|
|
|
+ * is only executed once per frame, render or object depending on the update
|
|
|
+ * type.
|
|
|
+ *
|
|
|
+ * @param {Node} node - The node that should be updated.
|
|
|
+ */
|
|
|
updateBeforeNode( node ) {
|
|
|
|
|
|
const updateType = node.getUpdateBeforeType();
|
|
|
@@ -84,6 +185,14 @@ class NodeFrame {
|
|
|
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * This method executes the {@link Node#updateAfter} for the given node.
|
|
|
+ * It makes sure {@link Node#updateAfterType} is honored meaning the update
|
|
|
+ * is only executed once per frame, render or object depending on the update
|
|
|
+ * type.
|
|
|
+ *
|
|
|
+ * @param {Node} node - The node that should be updated.
|
|
|
+ */
|
|
|
updateAfterNode( node ) {
|
|
|
|
|
|
const updateType = node.getUpdateAfterType();
|
|
|
@@ -125,6 +234,14 @@ class NodeFrame {
|
|
|
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * This method executes the {@link Node#update} for the given node.
|
|
|
+ * It makes sure {@link Node#updateType} is honored meaning the update
|
|
|
+ * is only executed once per frame, render or object depending on the update
|
|
|
+ * type.
|
|
|
+ *
|
|
|
+ * @param {Node} node - The node that should be updated.
|
|
|
+ */
|
|
|
updateNode( node ) {
|
|
|
|
|
|
const updateType = node.getUpdateType();
|
|
|
@@ -166,6 +283,10 @@ class NodeFrame {
|
|
|
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Updates the internal state of the node frame. This method is
|
|
|
+ * called by the renderer in its internal animation loop.
|
|
|
+ */
|
|
|
update() {
|
|
|
|
|
|
this.frameId ++;
|