@needle-tools/engine
Version:
Needle Engine is a web-based runtime for 3D apps. It runs on your machine for development with great integrations into editors like Unity or Blender - and can be deployed onto any device! It is flexible, extensible and networking and XR are built-in.
58 lines • 2.1 kB
JavaScript
export const EXTENSION_NAME = "NEEDLE_gameobject_data";
export class NEEDLE_gameobject_data {
get name() {
return EXTENSION_NAME;
}
parser;
constructor(parser) {
this.parser = parser;
}
// private _lastIndex: number = -1;
// createNodeAttachment(index): null {
// if (index === this._lastIndex) return null;
// this._lastIndex = index;
// const node = this.parser.json.nodes[index];
// if (node && node.extensions) {
// const ext = node.extensions[EXTENSION_NAME];
// if (ext)
// this.findAndApplyExtensionData(index, ext);
// }
// return null;
// }
// private lastIndex: number = -1;
afterRoot(_result) {
// console.log("AFTER ROOT", _result);
const promises = [];
for (let index = 0; index < this.parser.json.nodes?.length; index++) {
const node = this.parser.json.nodes[index];
if (node && node.extensions) {
const ext = node.extensions[EXTENSION_NAME];
if (ext) {
const p = this.findAndApplyExtensionData(index, ext);
promises.push(p);
}
}
}
return Promise.all(promises).then(() => null);
}
async findAndApplyExtensionData(nodeId, ext) {
const obj = await this.parser.getDependency("node", nodeId);
if (obj) {
this.applyExtensionData(obj, ext);
}
}
applyExtensionData(node, ext) {
if (ext.layers === undefined)
ext.layers = 0;
node.userData.layer = ext.layers;
node.layers.disableAll();
node.layers.set(ext.layers);
node.userData.tag = ext.tag ?? "none";
node.hideFlags = 0;
node.userData.static = ext.static ?? false;
node.visible = ext.activeSelf ?? true;
node["guid"] = ext.guid;
// console.log(node.name, ext.activeSelf, node);
}
}
//# sourceMappingURL=NEEDLE_gameobject_data.js.map