-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
113 lines (97 loc) · 3.55 KB
/
script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
const { Document, NodeIO, WebIO } = require('@gltf-transform/core');
const { KHRONOS_EXTENSIONS } = require('@gltf-transform/extensions');
const { Extension, ExtensionProperty, PropertyType, WriterContext } = require('@gltf-transform/core');
class Personality extends Extension {
extensionName = 'SXP_personality';
static EXTENSION_NAME = 'SXP_personality';
/** Creates a new Emitter property, for use on a Node. */
createPersonality(name = 'myNode') {
return new PersonalityProps(this.document.getGraph());
}
/** See https://github.com/donmccurdy/glTF-Transform/blob/main/packages/core/src/io/reader-context.ts */
read(context) {
throw new Error('SXP_personality: read() not implemented');
}
/** See https://github.com/donmccurdy/glTF-Transform/blob/main/packages/core/src/io/writer-context.ts */
write(context) {
let agent;
let personality;
let host;
let defaultMessage;
this.properties.forEach(value => {
agent = value.agent;
personality = value.personality;
host = value.endpoint;
defaultMessage = value.defaultMessage;
console.log(value.agent);
console.log(value['agent']);
// console.log("set", value);
});
for (const node of this.document.getRoot().listNodes()) {
if (node.getExtension("SXP_personality")) {
const nodeDef = context.jsonDoc.json.nodes[context.nodeIndexMap.get(node)];
nodeDef.extensions = nodeDef.extensions || {};
nodeDef.extensions["SXP_personality"] = {
agent: agent,
personality : personality,
host : host,
defaultMessage : defaultMessage,
};
}
}
return this;
}
}
class PersonalityProps extends ExtensionProperty {
static EXTENSION_NAME = 'SXP_personality';
static PROPERTY = 'someprop';
init() {
this.extensionName = 'SXP_personality';
this.propertyType = 'PersonalityProps';
this.parentTypes = [PropertyType.NODE];
this.agent = "tubby";
this.personality = "#agent is cheery";
this.endpoint = "https://localhost:8001";
this.defaultMessage = "nya nya!";
}
getDefaults() {
console.log("Personality come on!!");
return Object.assign(super.getDefaults(), {
agent: "tubby",
personality: "#agent is cheery",
host: "https://localhost:8001",
defaultMessage: "nya nya!",
});
}
}
async function main() {
console.log(Personality);
// Register extensions.
const io = new NodeIO()
.registerExtensions([...KHRONOS_EXTENSIONS, Personality]);
// Get the input file path from the command line argument.
const inputFile = process.argv[2];
// Merge documents.
const document = new Document();
document.merge(await io.read(inputFile));
const node = document.createNode(process.argv[3])
const emitterExtension = document.createExtension(Personality);
const emitter = emitterExtension.createPersonality(process.argv[3], process.argv[3], process.argv[4], process.argv[5], process.argv[6], process.argv[7]);
emitter.agent = process.argv[3];
emitter.personality = process.argv[4];
emitter.endpoint = process.argv[5];
emitter.defaultMessage = process.argv[6];
node.setExtension('SXP_personality', emitter);
// (Optional) Merge buffers.
const buffer = document.getRoot().listBuffers()[0];
document.getRoot()
.listAccessors()
.forEach((a) => a.setBuffer(buffer));
document.getRoot()
.listBuffers()
.forEach((b, index) => (index > 0 ? b.dispose() : null));
// Write the output file to the current directory.
const outputFile = 'output.glb';
await io.write(outputFile, document);
}
main();