Skip to content

Commit

Permalink
simplified value nodes
Browse files Browse the repository at this point in the history
- merged ValueStore and TriggerValueStore into ValueNode
  • Loading branch information
ptc-rdeleeuw committed Jun 17, 2024
1 parent b5775c7 commit 71a4406
Show file tree
Hide file tree
Showing 30 changed files with 264 additions and 275 deletions.
2 changes: 1 addition & 1 deletion libraries/objectDefaultFiles/scene/BaseNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class BaseNode {
*
* @param {string} type
*/
constructor(type, name = "") {
constructor(type) {
this.#type = type;
this.#isTypeDirty = false;
this.#parent = null;
Expand Down
12 changes: 6 additions & 6 deletions libraries/objectDefaultFiles/scene/ColorNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ class ColorNode extends ObjectNode {
* @param {ColorValue} value
*/
setValue(value) {
this.get("r").set(value.r);
this.get("g").set(value.g);
this.get("b").set(value.b);
this.get("r").value = value.r;
this.get("g").value = value.g;
this.get("b").value = value.b;
}

/**
Expand All @@ -34,9 +34,9 @@ class ColorNode extends ObjectNode {
*/
getValue() {
return {
"r": this.get("r").get(),
"g": this.get("g").get(),
"b": this.get("b").get()
"r": this.get("r").value,
"g": this.get("g").value,
"b": this.get("b").value
};
}
}
Expand Down
7 changes: 3 additions & 4 deletions libraries/objectDefaultFiles/scene/ColorStore.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import ObjectStore from "./ObjectStore.js";
import ValueNode from "./ValueNode.js";
import ValueStore from "./ValueStore.js";

/**
* @typedef {import("./ObjectNode.js").NodeDict} NodeDict
Expand Down Expand Up @@ -28,9 +27,9 @@ class ColorStore extends ObjectStore {
*/
getProperties(_thisNode) {
return {
"r": new ValueNode(new ValueStore(this.#initValues.r)),
"g": new ValueNode(new ValueStore(this.#initValues.g)),
"b": new ValueNode(new ValueStore(this.#initValues.b))
"r": new ValueNode(this.#initValues.r),
"g": new ValueNode(this.#initValues.g),
"b": new ValueNode(this.#initValues.b)
};
}
}
Expand Down
5 changes: 2 additions & 3 deletions libraries/objectDefaultFiles/scene/DictionaryStore.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import DictionaryNode from "./DictionaryNode.js";
import ValueNode from "./ValueNode.js";
import VersionedNode from "./VersionedNode.js";
import ValueStore from "./ValueStore.js";

/**
* @typedef {import("./ObjectNode").ObjectNodeState} ObjectNodeState
Expand Down Expand Up @@ -35,15 +34,15 @@ class DictionaryStore {
if (!state.hasOwnProperty("value")) {
throw Error("Can't create ValueNode without initial value");
}
return new ValueNode(new ValueStore(state.value), state.type);
return new ValueNode(state.value, state.type);
} else if (state.type.startsWith("Versioned")) {
if (!state.hasOwnProperty("value")) {
throw Error("Can't create VaersionedNode without initial value");
}
if (!state.hasOwnProperty("version")) {
throw Error("Can't create VersionedNode without initial version");
}
return new VersionedNode(new ValueStore(state.value), state.type, null, state.version);
return new VersionedNode(state.value, state.type, state.version);
} else {
throw Error("Can't create property with type: " + state.type);
}
Expand Down
16 changes: 8 additions & 8 deletions libraries/objectDefaultFiles/scene/EulerAnglesNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ class EulerAnglesNode extends ObjectNode {
* @param {EulerAnglesValue} value
*/
setValue(value) {
this.get("x").set(value.x);
this.get("y").set(value.y);
this.get("z").set(value.z);
this.get("order").set(value.order);
this.get("x").value = value.x;
this.get("y").value = value.y;
this.get("z").value = value.z;
this.get("order").value = value.order;
}

/**
Expand All @@ -35,10 +35,10 @@ class EulerAnglesNode extends ObjectNode {
*/
getValue() {
return {
"x": this.get("x").get(),
"y": this.get("y").get(),
"z": this.get("z").get(),
"order": this.get("order").get()
"x": this.get("x").value,
"y": this.get("y").value,
"z": this.get("z").value,
"order": this.get("order").value
};
}
}
Expand Down
9 changes: 4 additions & 5 deletions libraries/objectDefaultFiles/scene/EulerAnglesStore.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import ObjectStore from "./ObjectStore.js";
import ValueNode from "./ValueNode.js";
import ValueStore from "./ValueStore.js";

/**
* @typedef {import("./ObjectNode.js").NodeDict} NodeDict
Expand Down Expand Up @@ -28,10 +27,10 @@ class EulerAnglesStore extends ObjectStore {
*/
getProperties(_thisNode) {
return {
"x": new ValueNode(new ValueStore(this.#initValues.x)),
"y": new ValueNode(new ValueStore(this.#initValues.y)),
"z": new ValueNode(new ValueStore(this.#initValues.z)),
"order": new ValueNode(new ValueStore(this.#initValues.order))
"x": new ValueNode(this.#initValues.x),
"y": new ValueNode(this.#initValues.y),
"z": new ValueNode(this.#initValues.z),
"order": new ValueNode(this.#initValues.order)
};
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class GLTFLoaderComponentNode extends BaseComponentNode {
}

setUrl(url) {
this.get("url").set(url);
this.get("url").value = url;
}

setEntityNode(node) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import ObjectStore from "./ObjectStore.js";
import VersionedNode from "./VersionedNode.js";
import ValueStore from "./ValueStore.js";

/**
* @typedef {import("./ObjectNode.js").NodeDict} NodeDict
Expand All @@ -23,7 +22,7 @@ class GLTFLoaderComponentStore extends ObjectStore {
*/
getProperties(_thisNode) {
return {
"url": new VersionedNode(new ValueStore(""))
"url": new VersionedNode("")
};
}

Expand Down
3 changes: 1 addition & 2 deletions libraries/objectDefaultFiles/scene/MaterialComponentStore.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import ObjectStore from "./ObjectStore.js";
import ValueNode from "./ValueNode.js";
import ValueStore from "./ValueStore.js";
import DictionaryNode from "./DictionaryNode.js";
import DictionaryStore from "./DictionaryStore.js";

Expand All @@ -11,7 +10,7 @@ class MaterialComponentStore extends ObjectStore {

getProperties() {
return {
"material": new ValueNode(new ValueStore()),
"material": new ValueNode(""),
"properties": new DictionaryNode(new DictionaryStore())
};
}
Expand Down
16 changes: 8 additions & 8 deletions libraries/objectDefaultFiles/scene/QuaternionNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ class QuaternionNode extends ObjectNode {
* @param {QuaternionValue} value
*/
setValue(value) {
this.get("x").set(value.x);
this.get("y").set(value.y);
this.get("z").set(value.z);
this.get("w").set(value.w);
this.get("x").value = value.x;
this.get("y").value = value.y;
this.get("z").value = value.z;
this.get("w").value = value.w;
}


Expand All @@ -37,10 +37,10 @@ class QuaternionNode extends ObjectNode {
*/
getValue() {
return {
"x": this.get("x").get(),
"y": this.get("y").get(),
"z": this.get("z").get(),
"w": this.get("w").get()
"x": this.get("x").value,
"y": this.get("y").value,
"z": this.get("z").value,
"w": this.get("w").value
};
}
}
Expand Down
9 changes: 4 additions & 5 deletions libraries/objectDefaultFiles/scene/QuaternionStore.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import ObjectStore from "./ObjectStore.js";
import ValueNode from "./ValueNode.js";
import ValueStore from "./ValueStore.js";

/**
* @typedef {import("./ObjectNode.js").NodeDict} NodeDict
Expand All @@ -27,10 +26,10 @@ class QuaternionStore extends ObjectStore {
*/
getProperties(_node) {
return {
"x": new ValueNode(new ValueStore(this.#initValues.x)),
"y": new ValueNode(new ValueStore(this.#initValues.y)),
"z": new ValueNode(new ValueStore(this.#initValues.z)),
"w": new ValueNode(new ValueStore(this.#initValues.w))
"x": new ValueNode(this.#initValues.x),
"y": new ValueNode(this.#initValues.y),
"z": new ValueNode(this.#initValues.z),
"w": new ValueNode(this.#initValues.w)
};
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import ObjectNode from "./ObjectNode.js";
import SimpleAnimationComponentStore from "./SimpleAnimationComponentStore.js";

/**
* @typedef {import("../three/addons/Timer.js").Timer} Timer
* @typedef {import("../three/addons/DateTimer.js").Timer} Timer
* @typedef {import("./Vector3Node").Vector3Value} Vector3Value;
* @typedef {number} Seconds
* @typedef {(timestamp: Seconds) => Vector3Value} animationFunc
Expand Down Expand Up @@ -82,19 +82,19 @@ class SimpleAnimationComponentNode extends ObjectNode {
sample = this.#animation(timestamp);
if (this.#isInitialized) {
this.get("oldSample").setValue(this.get("newSample").getValue());
this.get("oldTimestamp").set(this.get("newTimestamp").get());
this.get("oldTimestamp").value = this.get("newTimestamp").value;
} else {
this.get("oldSample").setValue(sample);
this.get("oldTimestamp").set(timestamp - 1);
this.get("oldTimestamp").value = timestamp - 1;
this.#isInitialized = true;
}
this.get("newSample").setValue(sample);
this.get("newTimestamp").set(timestamp);
this.get("newTimestamp").value = timestamp;
} else {
const oldSample = this.get("oldSample").getValue();
const oldTimestamp = this.get("oldTimestamp").get();
const oldTimestamp = this.get("oldTimestamp").value;
const newSample = this.get("newSample").getValue();
const newTimestamp = this.get("newTimestamp").get();
const newTimestamp = this.get("newTimestamp").value;
const interp = (timestamp - oldTimestamp) / (newTimestamp - oldTimestamp);
sample.x = oldSample.x + (interp * (newSample.x - oldSample.x));
sample.y = oldSample.y + (interp * (newSample.y - oldSample.y));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,22 @@ import ObjectStore from "./ObjectStore.js";
import Vector3Node from "./Vector3Node.js";
import Vector3Store from "./Vector3Store.js";
import ValueNode from "./ValueNode.js";
import ValueStore from "./ValueStore.js";

class SimpleAnimationComponentStore extends ObjectStore {
constructor() {
super();
}

/**
*
* @returns {{oldSample: Vector3Node, oldTimestamp: ValueNode<number>, newSample: Vector3Node, newTimestamp: ValueNode<number>}}
*/
getProperties() {
return {
"oldSample": new Vector3Node(new Vector3Store()),
"oldTimestamp": new ValueNode(new ValueStore(0)),
"oldTimestamp": new ValueNode(0),
"newSample": new Vector3Node(new Vector3Store()),
"newTimestamp": new ValueNode(new ValueStore(0))
"newTimestamp": new ValueNode(0)
};
}
}
Expand Down
18 changes: 9 additions & 9 deletions libraries/objectDefaultFiles/scene/TextureStore.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import ObjectStore from "./ObjectStore.js";
import ValueNode from "./ValueNode.js";
import ValueStore from "./ValueStore.js";
import {UVMapping, ClampToEdgeWrapping, LinearFilter} from "../../thirdPartyCode/three/three.module.js";

/**
* @typedef {import("./ObjectNode.js").NodeDict} NodeDict
* @typedef {import("./TextureNode.js").default} TextureNode
* @typedef {import("./TextureNode.js").TextureValue} TextureValue
* @typedef {string} resourceId
*/

class TextureStore extends ObjectStore {
Expand All @@ -25,17 +25,17 @@ class TextureStore extends ObjectStore {
/**
* @override
* @param {TextureNode} _thisNode
* @returns {{id: ValueNode}}
* @returns {{id: ValueNode<resourceId>, mapping: ValueNode<number>, wrapS: ValueNode<number>, wrapT: ValueNode<number>, magFilter: ValueNode<number>, minFilter: ValueNode<number>, anisotropy: ValueNode<number>}}
*/
getProperties(_thisNode) {
return {
"id": new ValueNode(new ValueStore(this.#initValues.id)),
"mapping": new ValueNode(new ValueStore(this.#initValues.mapping)),
"wrapS": new ValueNode(new ValueStore(this.#initValues.wrapS)),
"wrapT": new ValueNode(new ValueStore(this.#initValues.wrapT)),
"magFilter": new ValueNode(new ValueStore(this.#initValues.magFilter)),
"minFilter": new ValueNode(new ValueStore(this.#initValues.minFilter)),
"anisotropy": new ValueNode(new ValueStore(this.#initValues.anisotropy))
"id": new ValueNode(this.#initValues.id),
"mapping": new ValueNode(this.#initValues.mapping),
"wrapS": new ValueNode(this.#initValues.wrapS),
"wrapT": new ValueNode(this.#initValues.wrapT),
"magFilter": new ValueNode(this.#initValues.magFilter),
"minFilter": new ValueNode(this.#initValues.minFilter),
"anisotropy": new ValueNode(this.#initValues.anisotropy)
};
}
}
Expand Down
2 changes: 1 addition & 1 deletion libraries/objectDefaultFiles/scene/Tool3D.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ class Tool3D {
if (this.#toolNode) {
const component = this.#toolNode.getComponentByType(VisibilityComponentNode.TYPE);
if (component) {
component.set(isVisible);
component.value = isVisible;
}
}
}
Expand Down
33 changes: 0 additions & 33 deletions libraries/objectDefaultFiles/scene/TriggerValueStore.js

This file was deleted.

3 changes: 1 addition & 2 deletions libraries/objectDefaultFiles/scene/ValueComponentNode.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import ValueNode from "./ValueNode.js";
import ValueStore from "./ValueStore.js";

class ValueComponentNode extends ValueNode {
constructor(value, type) {
super(new ValueStore(value), type);
super(value, type);
}

/**
Expand Down
Loading

0 comments on commit 71a4406

Please sign in to comment.