Skip to content
Draft
5 changes: 1 addition & 4 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,7 @@ module.exports = {
'warn',
4
],
'linebreak-style': [
'error',
'unix'
],
'linebreak-style': 0,
'quotes': 'off',
'semi': [
'warn',
Expand Down
1 change: 1 addition & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const config = {
coveragePathIgnorePatterns: ["/node_modules/", "/addons/"],
transform: {},
transformIgnorePatterns: ["/node_modules/", "/addons/", "\\.pnp\\.[^\\/]+$"],
testPathIgnorePatterns: ["vuforia-spatial-toolbox-userinterface"],
moduleNameMapper: {
Expand Down
9 changes: 9 additions & 0 deletions libraries/objectDefaultFiles/object.js
Original file line number Diff line number Diff line change
Expand Up @@ -764,6 +764,7 @@
this.subscribeToObjectsOfType = makeSendStub('subscribeToObjectsOfType');
this.errorNotification = makeSendStub('errorNotification');
this.useWebGlWorker = makeSendStub('useWebGlWorker');
this.useToolRenderer = makeSendStub('useToolRenderer');
this.wasToolJustCreated = makeSendStub('wasToolJustCreated');
this.setPinned = makeSendStub('setPinned');
this.promptForArea = makeSendStub('promptForArea');
Expand Down Expand Up @@ -2128,12 +2129,20 @@

};

// both render engines are mutual exclusive

this.useWebGlWorker = function() {
postDataToParent({
useWebGlWorker: true
});
};

this.useToolRenderer = function() {
postDataToParent({
useToolRenderer: true
});
};

this.prefersAttachingToWorld = function() {
spatialObject.attachesTo = ['world'];

Expand Down
7 changes: 7 additions & 0 deletions libraries/objectDefaultFiles/scene/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = {
'extends': '../../../.eslintrc-web.js',
"parserOptions": {
"ecmaVersion": 2022,
"sourceType": "module"
}
};
25 changes: 25 additions & 0 deletions libraries/objectDefaultFiles/scene/AnchoredGroupNode.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import ObjectNode from "./ObjectNode.js";

/**
* @typedef {import("./BaseNode.js").BaseNodeState} BaseNodeState
* @typedef {import("./BaseNode.js").BaseNodeDelta} BaseNodeDelta
* @typedef {import("./ToolsRootNode.js").ToolsRootNodeState} ToolsRootNodeState
* @typedef {import("./ToolsRootNode.js").ToolsRootNodeDelta} ToolsRootNodeDelta
* @typedef {{properties: {}} & BaseNodeState} AnchoredGroupNodeState
* @typedef {{properties?: {}} & BaseNodeDelta} AnchoredGroupNodeDelta
* @typedef {import("./ObjectNode.js").ObjectInterface} ObjectInterface
*/

class AnchoredGroupNode extends ObjectNode {
static TYPE = "Object.AnchoredGroup";

/**
*
* @param {ObjectInterface} listener
*/
constructor() {
super(AnchoredGroupNode.TYPE);
}
}

export default AnchoredGroupNode;
39 changes: 39 additions & 0 deletions libraries/objectDefaultFiles/scene/BaseComponentNode.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import ObjectNode from "./ObjectNode.js";

/**
* @typedef {import("./BaseNode.js").BaseNodeState} BaseNodeState
* @typedef {import("./BaseNode.js").BaseNodeDelta} BaseNodeDelta
* @typedef {{properties: {[key: string]: BaseNodeState}} & BaseNodeState} BaseComponentNodeState
* @typedef {{properties?: {[key: string]: BaseNodeDelta}} & BaseNodeDelta} BaseComponentNodeDelta
*/

class BaseComponentNode extends ObjectNode {
static TYPE = "Object.Component";

constructor(listener, type) {
super(listener, type);
}

/**
*
* @param {EntityNode} _node
*/
setEntityNode(_node) {
}

/**
*
* @returns {ComponentInterface}
*/
getComponent() {
return this;
}

/**
*
*/
update() {
}
}

export default BaseComponentNode;
151 changes: 151 additions & 0 deletions libraries/objectDefaultFiles/scene/BaseEntity.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
/**
* @typedef {{setComponent: (order: number, component: ComponentInterface) => void, removeComponent: (order: number) => void, updateComponents: () => void, setChild: (key: string, child: EntityInterface) => void, getChild: (key: string) => EntityInterface|undefined, removeChild: (key: string) => void, createEntity: (name: string) => EntityInterface}} EntityInterface
*/

class BaseEntity {
/** @type {{order: number, component: ComponentInterface}[]} */
#components;

/** @type {{[key: string]: BaseEntity}} */
#children;

constructor() {
this.#components = [];
this.#children = {};
}

/**
*
* @param {number} order
* @param {ComponentInterface} component
*/
setComponent(order, component) {
for (let i = 0; i < this.#components.length; i++) {
if (this.#components[i].order > order) {
this.#components.splice(i, 0, {order, component});
return;
}
}
this.#components.push({order, component});
}

/**
*
* @param {number} order
*/
removeComponent(order) {
for (let i = 0; i < this.#components.length; i++) {
if (this.#components[i].order == order) {
delete this.#components[i];
return;
}
}
}

/**
*
* @param {number} order
* @returns {ComponentInterface}
*/
getComponentByOrder(order) {
for (let i = 0; i < this.#components.length; i++) {
if (this.#components[i].order == order) {
return this.#components[i].component;
}
}
return undefined;
}

/**
*
* @param {string} type
* @returns {ComponentInterface}
*/
getComponentByType(type) {
for (let i = 0; i < this.#components.length; i++) {
if (this.#components[i].component.getType() == type) {
return this.#components[i].component;
}
}
return undefined;
}

/**
*
* @param {string} type
* @returns {boolean}
*/
hasComponentWithType(type) {
return this.getComponentByType(type) !== undefined;
}

/**
*
*/
updateComponents() {
for (let entry of this.#components) {
if (!entry || !entry.component || !entry.component.update) {
console.log("here");
}
entry.component.update();
}
for (let child of Object.values(this.#children)) {
child.updateComponents();
}
}

/**
*
* @param {string} key
* @param {EntityInterface} child
*/
setChild(key, child) {
this.#children[key] = child;
}

/**
*
* @param {string} key
* @returns {ComponentInterface}
*/
getChild(key) {
return this.#children[key];
}

/**
*
* @param {string} key
*/
removeChild(key) {
delete this.#children[key];
}

/**
*
*/
internalRelease() {
}

/**
*
*/
release() {
BaseEntity.entityReleaser(this);
}

/**
*
* @param {baseEntity} entity
*/
static entityReleaser(entity) {
entity.internalRelease();
for (let entry of entity.#components) {
entry.component.release();
}
for (let child of Object.values(entity.#children)) {
BaseEntity.entityReleaser(child);
}
}
}

export default BaseEntity;
116 changes: 116 additions & 0 deletions libraries/objectDefaultFiles/scene/BaseEntityNode.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
import ComponentsNode from "./ComponentsNode.js";
import EntitiesNode from "./EntitiesNode.js";
import ObjectNode from "./ObjectNode.js";
import TransformComponentNode from "./TransformComponentNode.js";

/**
* @typedef {import("./BaseNode.js").BaseNodeState} BaseNodeState
* @typedef {import("./BaseNode.js").BaseNodeDelta} BaseNodeDelta
* @typedef {import("./EntitiesNode.js").EntitiesNodeState} EntitiesNodeState
* @typedef {import("./EntitiesNode.js").EntitiesNodeDelta} EntitiesNodeDelta
* @typedef {import("./ComponentsNode.js").ComponentsNodeState} ComponentsNodeState
* @typedef {import("./ComponentsNode.js").ComponentsNodeDelta} ComponentsNodeDelta
* @typedef {{properties: {children: EntitiesNodeState, components: ComponentsNodeState}} & BaseNodeState} EntityNodeState
* @typedef {{properties?: {children?: EntitiesNodeDelta, components?: ComponentsNodeDelta}} & BaseNodeDelta} EntityNodeDelta
* @typedef {import("./ObjectNode.js").ObjectInterface} ObjectInterface
* @typedef {import("./DictionaryComponentNode.js").default} ComponentNode
* @typedef {import("./Vector3Node.js").Vector3Value} Vector3Value
* @typedef {import("./QuaternionNode.js").QuaternionValue} QuaternionValue
* @typedef {{getPosition: () => Vector3Value, setPosition: (position: Vector3Value) => void, getRotation: () => QuaternionValue, setRotation: (rotation: QuaternionValue) => void, getScale: () => Vector3Value, setScale: (scale: Vector3Value) => void}} EntityInterface
*/

class BaseEntityNode extends ObjectNode {
static TYPE = "Object.Entity";

/** @tpye {EntityInterface} */
#entity;

/**
* @param {EntityInterface} entity
* @param {string} type
*/
constructor(entity, type = BaseEntityNode.TYPE) {
super(type);
this._set("children", new EntitiesNode(this));
this._set("components", new ComponentsNode(this));
this.#entity = entity
this.setComponent("0", new TransformComponentNode(this.#entity), false);
}

get entity() {
return this.#entity;
}

/**
*
* @param {string} name
* @returns {boolean}
*/
hasChild(name) {
return this.get("children").has(name);
}

getChild(name) {
return this.get("children").get(name);
}

/**
*
* @param {string} name
* @param {EntityNode} entity
*/
setChild(name, entity, makeDirty = true) {
this.get("children").set(name, entity, makeDirty);
}

/**
*
* @param {number} order
* @param {ComponentNode} component
*/
setComponent(order, component, makeDirty = true) {
this.get("components").set(order, component, makeDirty);
}

/**
*
* @param {string} type
*/
getComponentByType(type) {
return this.get("components").getWithType(type);
}

/**
*
* @param {string} type
*/
hasComponentWithType(type) {
return this.getComponentByType(type) !== undefined;
}

/**
* @param {Vector3Value} value
*/
set position(value) {
const transform = this.get("components").get(0);
transform.position = value;
}

/**
* @param {QuaternionValue} value
*/
set rotation(value) {
const transform = this.get("components").get(0);
transform.rotation = value;
}

/**
* @param {Vector3Value} value
*/
set scale(value) {
const transform = this.get("components").get(0);
transform.scale = value;
}
}

export default BaseEntityNode;
Loading