@bluemoonfoundry/daz-ts 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +377 -2
- package/dist/animation.d.ts +129 -0
- package/dist/animation.js +276 -0
- package/dist/batch.d.ts +118 -0
- package/dist/batch.js +186 -0
- package/dist/bone.d.ts +50 -0
- package/dist/bone.js +66 -0
- package/dist/camera.d.ts +61 -0
- package/dist/camera.js +120 -0
- package/dist/cinematics.d.ts +188 -0
- package/dist/cinematics.js +165 -0
- package/dist/client.d.ts +399 -0
- package/dist/client.js +769 -0
- package/dist/dforce.d.ts +15 -0
- package/dist/dforce.js +36 -0
- package/dist/element.d.ts +51 -0
- package/dist/element.js +141 -0
- package/dist/exceptions.d.ts +124 -0
- package/dist/exceptions.js +173 -0
- package/dist/geometry.d.ts +81 -0
- package/dist/geometry.js +433 -0
- package/dist/index.d.ts +50 -0
- package/dist/index.js +36 -0
- package/dist/light.d.ts +24 -0
- package/dist/light.js +40 -0
- package/dist/lighting.d.ts +120 -0
- package/dist/lighting.js +107 -0
- package/dist/material.d.ts +27 -0
- package/dist/material.js +63 -0
- package/dist/materials.d.ts +107 -0
- package/dist/materials.js +165 -0
- package/dist/math3.d.ts +204 -0
- package/dist/math3.js +502 -0
- package/dist/modifier.d.ts +14 -0
- package/dist/modifier.js +24 -0
- package/dist/morph.d.ts +11 -0
- package/dist/morph.js +24 -0
- package/dist/node.d.ts +196 -0
- package/dist/node.js +447 -0
- package/dist/polling.d.ts +24 -0
- package/dist/polling.js +50 -0
- package/dist/pose.d.ts +82 -0
- package/dist/pose.js +295 -0
- package/dist/poses.d.ts +54 -0
- package/dist/poses.js +40 -0
- package/dist/property.d.ts +64 -0
- package/dist/property.js +125 -0
- package/dist/render.d.ts +242 -0
- package/dist/render.js +811 -0
- package/dist/renderApi.d.ts +124 -0
- package/dist/renderApi.js +235 -0
- package/dist/result.d.ts +15 -0
- package/dist/result.js +1 -0
- package/dist/scene.d.ts +154 -0
- package/dist/scene.js +584 -0
- package/dist/sceneEvents.d.ts +63 -0
- package/dist/sceneEvents.js +102 -0
- package/dist/sceneState.d.ts +167 -0
- package/dist/sceneState.js +430 -0
- package/dist/scriptBuilder.d.ts +41 -0
- package/dist/scriptBuilder.js +72 -0
- package/dist/shotGeometry.d.ts +49 -0
- package/dist/shotGeometry.js +76 -0
- package/dist/skeleton.d.ts +120 -0
- package/dist/skeleton.js +561 -0
- package/dist/timeline.d.ts +24 -0
- package/dist/timeline.js +39 -0
- package/dist/undo.d.ts +24 -0
- package/dist/undo.js +45 -0
- package/dist/version.d.ts +31 -0
- package/dist/version.js +36 -0
- package/dist/viewport.d.ts +58 -0
- package/dist/viewport.js +239 -0
- package/package.json +52 -4
package/dist/geometry.js
ADDED
|
@@ -0,0 +1,433 @@
|
|
|
1
|
+
import { DazElement } from "./element.js";
|
|
2
|
+
import { BoundingBox, Vec3 } from "./math3.js";
|
|
3
|
+
import { ScriptBuilder } from "./scriptBuilder.js";
|
|
4
|
+
/** Chunked access to vertices, faces, normals, UV sets, and face/material groups for a node's current shape's geometry. */
|
|
5
|
+
export class DazGeometry extends DazElement {
|
|
6
|
+
nodeExpr;
|
|
7
|
+
constructor(client, identifier) {
|
|
8
|
+
const nodeExpr = ScriptBuilder.findNodeExpr(identifier);
|
|
9
|
+
const locator = `(function(){` +
|
|
10
|
+
`var n = ${nodeExpr};` +
|
|
11
|
+
`if (!n) return null;` +
|
|
12
|
+
`var obj = n.getObject();` +
|
|
13
|
+
`if (!obj) return null;` +
|
|
14
|
+
`var sh = obj.getCurrentShape();` +
|
|
15
|
+
`return sh ? sh.getGeometry() : null;` +
|
|
16
|
+
`})()`;
|
|
17
|
+
super(client, locator);
|
|
18
|
+
this.nodeExpr = nodeExpr;
|
|
19
|
+
}
|
|
20
|
+
// ---------------------------------------------------------------------
|
|
21
|
+
// Vertex / facet counts
|
|
22
|
+
// ---------------------------------------------------------------------
|
|
23
|
+
/** Total number of vertices in the mesh (read-only). */
|
|
24
|
+
async vertexCount() {
|
|
25
|
+
const script = ScriptBuilder.iife(`var g = ${this.locator}; return g ? g.getNumVertices() : null;`);
|
|
26
|
+
return (await this.client.execute(script)).value;
|
|
27
|
+
}
|
|
28
|
+
/** Total number of faces (triangles + quads, read-only). */
|
|
29
|
+
async facetCount() {
|
|
30
|
+
const script = ScriptBuilder.iife(`var g = ${this.locator}; return g ? g.getNumFacets() : null;`);
|
|
31
|
+
return (await this.client.execute(script)).value;
|
|
32
|
+
}
|
|
33
|
+
// ---------------------------------------------------------------------
|
|
34
|
+
// Chunked vertex access
|
|
35
|
+
// ---------------------------------------------------------------------
|
|
36
|
+
/** One chunk of vertex positions. `start`/`count` default to `0`/`5000`. */
|
|
37
|
+
async vertexPositions(start = 0, count = 5000) {
|
|
38
|
+
const startJs = ScriptBuilder.serializeArg(start);
|
|
39
|
+
const countJs = ScriptBuilder.serializeArg(count);
|
|
40
|
+
const script = ScriptBuilder.iife(`
|
|
41
|
+
var g = ${this.locator};
|
|
42
|
+
if (!g) return null;
|
|
43
|
+
var total = g.getNumVertices();
|
|
44
|
+
var end = Math.min(${startJs} + ${countJs}, total);
|
|
45
|
+
var verts = [];
|
|
46
|
+
for (var i = ${startJs}; i < end; i++) {
|
|
47
|
+
var v = g.getVertex(i);
|
|
48
|
+
verts.push([v.x, v.y, v.z]);
|
|
49
|
+
}
|
|
50
|
+
return {total: total, start: ${startJs}, count: verts.length, vertices: verts};
|
|
51
|
+
`);
|
|
52
|
+
return (await this.client.execute(script)).value ?? {
|
|
53
|
+
total: 0,
|
|
54
|
+
start,
|
|
55
|
+
count: 0,
|
|
56
|
+
vertices: [],
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
/** Every vertex position, auto-paginating by `chunkSize` (default `5000`). */
|
|
60
|
+
async vertexPositionsAll(chunkSize = 5000) {
|
|
61
|
+
const all = [];
|
|
62
|
+
let offset = 0;
|
|
63
|
+
let total = Infinity;
|
|
64
|
+
while (offset < total) {
|
|
65
|
+
const chunk = await this.vertexPositions(offset, chunkSize);
|
|
66
|
+
total = chunk.total;
|
|
67
|
+
if (chunk.vertices.length === 0)
|
|
68
|
+
break;
|
|
69
|
+
all.push(...chunk.vertices);
|
|
70
|
+
offset += chunk.vertices.length;
|
|
71
|
+
}
|
|
72
|
+
return all;
|
|
73
|
+
}
|
|
74
|
+
// ---------------------------------------------------------------------
|
|
75
|
+
// Faces / normals / UVs
|
|
76
|
+
// ---------------------------------------------------------------------
|
|
77
|
+
/** One chunk of face vertex indices; each entry is `[v0,v1,v2]` (tri) or `[v0,v1,v2,v3]` (quad). `start`/`count` default `0`/`1000`. */
|
|
78
|
+
async faceVertexIndices(start = 0, count = 1000) {
|
|
79
|
+
const startJs = ScriptBuilder.serializeArg(start);
|
|
80
|
+
const countJs = ScriptBuilder.serializeArg(count);
|
|
81
|
+
const script = ScriptBuilder.iife(`
|
|
82
|
+
var g = ${this.locator};
|
|
83
|
+
if (!g) return null;
|
|
84
|
+
var total = g.getNumFacets();
|
|
85
|
+
var end = Math.min(${startJs} + ${countJs}, total);
|
|
86
|
+
var facets = [];
|
|
87
|
+
for (var i = ${startJs}; i < end; i++) {
|
|
88
|
+
var f = g.getFacet(i);
|
|
89
|
+
if (f.isQuad()) {
|
|
90
|
+
facets.push([f.vertIdx1, f.vertIdx2, f.vertIdx3, f.vertIdx4]);
|
|
91
|
+
} else {
|
|
92
|
+
facets.push([f.vertIdx1, f.vertIdx2, f.vertIdx3]);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
return {total: total, start: ${startJs}, facets: facets};
|
|
96
|
+
`);
|
|
97
|
+
return (await this.client.execute(script)).value ?? {
|
|
98
|
+
total: 0,
|
|
99
|
+
start,
|
|
100
|
+
facets: [],
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
/** Every face's vertex indices, auto-paginating by `chunkSize` (default `1000`). */
|
|
104
|
+
async faceVertexIndicesAll(chunkSize = 1000) {
|
|
105
|
+
const all = [];
|
|
106
|
+
let offset = 0;
|
|
107
|
+
let total = Infinity;
|
|
108
|
+
while (offset < total) {
|
|
109
|
+
const chunk = await this.faceVertexIndices(offset, chunkSize);
|
|
110
|
+
total = chunk.total;
|
|
111
|
+
if (chunk.facets.length === 0)
|
|
112
|
+
break;
|
|
113
|
+
all.push(...chunk.facets);
|
|
114
|
+
offset += chunk.facets.length;
|
|
115
|
+
}
|
|
116
|
+
return all;
|
|
117
|
+
}
|
|
118
|
+
/** One chunk of face normals. `start`/`count` default `0`/`5000`. */
|
|
119
|
+
async normals(start = 0, count = 5000) {
|
|
120
|
+
const startJs = ScriptBuilder.serializeArg(start);
|
|
121
|
+
const countJs = ScriptBuilder.serializeArg(count);
|
|
122
|
+
const script = ScriptBuilder.iife(`
|
|
123
|
+
var g = ${this.locator};
|
|
124
|
+
if (!g) return null;
|
|
125
|
+
var total = g.getNumNormals ? g.getNumNormals() : 0;
|
|
126
|
+
var end = Math.min(${startJs} + ${countJs}, total);
|
|
127
|
+
var norms = [];
|
|
128
|
+
for (var i = ${startJs}; i < end; i++) {
|
|
129
|
+
var n = g.getNormal(i);
|
|
130
|
+
norms.push([n.x, n.y, n.z]);
|
|
131
|
+
}
|
|
132
|
+
return {total: total, start: ${startJs}, normals: norms};
|
|
133
|
+
`);
|
|
134
|
+
return (await this.client.execute(script)).value ?? {
|
|
135
|
+
total: 0,
|
|
136
|
+
start,
|
|
137
|
+
normals: [],
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
/** Every face normal, auto-paginating by `chunkSize` (default `5000`). */
|
|
141
|
+
async normalsAll(chunkSize = 5000) {
|
|
142
|
+
const all = [];
|
|
143
|
+
let offset = 0;
|
|
144
|
+
let total = Infinity;
|
|
145
|
+
while (offset < total) {
|
|
146
|
+
const chunk = await this.normals(offset, chunkSize);
|
|
147
|
+
total = chunk.total;
|
|
148
|
+
if (chunk.normals.length === 0)
|
|
149
|
+
break;
|
|
150
|
+
all.push(...chunk.normals);
|
|
151
|
+
offset += chunk.normals.length;
|
|
152
|
+
}
|
|
153
|
+
return all;
|
|
154
|
+
}
|
|
155
|
+
/** Number of UV sets on this mesh (read-only). */
|
|
156
|
+
async uvSetCount() {
|
|
157
|
+
const script = ScriptBuilder.iife(`var g = ${this.locator}; return g ? g.getNumUVSets() : null;`);
|
|
158
|
+
return (await this.client.execute(script)).value;
|
|
159
|
+
}
|
|
160
|
+
/** One chunk of UV coordinates for `uvSet` (default `0`, the primary set uses `g.getUVs()` rather than `g.getUVSet(0)`). */
|
|
161
|
+
async uvPositions(uvSet = 0, start = 0, count = 5000) {
|
|
162
|
+
const uvSetJs = ScriptBuilder.serializeArg(uvSet);
|
|
163
|
+
const startJs = ScriptBuilder.serializeArg(start);
|
|
164
|
+
const countJs = ScriptBuilder.serializeArg(count);
|
|
165
|
+
const script = ScriptBuilder.iife(`
|
|
166
|
+
var g = ${this.locator};
|
|
167
|
+
if (!g) return null;
|
|
168
|
+
var uvMap = (${uvSetJs} === 0) ? g.getUVs() : g.getUVSet(${uvSetJs});
|
|
169
|
+
if (!uvMap) return null;
|
|
170
|
+
var total = uvMap.getNumValues();
|
|
171
|
+
var end = Math.min(${startJs} + ${countJs}, total);
|
|
172
|
+
var uvs = [];
|
|
173
|
+
for (var i = ${startJs}; i < end; i++) {
|
|
174
|
+
var p = uvMap.getPnt2Vec(i);
|
|
175
|
+
uvs.push([p.x, p.y]);
|
|
176
|
+
}
|
|
177
|
+
return {total: total, start: ${startJs}, uvs: uvs};
|
|
178
|
+
`);
|
|
179
|
+
return (await this.client.execute(script)).value ?? {
|
|
180
|
+
total: 0,
|
|
181
|
+
start,
|
|
182
|
+
uvs: [],
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
/** Every UV coordinate for `uvSet`, auto-paginating by `chunkSize` (default `5000`). */
|
|
186
|
+
async uvPositionsAll(uvSet = 0, chunkSize = 5000) {
|
|
187
|
+
const all = [];
|
|
188
|
+
let offset = 0;
|
|
189
|
+
let total = Infinity;
|
|
190
|
+
while (offset < total) {
|
|
191
|
+
const chunk = await this.uvPositions(uvSet, offset, chunkSize);
|
|
192
|
+
total = chunk.total;
|
|
193
|
+
if (chunk.uvs.length === 0)
|
|
194
|
+
break;
|
|
195
|
+
all.push(...chunk.uvs);
|
|
196
|
+
offset += chunk.uvs.length;
|
|
197
|
+
}
|
|
198
|
+
return all;
|
|
199
|
+
}
|
|
200
|
+
// ---------------------------------------------------------------------
|
|
201
|
+
// Groups
|
|
202
|
+
// ---------------------------------------------------------------------
|
|
203
|
+
async faceGroupNames() {
|
|
204
|
+
const script = ScriptBuilder.iife(`
|
|
205
|
+
var g = ${this.locator};
|
|
206
|
+
if (!g || !g.getNumFaceGroups) return [];
|
|
207
|
+
var n = g.getNumFaceGroups();
|
|
208
|
+
var names = [];
|
|
209
|
+
for (var i = 0; i < n; i++) {
|
|
210
|
+
var grp = g.getFaceGroup(i);
|
|
211
|
+
names.push(grp ? grp.getName() : null);
|
|
212
|
+
}
|
|
213
|
+
return names;
|
|
214
|
+
`);
|
|
215
|
+
return (await this.client.execute(script)).value ?? [];
|
|
216
|
+
}
|
|
217
|
+
async materialGroupNames() {
|
|
218
|
+
const script = ScriptBuilder.iife(`
|
|
219
|
+
var g = ${this.locator};
|
|
220
|
+
if (!g || !g.getNumMaterialGroups) return [];
|
|
221
|
+
var n = g.getNumMaterialGroups();
|
|
222
|
+
var names = [];
|
|
223
|
+
for (var i = 0; i < n; i++) {
|
|
224
|
+
var grp = g.getMaterialGroup(i);
|
|
225
|
+
names.push(grp ? grp.getName() : null);
|
|
226
|
+
}
|
|
227
|
+
return names;
|
|
228
|
+
`);
|
|
229
|
+
return (await this.client.execute(script)).value ?? [];
|
|
230
|
+
}
|
|
231
|
+
/** Face indices belonging to the named face group, or `[]` if it doesn't exist. */
|
|
232
|
+
async faceGroupFaces(name) {
|
|
233
|
+
const nameJs = ScriptBuilder.escapeString(name);
|
|
234
|
+
const script = ScriptBuilder.iife(`
|
|
235
|
+
var g = ${this.locator};
|
|
236
|
+
if (!g || !g.getNumFaceGroups) return [];
|
|
237
|
+
for (var i = 0; i < g.getNumFaceGroups(); i++) {
|
|
238
|
+
var grp = g.getFaceGroup(i);
|
|
239
|
+
if (grp && grp.getName() === ${nameJs}) {
|
|
240
|
+
var idx = [];
|
|
241
|
+
for (var j = 0; j < grp.count(); j++) idx.push(grp.getIndexAt(j));
|
|
242
|
+
return idx;
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
return [];
|
|
246
|
+
`);
|
|
247
|
+
return (await this.client.execute(script)).value ?? [];
|
|
248
|
+
}
|
|
249
|
+
/** Face indices belonging to the named material group, or `[]` if it doesn't exist. */
|
|
250
|
+
async materialGroupFaces(name) {
|
|
251
|
+
const nameJs = ScriptBuilder.escapeString(name);
|
|
252
|
+
const script = ScriptBuilder.iife(`
|
|
253
|
+
var g = ${this.locator};
|
|
254
|
+
if (!g || !g.getNumMaterialGroups) return [];
|
|
255
|
+
for (var i = 0; i < g.getNumMaterialGroups(); i++) {
|
|
256
|
+
var grp = g.getMaterialGroup(i);
|
|
257
|
+
if (grp && grp.getName() === ${nameJs}) {
|
|
258
|
+
var idx = [];
|
|
259
|
+
for (var j = 0; j < grp.count(); j++) idx.push(grp.getIndexAt(j));
|
|
260
|
+
return idx;
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
return [];
|
|
264
|
+
`);
|
|
265
|
+
return (await this.client.execute(script)).value ?? [];
|
|
266
|
+
}
|
|
267
|
+
// ---------------------------------------------------------------------
|
|
268
|
+
// Subdivision / tris / quads / mesh info
|
|
269
|
+
// ---------------------------------------------------------------------
|
|
270
|
+
/** Current subdivision level (`0` = base mesh, read-only). */
|
|
271
|
+
async subdivisionLevel() {
|
|
272
|
+
const script = ScriptBuilder.iife(`var g = ${this.locator}; return (g && g.getCurrentSubDivisionLevel) ? g.getCurrentSubDivisionLevel() : null;`);
|
|
273
|
+
return (await this.client.execute(script)).value;
|
|
274
|
+
}
|
|
275
|
+
async trisCount() {
|
|
276
|
+
const script = ScriptBuilder.iife(`var g = ${this.locator}; return (g && g.getNumTris) ? g.getNumTris() : null;`);
|
|
277
|
+
return (await this.client.execute(script)).value;
|
|
278
|
+
}
|
|
279
|
+
async quadsCount() {
|
|
280
|
+
const script = ScriptBuilder.iife(`var g = ${this.locator}; return (g && g.getNumQuads) ? g.getNumQuads() : null;`);
|
|
281
|
+
return (await this.client.execute(script)).value;
|
|
282
|
+
}
|
|
283
|
+
/** All mesh metadata (vertex/facet/tri/quad counts, subdivision level, UV set count, group names) in a single HTTP call, instead of 7+ separate reads. */
|
|
284
|
+
async meshInfo() {
|
|
285
|
+
const script = ScriptBuilder.iife(`
|
|
286
|
+
var g = ${this.locator};
|
|
287
|
+
if (!g) return null;
|
|
288
|
+
var fgNames = [];
|
|
289
|
+
if (g.getNumFaceGroups) {
|
|
290
|
+
for (var i = 0; i < g.getNumFaceGroups(); i++) {
|
|
291
|
+
var fg = g.getFaceGroup(i);
|
|
292
|
+
fgNames.push(fg ? fg.getName() : null);
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
var mgNames = [];
|
|
296
|
+
if (g.getNumMaterialGroups) {
|
|
297
|
+
for (var i = 0; i < g.getNumMaterialGroups(); i++) {
|
|
298
|
+
var mg = g.getMaterialGroup(i);
|
|
299
|
+
mgNames.push(mg ? mg.getName() : null);
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
return {
|
|
303
|
+
vertex_count: g.getNumVertices(),
|
|
304
|
+
facet_count: g.getNumFacets(),
|
|
305
|
+
tris_count: g.getNumTris ? g.getNumTris() : null,
|
|
306
|
+
quads_count: g.getNumQuads ? g.getNumQuads() : null,
|
|
307
|
+
subdivision_level: g.getCurrentSubDivisionLevel ? g.getCurrentSubDivisionLevel() : null,
|
|
308
|
+
uv_set_count: g.getNumUVSets ? g.getNumUVSets() : null,
|
|
309
|
+
face_group_names: fgNames,
|
|
310
|
+
material_group_names: mgNames
|
|
311
|
+
};
|
|
312
|
+
`);
|
|
313
|
+
return (await this.client.execute(script)).value;
|
|
314
|
+
}
|
|
315
|
+
// ---------------------------------------------------------------------
|
|
316
|
+
// Bounding box
|
|
317
|
+
// ---------------------------------------------------------------------
|
|
318
|
+
/** Axis-aligned bounding box of the base mesh, computed server-side in one HTTP call. `null` if unavailable or empty. */
|
|
319
|
+
async boundingBox() {
|
|
320
|
+
const script = ScriptBuilder.iife(`
|
|
321
|
+
var g = ${this.locator};
|
|
322
|
+
if (!g || g.getNumVertices() === 0) return null;
|
|
323
|
+
var v = g.getVertex(0);
|
|
324
|
+
var mnX = v.x, mnY = v.y, mnZ = v.z;
|
|
325
|
+
var mxX = v.x, mxY = v.y, mxZ = v.z;
|
|
326
|
+
var n = g.getNumVertices();
|
|
327
|
+
for (var i = 1; i < n; i++) {
|
|
328
|
+
v = g.getVertex(i);
|
|
329
|
+
if (v.x < mnX) mnX = v.x; else if (v.x > mxX) mxX = v.x;
|
|
330
|
+
if (v.y < mnY) mnY = v.y; else if (v.y > mxY) mxY = v.y;
|
|
331
|
+
if (v.z < mnZ) mnZ = v.z; else if (v.z > mxZ) mxZ = v.z;
|
|
332
|
+
}
|
|
333
|
+
return {min: {x:mnX, y:mnY, z:mnZ}, max: {x:mxX, y:mxY, z:mxZ}};
|
|
334
|
+
`);
|
|
335
|
+
const result = (await this.client.execute(script)).value;
|
|
336
|
+
if (result === null)
|
|
337
|
+
return null;
|
|
338
|
+
return BoundingBox.fromDict(result);
|
|
339
|
+
}
|
|
340
|
+
/** AABB of the world-space posed-and-morphed mesh (after forcing a cache update), in one HTTP call. */
|
|
341
|
+
async boundingBoxPosed() {
|
|
342
|
+
const script = ScriptBuilder.iife(`
|
|
343
|
+
var _nd = ${this.nodeExpr};
|
|
344
|
+
if (!_nd) return null;
|
|
345
|
+
var obj = _nd.getObject();
|
|
346
|
+
if (!obj) return null;
|
|
347
|
+
obj.forceCacheUpdate(_nd, false);
|
|
348
|
+
var g = obj.getCachedGeom();
|
|
349
|
+
if (!g || g.getNumVertices() === 0) return null;
|
|
350
|
+
var v = g.getVertex(0);
|
|
351
|
+
var mnX = v.x, mnY = v.y, mnZ = v.z;
|
|
352
|
+
var mxX = v.x, mxY = v.y, mxZ = v.z;
|
|
353
|
+
var n = g.getNumVertices();
|
|
354
|
+
for (var i = 1; i < n; i++) {
|
|
355
|
+
v = g.getVertex(i);
|
|
356
|
+
if (v.x < mnX) mnX = v.x; else if (v.x > mxX) mxX = v.x;
|
|
357
|
+
if (v.y < mnY) mnY = v.y; else if (v.y > mxY) mxY = v.y;
|
|
358
|
+
if (v.z < mnZ) mnZ = v.z; else if (v.z > mxZ) mxZ = v.z;
|
|
359
|
+
}
|
|
360
|
+
return {min: {x:mnX, y:mnY, z:mnZ}, max: {x:mxX, y:mxY, z:mxZ}};
|
|
361
|
+
`);
|
|
362
|
+
const result = (await this.client.execute(script)).value;
|
|
363
|
+
if (result === null)
|
|
364
|
+
return null;
|
|
365
|
+
return BoundingBox.fromDict(result);
|
|
366
|
+
}
|
|
367
|
+
// ---------------------------------------------------------------------
|
|
368
|
+
// Posed (world-space) vertex positions
|
|
369
|
+
// ---------------------------------------------------------------------
|
|
370
|
+
/** One chunk of fully-deformed world-space vertex positions (post morph-and-skinning), via `DzObject.getCachedGeom()`. */
|
|
371
|
+
async vertexPositionsPosed(start = 0, count = 5000) {
|
|
372
|
+
const startJs = ScriptBuilder.serializeArg(start);
|
|
373
|
+
const countJs = ScriptBuilder.serializeArg(count);
|
|
374
|
+
const script = ScriptBuilder.iife(`
|
|
375
|
+
var n = ${this.nodeExpr};
|
|
376
|
+
if (!n) return null;
|
|
377
|
+
var obj = n.getObject();
|
|
378
|
+
if (!obj) return null;
|
|
379
|
+
obj.forceCacheUpdate(n, false);
|
|
380
|
+
var cached = obj.getCachedGeom();
|
|
381
|
+
if (!cached) return null;
|
|
382
|
+
var total = cached.getNumVertices();
|
|
383
|
+
var end = Math.min(${startJs} + ${countJs}, total);
|
|
384
|
+
var verts = [];
|
|
385
|
+
for (var i = ${startJs}; i < end; i++) {
|
|
386
|
+
var v = cached.getVertex(i);
|
|
387
|
+
verts.push([v.x, v.y, v.z]);
|
|
388
|
+
}
|
|
389
|
+
return {total: total, start: ${startJs}, count: verts.length, vertices: verts};
|
|
390
|
+
`);
|
|
391
|
+
return (await this.client.execute(script)).value ?? { total: 0, start, count: 0, vertices: [] };
|
|
392
|
+
}
|
|
393
|
+
/** Every world-space posed+morphed vertex position, auto-paginating by `chunkSize` (default `5000`). */
|
|
394
|
+
async vertexPositionsPosedAll(chunkSize = 5000) {
|
|
395
|
+
const all = [];
|
|
396
|
+
let offset = 0;
|
|
397
|
+
let total = Infinity;
|
|
398
|
+
while (offset < total) {
|
|
399
|
+
const chunk = await this.vertexPositionsPosed(offset, chunkSize);
|
|
400
|
+
total = chunk.total;
|
|
401
|
+
if (chunk.vertices.length === 0)
|
|
402
|
+
break;
|
|
403
|
+
all.push(...chunk.vertices);
|
|
404
|
+
offset += chunk.vertices.length;
|
|
405
|
+
}
|
|
406
|
+
return all;
|
|
407
|
+
}
|
|
408
|
+
// ---------------------------------------------------------------------
|
|
409
|
+
// Static helpers (pure functions, no HTTP)
|
|
410
|
+
// ---------------------------------------------------------------------
|
|
411
|
+
/**
|
|
412
|
+
* Convert face index arrays (tris or quads) to all-triangles. Quads split
|
|
413
|
+
* along the 0->2 diagonal (`[v0,v1,v2,v3]` -> `[v0,v1,v2]` + `[v0,v2,v3]`).
|
|
414
|
+
* Faces with any other vertex count are silently skipped. Pure function — no HTTP round-trip.
|
|
415
|
+
*/
|
|
416
|
+
static triangulate(faces) {
|
|
417
|
+
const result = [];
|
|
418
|
+
for (const f of faces) {
|
|
419
|
+
if (f.length === 3) {
|
|
420
|
+
result.push([...f]);
|
|
421
|
+
}
|
|
422
|
+
else if (f.length === 4) {
|
|
423
|
+
result.push([f[0], f[1], f[2]]);
|
|
424
|
+
result.push([f[0], f[2], f[3]]);
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
return result;
|
|
428
|
+
}
|
|
429
|
+
/** Wrap `[[x,y,z], ...]` vertex data as {@link Vec3} instances. Pure function — no HTTP round-trip. */
|
|
430
|
+
static asVec3(vertices) {
|
|
431
|
+
return vertices.map((v) => Vec3.fromList(v));
|
|
432
|
+
}
|
|
433
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
export { DazClient } from "./client.js";
|
|
2
|
+
export type { DazClientOptions, RetryOptions, RenderSubmitOptions, CapabilityRoute, Artifact, ArtifactList, DownloadArtifactOptions, ServerCapabilities, RequestStatus, CancelResponse, StreamOptions, } from "./client.js";
|
|
3
|
+
export { parseSseStream, FINAL_REQUEST_STATUSES } from "./client.js";
|
|
4
|
+
export type { ExecutionResult } from "./result.js";
|
|
5
|
+
export { AsyncExecutionError, AuthenticationError, BatchLimitExceededError, ConcurrencyLimitError, ConnectionError, DazBusyError, DazError, DazTimeoutError, MaterialError, NodeNotFoundError, RenderError, ArtifactError, ScriptError, ScriptRuntimeError, ScriptSyntaxError, StudioBusyError, } from "./exceptions.js";
|
|
6
|
+
export { ScriptBuilder } from "./scriptBuilder.js";
|
|
7
|
+
export { Batch, BatchFuture, buildOperationsScript, DEFAULT_MAX_OPERATIONS, DEFAULT_MAX_SCRIPT_LENGTH } from "./batch.js";
|
|
8
|
+
export type { BatchOptions } from "./batch.js";
|
|
9
|
+
export { executeLong } from "./polling.js";
|
|
10
|
+
export type { ExecuteLongOptions } from "./polling.js";
|
|
11
|
+
export { AxisRemap, BoundingBox, Quat, Vec3, Y_UP_TO_Z_UP } from "./math3.js";
|
|
12
|
+
export { DazElement } from "./element.js";
|
|
13
|
+
export { DazProperty } from "./property.js";
|
|
14
|
+
export { DazNode, type NodeIdentifier } from "./node.js";
|
|
15
|
+
export { DazBone } from "./bone.js";
|
|
16
|
+
export { DazCamera } from "./camera.js";
|
|
17
|
+
export { DazLight } from "./light.js";
|
|
18
|
+
export { DazSkeleton } from "./skeleton.js";
|
|
19
|
+
export { DazMaterial } from "./material.js";
|
|
20
|
+
export { DazModifier } from "./modifier.js";
|
|
21
|
+
export { DazMorph } from "./morph.js";
|
|
22
|
+
export { DazDForce } from "./dforce.js";
|
|
23
|
+
export { DazScene } from "./scene.js";
|
|
24
|
+
export { DazGeometry } from "./geometry.js";
|
|
25
|
+
export { DazViewport } from "./viewport.js";
|
|
26
|
+
export { DazTimeline } from "./timeline.js";
|
|
27
|
+
export { UndoGroup, withUndo } from "./undo.js";
|
|
28
|
+
export { DazRenderSettings } from "./render.js";
|
|
29
|
+
export type { Canvas, RenderOptions, RenderOutcome } from "./render.js";
|
|
30
|
+
export { render, renderVariants } from "./renderApi.js";
|
|
31
|
+
export type { FigureMorphs, RenderBaseSpec, RenderCallOptions, RenderResult, RenderVariantSpec, RenderVariantsOptions, } from "./renderApi.js";
|
|
32
|
+
export { DazPose } from "./pose.js";
|
|
33
|
+
export type { DazPoseDict } from "./pose.js";
|
|
34
|
+
export { DazSceneState } from "./sceneState.js";
|
|
35
|
+
export type { ApplyOptions, ApplyResult, CaptureOptions, DazSceneStateDict, SkippedNode } from "./sceneState.js";
|
|
36
|
+
export { DazAnimation } from "./animation.js";
|
|
37
|
+
export type { AnimationFrame, DazAnimationDict } from "./animation.js";
|
|
38
|
+
export { sphericalOffset, lookAtEuler, resolveTarget } from "./shotGeometry.js";
|
|
39
|
+
export { applyPose, resetTransforms, zeroFigure } from "./poses.js";
|
|
40
|
+
export type { ZeroFigureOptions } from "./poses.js";
|
|
41
|
+
export { applyIrayMaterial, applyTextureMap, getSurfaceProperty, setSurfaceProperty } from "./materials.js";
|
|
42
|
+
export type { IrayMaterial, SurfaceProperty, TextureMap } from "./materials.js";
|
|
43
|
+
export { applyHdriEnvironment, applyThreePointLightSetup, setLightColor } from "./lighting.js";
|
|
44
|
+
export type { HDRIEnvironment, LightSpec, ThreePointLightRig, ThreePointLightSetup } from "./lighting.js";
|
|
45
|
+
export { applyAnimatedShot, applyFrameSubject, applyOrbitCamera, applyStaticShot } from "./cinematics.js";
|
|
46
|
+
export type { CameraKeyframe, CameraTargetOptions, CinematicAnimatedShot, CinematicStaticShot, FrameSubject, OrbitCamera, } from "./cinematics.js";
|
|
47
|
+
export { watchSceneEvents, waitForSceneEvent } from "./sceneEvents.js";
|
|
48
|
+
export type { SceneEvent } from "./sceneEvents.js";
|
|
49
|
+
export { MIN_SERVER_VERSION, parseVersion, evaluateServerVersion } from "./version.js";
|
|
50
|
+
export type { VersionCheck } from "./version.js";
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
export { DazClient } from "./client.js";
|
|
2
|
+
export { parseSseStream, FINAL_REQUEST_STATUSES } from "./client.js";
|
|
3
|
+
export { AsyncExecutionError, AuthenticationError, BatchLimitExceededError, ConcurrencyLimitError, ConnectionError, DazBusyError, DazError, DazTimeoutError, MaterialError, NodeNotFoundError, RenderError, ArtifactError, ScriptError, ScriptRuntimeError, ScriptSyntaxError, StudioBusyError, } from "./exceptions.js";
|
|
4
|
+
export { ScriptBuilder } from "./scriptBuilder.js";
|
|
5
|
+
export { Batch, BatchFuture, buildOperationsScript, DEFAULT_MAX_OPERATIONS, DEFAULT_MAX_SCRIPT_LENGTH } from "./batch.js";
|
|
6
|
+
export { executeLong } from "./polling.js";
|
|
7
|
+
export { AxisRemap, BoundingBox, Quat, Vec3, Y_UP_TO_Z_UP } from "./math3.js";
|
|
8
|
+
export { DazElement } from "./element.js";
|
|
9
|
+
export { DazProperty } from "./property.js";
|
|
10
|
+
export { DazNode } from "./node.js";
|
|
11
|
+
export { DazBone } from "./bone.js";
|
|
12
|
+
export { DazCamera } from "./camera.js";
|
|
13
|
+
export { DazLight } from "./light.js";
|
|
14
|
+
export { DazSkeleton } from "./skeleton.js";
|
|
15
|
+
export { DazMaterial } from "./material.js";
|
|
16
|
+
export { DazModifier } from "./modifier.js";
|
|
17
|
+
export { DazMorph } from "./morph.js";
|
|
18
|
+
export { DazDForce } from "./dforce.js";
|
|
19
|
+
export { DazScene } from "./scene.js";
|
|
20
|
+
export { DazGeometry } from "./geometry.js";
|
|
21
|
+
export { DazViewport } from "./viewport.js";
|
|
22
|
+
export { DazTimeline } from "./timeline.js";
|
|
23
|
+
export { UndoGroup, withUndo } from "./undo.js";
|
|
24
|
+
export { DazRenderSettings } from "./render.js";
|
|
25
|
+
export { render, renderVariants } from "./renderApi.js";
|
|
26
|
+
// ── Phase 4: capture/restore and domain helpers ────────────────────────────
|
|
27
|
+
export { DazPose } from "./pose.js";
|
|
28
|
+
export { DazSceneState } from "./sceneState.js";
|
|
29
|
+
export { DazAnimation } from "./animation.js";
|
|
30
|
+
export { sphericalOffset, lookAtEuler, resolveTarget } from "./shotGeometry.js";
|
|
31
|
+
export { applyPose, resetTransforms, zeroFigure } from "./poses.js";
|
|
32
|
+
export { applyIrayMaterial, applyTextureMap, getSurfaceProperty, setSurfaceProperty } from "./materials.js";
|
|
33
|
+
export { applyHdriEnvironment, applyThreePointLightSetup, setLightColor } from "./lighting.js";
|
|
34
|
+
export { applyAnimatedShot, applyFrameSubject, applyOrbitCamera, applyStaticShot } from "./cinematics.js";
|
|
35
|
+
export { watchSceneEvents, waitForSceneEvent } from "./sceneEvents.js";
|
|
36
|
+
export { MIN_SERVER_VERSION, parseVersion, evaluateServerVersion } from "./version.js";
|
package/dist/light.d.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { DazNode } from "./node.js";
|
|
2
|
+
/** Proxy for a `DzLight` node. Extends `DazNode` with light-specific properties. */
|
|
3
|
+
export declare class DazLight extends DazNode {
|
|
4
|
+
intensity(): Promise<number | null>;
|
|
5
|
+
setIntensity(value: number): Promise<void>;
|
|
6
|
+
/** Diffuse colour as `{r, g, b}` (0-255, read-only; use {@link setColor} to change). */
|
|
7
|
+
color(): Promise<{
|
|
8
|
+
r: number;
|
|
9
|
+
g: number;
|
|
10
|
+
b: number;
|
|
11
|
+
} | null>;
|
|
12
|
+
setColor(r: number, g: number, b: number): Promise<void>;
|
|
13
|
+
shadowType(): Promise<string | null>;
|
|
14
|
+
illumination(): Promise<string | null>;
|
|
15
|
+
isOn(): Promise<boolean>;
|
|
16
|
+
isDirectional(): Promise<boolean>;
|
|
17
|
+
isAreaLight(): Promise<boolean>;
|
|
18
|
+
/** World-space direction vector `{x, y, z}`, or `null` when the light is not directional. */
|
|
19
|
+
direction(): Promise<{
|
|
20
|
+
x: number;
|
|
21
|
+
y: number;
|
|
22
|
+
z: number;
|
|
23
|
+
} | null>;
|
|
24
|
+
}
|
package/dist/light.js
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { DazNode } from "./node.js";
|
|
2
|
+
import { ScriptBuilder } from "./scriptBuilder.js";
|
|
3
|
+
/** Proxy for a `DzLight` node. Extends `DazNode` with light-specific properties. */
|
|
4
|
+
export class DazLight extends DazNode {
|
|
5
|
+
async intensity() {
|
|
6
|
+
return (await this.getProperty("Intensity"));
|
|
7
|
+
}
|
|
8
|
+
async setIntensity(value) {
|
|
9
|
+
await this.setProperty("Intensity", value);
|
|
10
|
+
}
|
|
11
|
+
/** Diffuse colour as `{r, g, b}` (0-255, read-only; use {@link setColor} to change). */
|
|
12
|
+
async color() {
|
|
13
|
+
const script = this.nodeScript(" var c = _node.getDiffuseColor();\n return {r: c.red, g: c.green, b: c.blue};\n ");
|
|
14
|
+
return (await this.client.execute(script)).value;
|
|
15
|
+
}
|
|
16
|
+
async setColor(r, g, b) {
|
|
17
|
+
const script = this.nodeScript(`var p = _node.findPropertyByLabel('Color'); if (p) p.setColorValue(new Color(${ScriptBuilder.serializeArg(Math.trunc(r))}, ${ScriptBuilder.serializeArg(Math.trunc(g))}, ${ScriptBuilder.serializeArg(Math.trunc(b))}));`);
|
|
18
|
+
await this.client.execute(script);
|
|
19
|
+
}
|
|
20
|
+
async shadowType() {
|
|
21
|
+
return (await this.getProperty("Shadow Type"));
|
|
22
|
+
}
|
|
23
|
+
async illumination() {
|
|
24
|
+
return (await this.getProperty("Illumination"));
|
|
25
|
+
}
|
|
26
|
+
async isOn() {
|
|
27
|
+
return Boolean((await this.client.execute(this.nodeScript("return _node.isOn();"))).value);
|
|
28
|
+
}
|
|
29
|
+
async isDirectional() {
|
|
30
|
+
return Boolean((await this.client.execute(this.nodeScript("return _node.isDirectional();"))).value);
|
|
31
|
+
}
|
|
32
|
+
async isAreaLight() {
|
|
33
|
+
return Boolean((await this.client.execute(this.nodeScript("return _node.isAreaLight();"))).value);
|
|
34
|
+
}
|
|
35
|
+
/** World-space direction vector `{x, y, z}`, or `null` when the light is not directional. */
|
|
36
|
+
async direction() {
|
|
37
|
+
const script = this.nodeScript("if (!_node.isDirectional()) return null; var d = _node.getWSDirection(); return {x: d.x, y: d.y, z: d.z};");
|
|
38
|
+
return (await this.client.execute(script)).value;
|
|
39
|
+
}
|
|
40
|
+
}
|