@zephyr3d/scene 0.9.6 → 0.9.8
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/dist/animation/animationset.js +52 -55
- package/dist/animation/animationset.js.map +1 -1
- package/dist/animation/joint_dynamics/controller.js +92 -32
- package/dist/animation/joint_dynamics/controller.js.map +1 -1
- package/dist/animation/joint_dynamics/convex_collider.js +320 -0
- package/dist/animation/joint_dynamics/convex_collider.js.map +1 -0
- package/dist/animation/joint_dynamics/joint_dynamics_system.js +57 -19
- package/dist/animation/joint_dynamics/joint_dynamics_system.js.map +1 -1
- package/dist/animation/joint_dynamics/solver.js +71 -27
- package/dist/animation/joint_dynamics/solver.js.map +1 -1
- package/dist/animation/joint_dynamics_modifier.js +4 -3
- package/dist/animation/joint_dynamics_modifier.js.map +1 -1
- package/dist/animation/skeleton.js +7 -10
- package/dist/animation/skeleton.js.map +1 -1
- package/dist/app/engine.js +3 -9
- package/dist/app/engine.js.map +1 -1
- package/dist/app/scriptregistry.js +47 -16
- package/dist/app/scriptregistry.js.map +1 -1
- package/dist/asset/assetmanager.js +3 -1
- package/dist/asset/assetmanager.js.map +1 -1
- package/dist/asset/model.js +346 -7
- package/dist/asset/model.js.map +1 -1
- package/dist/avatar/wardrobe.js +7 -3
- package/dist/avatar/wardrobe.js.map +1 -1
- package/dist/camera/camera.js +240 -34
- package/dist/camera/camera.js.map +1 -1
- package/dist/index.d.ts +1350 -622
- package/dist/index.js +6 -11
- package/dist/index.js.map +1 -1
- package/dist/material/blinn.js +1 -1
- package/dist/material/blinn.js.map +1 -1
- package/dist/material/lambert.js +1 -1
- package/dist/material/lambert.js.map +1 -1
- package/dist/material/material.js +23 -1
- package/dist/material/material.js.map +1 -1
- package/dist/material/meshmaterial.js +178 -23
- package/dist/material/meshmaterial.js.map +1 -1
- package/dist/material/mixins/albedocolor.js +4 -4
- package/dist/material/mixins/albedocolor.js.map +1 -1
- package/dist/material/mixins/lightmodel/blinnphong.js +2 -1
- package/dist/material/mixins/lightmodel/blinnphong.js.map +1 -1
- package/dist/material/mixins/lightmodel/lambert.js +2 -1
- package/dist/material/mixins/lightmodel/lambert.js.map +1 -1
- package/dist/material/mixins/lightmodel/pbrblueprintmixin.js +63 -16
- package/dist/material/mixins/lightmodel/pbrblueprintmixin.js.map +1 -1
- package/dist/material/mixins/lightmodel/pbrmetallicroughness.js +100 -27
- package/dist/material/mixins/lightmodel/pbrmetallicroughness.js.map +1 -1
- package/dist/material/mixins/lightmodel/pbrspecularglossness.js +16 -6
- package/dist/material/mixins/lightmodel/pbrspecularglossness.js.map +1 -1
- package/dist/material/mixins/lit.js +1 -1
- package/dist/material/mixins/lit.js.map +1 -1
- package/dist/material/mixins/pbr/common.js +276 -65
- package/dist/material/mixins/pbr/common.js.map +1 -1
- package/dist/material/mixins/texture.js +3 -3
- package/dist/material/mixins/texture.js.map +1 -1
- package/dist/material/mixins/vertexcolor.js +2 -2
- package/dist/material/mixins/vertexcolor.js.map +1 -1
- package/dist/material/mtoon.js +574 -0
- package/dist/material/mtoon.js.map +1 -0
- package/dist/material/pbrblueprint.js +494 -331
- package/dist/material/pbrblueprint.js.map +1 -1
- package/dist/material/pbrmr.js +118 -100
- package/dist/material/pbrmr.js.map +1 -1
- package/dist/material/pbrsg.js +1 -1
- package/dist/material/pbrsg.js.map +1 -1
- package/dist/material/shader/helper.js +45 -15
- package/dist/material/shader/helper.js.map +1 -1
- package/dist/material/subsurfaceprofile.js +812 -0
- package/dist/material/subsurfaceprofile.js.map +1 -0
- package/dist/material/unlit.js +1 -1
- package/dist/material/unlit.js.map +1 -1
- package/dist/posteffect/compositor.js +46 -11
- package/dist/posteffect/compositor.js.map +1 -1
- package/dist/posteffect/ssr.js +413 -87
- package/dist/posteffect/ssr.js.map +1 -1
- package/dist/posteffect/sss.js +1053 -0
- package/dist/posteffect/sss.js.map +1 -0
- package/dist/posteffect/taa.js +61 -60
- package/dist/posteffect/taa.js.map +1 -1
- package/dist/render/abuffer_oit.js +63 -12
- package/dist/render/abuffer_oit.js.map +1 -1
- package/dist/render/cluster_light.js +6 -5
- package/dist/render/cluster_light.js.map +1 -1
- package/dist/render/drawable.js +1 -5
- package/dist/render/drawable.js.map +1 -1
- package/dist/render/drawable_mixin.js +2 -1
- package/dist/render/drawable_mixin.js.map +1 -1
- package/dist/render/fbm_wavegenerator.js +2 -1
- package/dist/render/fbm_wavegenerator.js.map +1 -1
- package/dist/render/gerstner_wavegenerator.js +2 -1
- package/dist/render/gerstner_wavegenerator.js.map +1 -1
- package/dist/render/globalbindgroup_allocator.js +2 -1
- package/dist/render/globalbindgroup_allocator.js.map +1 -1
- package/dist/render/lightpass.js +105 -18
- package/dist/render/lightpass.js.map +1 -1
- package/dist/render/render_queue.js +51 -8
- package/dist/render/render_queue.js.map +1 -1
- package/dist/render/renderer.js +73 -59
- package/dist/render/renderer.js.map +1 -1
- package/dist/render/rendergraph/device_pool_allocator.js +8 -0
- package/dist/render/rendergraph/device_pool_allocator.js.map +1 -1
- package/dist/render/rendergraph/forward_plus_builder.js +481 -95
- package/dist/render/rendergraph/forward_plus_builder.js.map +1 -1
- package/dist/render/rendergraph/history_resource_manager.js +55 -0
- package/dist/render/rendergraph/history_resource_manager.js.map +1 -1
- package/dist/render/rendergraph/history_resources.js +3 -1
- package/dist/render/rendergraph/history_resources.js.map +1 -1
- package/dist/render/rendergraph/types.js.map +1 -1
- package/dist/render/renderpass.js +10 -4
- package/dist/render/renderpass.js.map +1 -1
- package/dist/render/sky.js +31 -1
- package/dist/render/sky.js.map +1 -1
- package/dist/render/weightedblended_oit.js +23 -5
- package/dist/render/weightedblended_oit.js.map +1 -1
- package/dist/scene/basesprite.js +4 -2
- package/dist/scene/basesprite.js.map +1 -1
- package/dist/scene/batchgroup.js +3 -1
- package/dist/scene/batchgroup.js.map +1 -1
- package/dist/scene/environment.js +11 -1
- package/dist/scene/environment.js.map +1 -1
- package/dist/scene/light.js +21 -3
- package/dist/scene/light.js.map +1 -1
- package/dist/scene/mesh.js +29 -14
- package/dist/scene/mesh.js.map +1 -1
- package/dist/scene/meshdrawable.js +6 -0
- package/dist/scene/meshdrawable.js.map +1 -1
- package/dist/scene/msdftext.js +5 -2
- package/dist/scene/msdftext.js.map +1 -1
- package/dist/scene/msdftextsprite.js +5 -3
- package/dist/scene/msdftextsprite.js.map +1 -1
- package/dist/scene/particlesys.js +3 -1
- package/dist/scene/particlesys.js.map +1 -1
- package/dist/scene/scene.js +6 -5
- package/dist/scene/scene.js.map +1 -1
- package/dist/scene/terrain-cm/grass.js +4 -2
- package/dist/scene/terrain-cm/grass.js.map +1 -1
- package/dist/scene/terrain-cm/grassmaterial.js +2 -1
- package/dist/scene/terrain-cm/grassmaterial.js.map +1 -1
- package/dist/scene/terrain-cm/terrain-cm.js +4 -2
- package/dist/scene/terrain-cm/terrain-cm.js.map +1 -1
- package/dist/scene/water.js +4 -2
- package/dist/scene/water.js.map +1 -1
- package/dist/shaders/shadow.js +26 -393
- package/dist/shaders/shadow.js.map +1 -1
- package/dist/shadow/esm.js +112 -12
- package/dist/shadow/esm.js.map +1 -1
- package/dist/shadow/pcf_opt.js +2 -2
- package/dist/shadow/pcf_opt.js.map +1 -1
- package/dist/shadow/pcf_pd.js +19 -10
- package/dist/shadow/pcf_pd.js.map +1 -1
- package/dist/shadow/shader.js +58 -7
- package/dist/shadow/shader.js.map +1 -1
- package/dist/shadow/shadow_impl.js +6 -0
- package/dist/shadow/shadow_impl.js.map +1 -1
- package/dist/shadow/shadow_region.js +229 -0
- package/dist/shadow/shadow_region.js.map +1 -0
- package/dist/shadow/shadowmapper.js +67 -59
- package/dist/shadow/shadowmapper.js.map +1 -1
- package/dist/shadow/vsm.js +45 -19
- package/dist/shadow/vsm.js.map +1 -1
- package/dist/utility/blueprint/common/constants.js +8 -8
- package/dist/utility/blueprint/common/constants.js.map +1 -1
- package/dist/utility/blueprint/material/pbr.js +31 -4
- package/dist/utility/blueprint/material/pbr.js.map +1 -1
- package/dist/utility/blueprint/material/texture.js +1 -17
- package/dist/utility/blueprint/material/texture.js.map +1 -1
- package/dist/utility/serialization/manager.js +66 -98
- package/dist/utility/serialization/manager.js.map +1 -1
- package/dist/utility/serialization/scene/animation.js +5 -2
- package/dist/utility/serialization/scene/animation.js.map +1 -1
- package/dist/utility/serialization/scene/batch.js +4 -1
- package/dist/utility/serialization/scene/batch.js.map +1 -1
- package/dist/utility/serialization/scene/camera.js +249 -54
- package/dist/utility/serialization/scene/camera.js.map +1 -1
- package/dist/utility/serialization/scene/common.js +37 -1
- package/dist/utility/serialization/scene/common.js.map +1 -1
- package/dist/utility/serialization/scene/light.js +42 -3
- package/dist/utility/serialization/scene/light.js.map +1 -1
- package/dist/utility/serialization/scene/material.js +1112 -646
- package/dist/utility/serialization/scene/material.js.map +1 -1
- package/dist/utility/serialization/scene/mesh.js +7 -4
- package/dist/utility/serialization/scene/mesh.js.map +1 -1
- package/dist/utility/serialization/scene/node.js +31 -12
- package/dist/utility/serialization/scene/node.js.map +1 -1
- package/dist/utility/serialization/scene/particle.js +4 -1
- package/dist/utility/serialization/scene/particle.js.map +1 -1
- package/dist/utility/serialization/scene/primitive.js +3 -1
- package/dist/utility/serialization/scene/primitive.js.map +1 -1
- package/dist/utility/serialization/scene/scene.js +18 -0
- package/dist/utility/serialization/scene/scene.js.map +1 -1
- package/dist/utility/serialization/scene/sprite.js +6 -3
- package/dist/utility/serialization/scene/sprite.js.map +1 -1
- package/dist/utility/serialization/scene/terrain.js +5 -2
- package/dist/utility/serialization/scene/terrain.js.map +1 -1
- package/dist/utility/serialization/scene/text.js +3 -1
- package/dist/utility/serialization/scene/text.js.map +1 -1
- package/dist/utility/serialization/scene/water.js +4 -1
- package/dist/utility/serialization/scene/water.js.map +1 -1
- package/dist/utility/textures/ltcdata.js +6 -0
- package/dist/utility/textures/ltcdata.js.map +1 -0
- package/dist/utility/textures/ltclut.js +61 -0
- package/dist/utility/textures/ltclut.js.map +1 -0
- package/dist/values.js +9 -1
- package/dist/values.js.map +1 -1
- package/package.json +3 -3
package/dist/asset/model.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Vector3, Quaternion, Matrix4x4, Disposable, uint8ArrayToBase64, ASSERT, DRef, Vector4 } from '@zephyr3d/base';
|
|
1
|
+
import { Vector3, Quaternion, Matrix4x4, Disposable, PathUtils, uint8ArrayToBase64, ASSERT, DRef, Vector4 } from '@zephyr3d/base';
|
|
2
2
|
import { getVertexFormatComponentCount } from '@zephyr3d/device';
|
|
3
3
|
import { Mesh } from '../scene/mesh.js';
|
|
4
4
|
import { BoundingBox } from '../utility/bounding_volume.js';
|
|
@@ -21,6 +21,7 @@ import { Primitive } from '../render/primitive.js';
|
|
|
21
21
|
import { UnlitMaterial } from '../material/unlit.js';
|
|
22
22
|
import { PBRSpecularGlossinessMaterial } from '../material/pbrsg.js';
|
|
23
23
|
import { PBRMetallicRoughnessMaterial } from '../material/pbrmr.js';
|
|
24
|
+
import { MToonMaterial } from '../material/mtoon.js';
|
|
24
25
|
|
|
25
26
|
/**
|
|
26
27
|
* Named object interface for model loading
|
|
@@ -181,6 +182,7 @@ import { PBRMetallicRoughnessMaterial } from '../material/pbrmr.js';
|
|
|
181
182
|
/** Joints of the skeleton */ joints;
|
|
182
183
|
/** Inverse of the binding matrices of the joints */ inverseBindMatrices;
|
|
183
184
|
/** Binding pose matrices of the joints */ bindPose;
|
|
185
|
+
/** Explicit humanoid joint mapping, when supplied by the source asset. */ humanoidJointMapping;
|
|
184
186
|
/**
|
|
185
187
|
* Creates an instance of AssetSkeleton
|
|
186
188
|
* @param name - Name of the skeleton
|
|
@@ -191,6 +193,7 @@ import { PBRMetallicRoughnessMaterial } from '../material/pbrmr.js';
|
|
|
191
193
|
this.joints = [];
|
|
192
194
|
this.inverseBindMatrices = [];
|
|
193
195
|
this.bindPose = [];
|
|
196
|
+
this.humanoidJointMapping = null;
|
|
194
197
|
}
|
|
195
198
|
/**
|
|
196
199
|
* Adds a joint to the skeleton
|
|
@@ -327,6 +330,202 @@ import { PBRMetallicRoughnessMaterial } from '../material/pbrmr.js';
|
|
|
327
330
|
addPrimitive(prim) {
|
|
328
331
|
this._primitiveList.push(prim);
|
|
329
332
|
}
|
|
333
|
+
sanitizeResourceName(name, fallback) {
|
|
334
|
+
let normalized = (name ?? '').trim();
|
|
335
|
+
if (!normalized) {
|
|
336
|
+
normalized = fallback;
|
|
337
|
+
}
|
|
338
|
+
normalized = normalized.replace(/[<>:"/\\|?*\u0000-\u001f]/g, '_');
|
|
339
|
+
normalized = normalized.replace(/\s+/g, ' ').trim();
|
|
340
|
+
normalized = normalized.replace(/[. ]+$/g, '');
|
|
341
|
+
return normalized || fallback;
|
|
342
|
+
}
|
|
343
|
+
getReimportPoolKey(baseName, ext) {
|
|
344
|
+
return `${ext.toLowerCase()}|${baseName}`;
|
|
345
|
+
}
|
|
346
|
+
getResourceBasename(path, ext) {
|
|
347
|
+
return path ? PathUtils.basename(path, ext || PathUtils.extname(path)) : '';
|
|
348
|
+
}
|
|
349
|
+
getResourceNumericSuffix(baseName, candidateBaseName) {
|
|
350
|
+
if (candidateBaseName === baseName) {
|
|
351
|
+
return 0;
|
|
352
|
+
}
|
|
353
|
+
const match = new RegExp(`^${baseName.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}_([0-9]+)$`).exec(candidateBaseName);
|
|
354
|
+
return match ? Number.parseInt(match[1], 10) : Number.MAX_SAFE_INTEGER;
|
|
355
|
+
}
|
|
356
|
+
registerReusableResourcePath(pools, path) {
|
|
357
|
+
const ext = PathUtils.extname(path).toLowerCase();
|
|
358
|
+
const baseName = this.getResourceBasename(path, ext);
|
|
359
|
+
const register = (keyBaseName)=>{
|
|
360
|
+
const key = this.getReimportPoolKey(keyBaseName, ext);
|
|
361
|
+
let candidates = pools.get(key);
|
|
362
|
+
if (!candidates) {
|
|
363
|
+
candidates = new Set();
|
|
364
|
+
pools.set(key, candidates);
|
|
365
|
+
}
|
|
366
|
+
candidates.add(path);
|
|
367
|
+
};
|
|
368
|
+
register(baseName);
|
|
369
|
+
const strippedBaseName = baseName.replace(/_[0-9]+$/u, '');
|
|
370
|
+
if (strippedBaseName && strippedBaseName !== baseName) {
|
|
371
|
+
register(strippedBaseName);
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
collectReferencedAssetPaths(value, destPath, extensions, out) {
|
|
375
|
+
if (typeof value === 'string') {
|
|
376
|
+
const normalizedPath = PathUtils.normalize(value);
|
|
377
|
+
const ext = PathUtils.extname(normalizedPath).toLowerCase();
|
|
378
|
+
const normalizedDestPath = PathUtils.normalize(destPath);
|
|
379
|
+
if (extensions.has(ext) && (normalizedPath === normalizedDestPath || normalizedPath.startsWith(normalizedDestPath.endsWith('/') ? normalizedDestPath : `${normalizedDestPath}/`))) {
|
|
380
|
+
out.add(normalizedPath);
|
|
381
|
+
}
|
|
382
|
+
return;
|
|
383
|
+
}
|
|
384
|
+
if (Array.isArray(value)) {
|
|
385
|
+
for (const item of value){
|
|
386
|
+
this.collectReferencedAssetPaths(item, destPath, extensions, out);
|
|
387
|
+
}
|
|
388
|
+
return;
|
|
389
|
+
}
|
|
390
|
+
if (value && typeof value === 'object') {
|
|
391
|
+
for (const item of Object.values(value)){
|
|
392
|
+
this.collectReferencedAssetPaths(item, destPath, extensions, out);
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
async collectReferencedAssetPathsFromJsonFile(destVFS, jsonPath, destPath, extensions) {
|
|
397
|
+
if (!await destVFS.exists(jsonPath)) {
|
|
398
|
+
return new Set();
|
|
399
|
+
}
|
|
400
|
+
try {
|
|
401
|
+
const content = await destVFS.readFile(jsonPath, {
|
|
402
|
+
encoding: 'utf8'
|
|
403
|
+
});
|
|
404
|
+
const json = JSON.parse(content);
|
|
405
|
+
const out = new Set();
|
|
406
|
+
this.collectReferencedAssetPaths(json, destPath, extensions, out);
|
|
407
|
+
return out;
|
|
408
|
+
} catch (err) {
|
|
409
|
+
console.warn(`Read existing import manifest failed: ${jsonPath}: ${err}`);
|
|
410
|
+
return new Set();
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
async createReimportResourcePools(destVFS, destPath, prefabPath) {
|
|
414
|
+
const pools = new Map();
|
|
415
|
+
if (!await destVFS.exists(prefabPath)) {
|
|
416
|
+
return pools;
|
|
417
|
+
}
|
|
418
|
+
const materialAndMeshPaths = await this.collectReferencedAssetPathsFromJsonFile(destVFS, prefabPath, destPath, new Set([
|
|
419
|
+
'.zmtl',
|
|
420
|
+
'.zmsh'
|
|
421
|
+
]));
|
|
422
|
+
for (const path of materialAndMeshPaths){
|
|
423
|
+
this.registerReusableResourcePath(pools, path);
|
|
424
|
+
}
|
|
425
|
+
const materialPaths = Array.from(materialAndMeshPaths).filter((path)=>PathUtils.extname(path).toLowerCase() === '.zmtl');
|
|
426
|
+
const imageExtensions = new Set([
|
|
427
|
+
'.jpg',
|
|
428
|
+
'.jpeg',
|
|
429
|
+
'.png',
|
|
430
|
+
'.webp',
|
|
431
|
+
'.tga',
|
|
432
|
+
'.hdr',
|
|
433
|
+
'.ktx',
|
|
434
|
+
'.ktx2'
|
|
435
|
+
]);
|
|
436
|
+
for (const materialPath of materialPaths){
|
|
437
|
+
const texturePaths = await this.collectReferencedAssetPathsFromJsonFile(destVFS, materialPath, destPath, imageExtensions);
|
|
438
|
+
for (const texturePath of texturePaths){
|
|
439
|
+
this.registerReusableResourcePath(pools, texturePath);
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
return pools;
|
|
443
|
+
}
|
|
444
|
+
consumeReusableResourcePath(pools, baseName, ext, usedPaths) {
|
|
445
|
+
const candidates = pools.get(this.getReimportPoolKey(baseName, ext));
|
|
446
|
+
if (!candidates || candidates.size === 0) {
|
|
447
|
+
return null;
|
|
448
|
+
}
|
|
449
|
+
const sorted = Array.from(candidates).filter((path)=>!usedPaths.has(path)).sort((a, b)=>{
|
|
450
|
+
const aSuffix = this.getResourceNumericSuffix(baseName, this.getResourceBasename(a, ext));
|
|
451
|
+
const bSuffix = this.getResourceNumericSuffix(baseName, this.getResourceBasename(b, ext));
|
|
452
|
+
if (aSuffix !== bSuffix) {
|
|
453
|
+
return aSuffix - bSuffix;
|
|
454
|
+
}
|
|
455
|
+
return a.localeCompare(b);
|
|
456
|
+
});
|
|
457
|
+
const selected = sorted[0] ?? null;
|
|
458
|
+
if (selected) {
|
|
459
|
+
usedPaths.add(selected);
|
|
460
|
+
}
|
|
461
|
+
return selected;
|
|
462
|
+
}
|
|
463
|
+
async createUniqueResourcePath(destVFS, destPath, baseName, ext, usedPaths, fallback) {
|
|
464
|
+
const sanitizedBase = this.sanitizeResourceName(baseName, fallback);
|
|
465
|
+
for(let suffix = 0;; suffix++){
|
|
466
|
+
const candidateName = suffix > 0 ? `${sanitizedBase}_${suffix}` : sanitizedBase;
|
|
467
|
+
const candidatePath = destVFS.join(destPath, `${candidateName}${ext}`);
|
|
468
|
+
if (!usedPaths.has(candidatePath) && !await destVFS.exists(candidatePath)) {
|
|
469
|
+
usedPaths.add(candidatePath);
|
|
470
|
+
return candidatePath;
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
async tryReuseExactResourcePath(destVFS, destPath, baseName, ext, usedPaths, fallback) {
|
|
475
|
+
const sanitizedBase = this.sanitizeResourceName(baseName, fallback);
|
|
476
|
+
const candidatePath = destVFS.join(destPath, `${sanitizedBase}${ext}`);
|
|
477
|
+
if (!usedPaths.has(candidatePath) && await destVFS.exists(candidatePath)) {
|
|
478
|
+
usedPaths.add(candidatePath);
|
|
479
|
+
return candidatePath;
|
|
480
|
+
}
|
|
481
|
+
return null;
|
|
482
|
+
}
|
|
483
|
+
collapseCompositeTextureName(name) {
|
|
484
|
+
const normalized = (name ?? '').trim();
|
|
485
|
+
if (!normalized) {
|
|
486
|
+
return normalized;
|
|
487
|
+
}
|
|
488
|
+
const separatorIndex = normalized.indexOf('-');
|
|
489
|
+
if (separatorIndex <= 0 || separatorIndex >= normalized.length - 1) {
|
|
490
|
+
return normalized;
|
|
491
|
+
}
|
|
492
|
+
const left = normalized.slice(0, separatorIndex).trim();
|
|
493
|
+
const right = normalized.slice(separatorIndex + 1).trim();
|
|
494
|
+
if (!left || !right) {
|
|
495
|
+
return normalized;
|
|
496
|
+
}
|
|
497
|
+
const leftParts = left.split('_');
|
|
498
|
+
const rightParts = right.split('_');
|
|
499
|
+
let prefixLength = 0;
|
|
500
|
+
while(prefixLength < leftParts.length - 1 && prefixLength < rightParts.length - 1 && leftParts[prefixLength] === rightParts[prefixLength]){
|
|
501
|
+
prefixLength++;
|
|
502
|
+
}
|
|
503
|
+
if (prefixLength <= 0) {
|
|
504
|
+
return normalized;
|
|
505
|
+
}
|
|
506
|
+
const prefix = leftParts.slice(0, prefixLength).join('_');
|
|
507
|
+
const leftSuffix = leftParts.slice(prefixLength).join('_');
|
|
508
|
+
const rightSuffix = rightParts.slice(prefixLength).join('_');
|
|
509
|
+
if (!leftSuffix || !rightSuffix) {
|
|
510
|
+
return normalized;
|
|
511
|
+
}
|
|
512
|
+
return `${prefix}_${leftSuffix}-${rightSuffix}`;
|
|
513
|
+
}
|
|
514
|
+
getImageBaseName(img, index, fallback) {
|
|
515
|
+
if (img?.name?.trim()) {
|
|
516
|
+
return this.collapseCompositeTextureName(img.name);
|
|
517
|
+
}
|
|
518
|
+
if (img?.uri) {
|
|
519
|
+
return this.collapseCompositeTextureName(PathUtils.basename(img.uri, PathUtils.extname(img.uri)));
|
|
520
|
+
}
|
|
521
|
+
return `${fallback}_texture_${index}`;
|
|
522
|
+
}
|
|
523
|
+
getMaterialBaseName(material, key, fallback) {
|
|
524
|
+
return material?.name?.trim() || `${fallback}_material_${key}`;
|
|
525
|
+
}
|
|
526
|
+
getPrimitiveBaseName(info, index, fallback) {
|
|
527
|
+
return info?.name?.trim() || `${fallback}_mesh_${index}`;
|
|
528
|
+
}
|
|
330
529
|
/**
|
|
331
530
|
* Adds a model-level morph target group.
|
|
332
531
|
* @param group - Morph target group to add
|
|
@@ -430,6 +629,11 @@ import { PBRMetallicRoughnessMaterial } from '../material/pbrmr.js';
|
|
|
430
629
|
}
|
|
431
630
|
/** preprocess */ async preprocess(manager, name, destPath, srcVFS, dstVFS) {
|
|
432
631
|
const destName = name;
|
|
632
|
+
const usedPaths = new Set();
|
|
633
|
+
const rebuildMaterial = this._preprocessOptions?.rebuildMaterial ?? true;
|
|
634
|
+
const prefabName = name.endsWith('.zprefab') ? name : `${name}.zprefab`;
|
|
635
|
+
const prefabPath = dstVFS.join(destPath, prefabName);
|
|
636
|
+
const reusableResourcePools = await this.createReimportResourcePools(dstVFS, destPath, prefabPath);
|
|
433
637
|
if (this._imageList.length > 0) {
|
|
434
638
|
console.info(`Importing ${this._imageList.length} textures`);
|
|
435
639
|
for(let i = 0; i < this._imageList.length; i++){
|
|
@@ -457,7 +661,8 @@ import { PBRMetallicRoughnessMaterial } from '../material/pbrmr.js';
|
|
|
457
661
|
continue;
|
|
458
662
|
}
|
|
459
663
|
ASSERT(!!ext, `Unknown image mime type: ${mimeType}`);
|
|
460
|
-
const
|
|
664
|
+
const baseName = this.sanitizeResourceName(this.getImageBaseName(img, i, destName), `${destName}_texture_${i}`);
|
|
665
|
+
const path = await this.tryReuseExactResourcePath(dstVFS, destPath, baseName, ext, usedPaths, `${destName}_texture_${i}`) ?? this.consumeReusableResourcePath(reusableResourcePools, baseName, ext, usedPaths) ?? await this.createUniqueResourcePath(dstVFS, destPath, baseName, ext, usedPaths, `${destName}_texture_${i}`);
|
|
461
666
|
if (img.uri) {
|
|
462
667
|
img.data = new Uint8Array(await srcVFS.readFile(img.uri, {
|
|
463
668
|
encoding: 'binary'
|
|
@@ -476,8 +681,16 @@ import { PBRMetallicRoughnessMaterial } from '../material/pbrmr.js';
|
|
|
476
681
|
if (materialKeys.length > 0) {
|
|
477
682
|
console.info(`Importing ${materialKeys.length} materials`);
|
|
478
683
|
for (const k of materialKeys){
|
|
479
|
-
const
|
|
480
|
-
const
|
|
684
|
+
const material = this._materialList[k];
|
|
685
|
+
const baseName = this.sanitizeResourceName(this.getMaterialBaseName(material, k, destName), `${destName}_material_${k}`);
|
|
686
|
+
const path = await this.tryReuseExactResourcePath(dstVFS, destPath, baseName, '.zmtl', usedPaths, `${destName}_material_${k}`) ?? this.consumeReusableResourcePath(reusableResourcePools, baseName, '.zmtl', usedPaths) ?? await this.createUniqueResourcePath(dstVFS, destPath, baseName, '.zmtl', usedPaths, `${destName}_material_${k}`);
|
|
687
|
+
if (!rebuildMaterial && await dstVFS.exists(path)) {
|
|
688
|
+
material.path = path;
|
|
689
|
+
continue;
|
|
690
|
+
}
|
|
691
|
+
material.path = '';
|
|
692
|
+
const m = await this.createMaterial(manager, material, dstVFS);
|
|
693
|
+
material.path = path;
|
|
481
694
|
const data = await manager.serializeObject(m);
|
|
482
695
|
const content = JSON.stringify({
|
|
483
696
|
type: 'Default',
|
|
@@ -487,7 +700,6 @@ import { PBRMetallicRoughnessMaterial } from '../material/pbrmr.js';
|
|
|
487
700
|
encoding: 'utf8',
|
|
488
701
|
create: true
|
|
489
702
|
});
|
|
490
|
-
this._materialList[k].path = path;
|
|
491
703
|
m.dispose();
|
|
492
704
|
}
|
|
493
705
|
}
|
|
@@ -498,7 +710,8 @@ import { PBRMetallicRoughnessMaterial } from '../material/pbrmr.js';
|
|
|
498
710
|
if (!info) {
|
|
499
711
|
continue;
|
|
500
712
|
}
|
|
501
|
-
const
|
|
713
|
+
const baseName = this.sanitizeResourceName(this.getPrimitiveBaseName(info, i, destName), `${destName}_mesh_${i}`);
|
|
714
|
+
const path = await this.tryReuseExactResourcePath(dstVFS, destPath, baseName, '.zmsh', usedPaths, `${destName}_mesh_${i}`) ?? this.consumeReusableResourcePath(reusableResourcePools, baseName, '.zmsh', usedPaths) ?? await this.createUniqueResourcePath(dstVFS, destPath, baseName, '.zmsh', usedPaths, `${destName}_mesh_${i}`);
|
|
502
715
|
await SharedModel.writePrimitive(dstVFS, info, path);
|
|
503
716
|
info.path = path;
|
|
504
717
|
}
|
|
@@ -641,6 +854,30 @@ import { PBRMetallicRoughnessMaterial } from '../material/pbrmr.js';
|
|
|
641
854
|
}
|
|
642
855
|
return null;
|
|
643
856
|
}
|
|
857
|
+
remapHumanoidJointMapping(mapping, nodeMap) {
|
|
858
|
+
if (!mapping) {
|
|
859
|
+
return null;
|
|
860
|
+
}
|
|
861
|
+
const remap = (source)=>{
|
|
862
|
+
if (!source) {
|
|
863
|
+
return undefined;
|
|
864
|
+
}
|
|
865
|
+
const result = {};
|
|
866
|
+
for (const key of Object.keys(source)){
|
|
867
|
+
const node = nodeMap.get(source[key]);
|
|
868
|
+
if (node) {
|
|
869
|
+
result[key] = node;
|
|
870
|
+
}
|
|
871
|
+
}
|
|
872
|
+
return Object.keys(result).length > 0 ? result : undefined;
|
|
873
|
+
};
|
|
874
|
+
const body = remap(mapping.body);
|
|
875
|
+
return body ? {
|
|
876
|
+
body,
|
|
877
|
+
leftHand: remap(mapping.leftHand),
|
|
878
|
+
rightHand: remap(mapping.rightHand)
|
|
879
|
+
} : null;
|
|
880
|
+
}
|
|
644
881
|
async createSceneNode(manager, scene, instancing, saveMeshes, saveSkeletons, saveAnimations, saveJointDynamics, srcVFS) {
|
|
645
882
|
const group = new SceneNode(scene);
|
|
646
883
|
const nodeMap = new Map();
|
|
@@ -674,7 +911,11 @@ import { PBRMetallicRoughnessMaterial } from '../material/pbrmr.js';
|
|
|
674
911
|
const rigKey = SkeletonRig.getRigKey(joints, rootJoint);
|
|
675
912
|
let rig = rigMap.get(rigKey);
|
|
676
913
|
if (!rig) {
|
|
677
|
-
|
|
914
|
+
const humanoidJointMapping = this.remapHumanoidJointMapping(sk.humanoidJointMapping, nodeMap);
|
|
915
|
+
rig = new SkeletonRig(joints, sk.bindPose, humanoidJointMapping ? {
|
|
916
|
+
rootJoint,
|
|
917
|
+
humanoidJointMapping
|
|
918
|
+
} : {
|
|
678
919
|
rootJoint
|
|
679
920
|
});
|
|
680
921
|
rigMap.set(rigKey, rig);
|
|
@@ -1100,6 +1341,18 @@ import { PBRMetallicRoughnessMaterial } from '../material/pbrmr.js';
|
|
|
1100
1341
|
}
|
|
1101
1342
|
return t;
|
|
1102
1343
|
}
|
|
1344
|
+
async function setMaterialTexture(material, propertyPrefix, textureInfo) {
|
|
1345
|
+
if (!textureInfo) {
|
|
1346
|
+
return;
|
|
1347
|
+
}
|
|
1348
|
+
const info = await getTextureInfo(textureInfo);
|
|
1349
|
+
if (info) {
|
|
1350
|
+
material[`${propertyPrefix}Texture`] = info.texture;
|
|
1351
|
+
material[`${propertyPrefix}TextureSampler`] = info.sampler;
|
|
1352
|
+
material[`${propertyPrefix}TexCoordIndex`] = info.texCoord;
|
|
1353
|
+
material[`${propertyPrefix}TexCoordMatrix`] = info.transform;
|
|
1354
|
+
}
|
|
1355
|
+
}
|
|
1103
1356
|
if (assetMaterial.type === 'unlit') {
|
|
1104
1357
|
const unlitAssetMaterial = assetMaterial;
|
|
1105
1358
|
const unlitMaterial = new UnlitMaterial();
|
|
@@ -1123,6 +1376,92 @@ import { PBRMetallicRoughnessMaterial } from '../material/pbrmr.js';
|
|
|
1123
1376
|
unlitMaterial.cullMode = 'none';
|
|
1124
1377
|
}
|
|
1125
1378
|
return unlitMaterial;
|
|
1379
|
+
} else if (assetMaterial.type === 'mtoon') {
|
|
1380
|
+
const mtoonAssetMaterial = assetMaterial;
|
|
1381
|
+
const mtoonMaterial = new MToonMaterial();
|
|
1382
|
+
const mtoonTextureTarget = mtoonMaterial;
|
|
1383
|
+
mtoonMaterial.albedoColor = mtoonAssetMaterial.diffuse ?? Vector4.one();
|
|
1384
|
+
await setMaterialTexture(mtoonTextureTarget, 'albedo', mtoonAssetMaterial.diffuseMap);
|
|
1385
|
+
await setMaterialTexture(mtoonTextureTarget, 'normal', mtoonAssetMaterial.common.normalMap);
|
|
1386
|
+
mtoonMaterial.normalScale = mtoonAssetMaterial.common.bumpScale ?? 1;
|
|
1387
|
+
await setMaterialTexture(mtoonTextureTarget, 'emissive', mtoonAssetMaterial.common.emissiveMap);
|
|
1388
|
+
mtoonMaterial.emissiveColor = mtoonAssetMaterial.common.emissiveColor ?? Vector3.zero();
|
|
1389
|
+
mtoonMaterial.emissiveStrength = mtoonAssetMaterial.common.emissiveStrength ?? 1;
|
|
1390
|
+
if (mtoonAssetMaterial.shadeColorFactor) {
|
|
1391
|
+
mtoonMaterial.shadeColorFactor = mtoonAssetMaterial.shadeColorFactor;
|
|
1392
|
+
}
|
|
1393
|
+
await setMaterialTexture(mtoonTextureTarget, 'shadeMultiply', mtoonAssetMaterial.shadeMultiplyMap);
|
|
1394
|
+
if (mtoonAssetMaterial.shadingShiftFactor !== undefined) {
|
|
1395
|
+
mtoonMaterial.shadingShiftFactor = mtoonAssetMaterial.shadingShiftFactor;
|
|
1396
|
+
}
|
|
1397
|
+
await setMaterialTexture(mtoonTextureTarget, 'shadingShift', mtoonAssetMaterial.shadingShiftMap);
|
|
1398
|
+
if (mtoonAssetMaterial.shadingShiftTextureScale !== undefined) {
|
|
1399
|
+
mtoonMaterial.shadingShiftTextureScale = mtoonAssetMaterial.shadingShiftTextureScale;
|
|
1400
|
+
}
|
|
1401
|
+
if (mtoonAssetMaterial.shadingToonyFactor !== undefined) {
|
|
1402
|
+
mtoonMaterial.shadingToonyFactor = mtoonAssetMaterial.shadingToonyFactor;
|
|
1403
|
+
}
|
|
1404
|
+
if (mtoonAssetMaterial.giEqualizationFactor !== undefined) {
|
|
1405
|
+
mtoonMaterial.giEqualizationFactor = mtoonAssetMaterial.giEqualizationFactor;
|
|
1406
|
+
}
|
|
1407
|
+
if (mtoonAssetMaterial.matcapFactor) {
|
|
1408
|
+
mtoonMaterial.matcapFactor = mtoonAssetMaterial.matcapFactor;
|
|
1409
|
+
}
|
|
1410
|
+
await setMaterialTexture(mtoonTextureTarget, 'matcap', mtoonAssetMaterial.matcapMap);
|
|
1411
|
+
if (mtoonAssetMaterial.parametricRimColorFactor) {
|
|
1412
|
+
mtoonMaterial.parametricRimColorFactor = mtoonAssetMaterial.parametricRimColorFactor;
|
|
1413
|
+
}
|
|
1414
|
+
if (mtoonAssetMaterial.parametricRimFresnelPowerFactor !== undefined) {
|
|
1415
|
+
mtoonMaterial.parametricRimFresnelPowerFactor = mtoonAssetMaterial.parametricRimFresnelPowerFactor;
|
|
1416
|
+
}
|
|
1417
|
+
if (mtoonAssetMaterial.parametricRimLiftFactor !== undefined) {
|
|
1418
|
+
mtoonMaterial.parametricRimLiftFactor = mtoonAssetMaterial.parametricRimLiftFactor;
|
|
1419
|
+
}
|
|
1420
|
+
await setMaterialTexture(mtoonTextureTarget, 'rimMultiply', mtoonAssetMaterial.rimMultiplyMap);
|
|
1421
|
+
if (mtoonAssetMaterial.rimLightingMixFactor !== undefined) {
|
|
1422
|
+
mtoonMaterial.rimLightingMixFactor = mtoonAssetMaterial.rimLightingMixFactor;
|
|
1423
|
+
}
|
|
1424
|
+
if (mtoonAssetMaterial.outlineWidthMode !== undefined) {
|
|
1425
|
+
mtoonMaterial.outlineWidthMode = mtoonAssetMaterial.outlineWidthMode;
|
|
1426
|
+
}
|
|
1427
|
+
if (mtoonAssetMaterial.outlineWidthFactor !== undefined) {
|
|
1428
|
+
mtoonMaterial.outlineWidthFactor = mtoonAssetMaterial.outlineWidthFactor;
|
|
1429
|
+
}
|
|
1430
|
+
await setMaterialTexture(mtoonTextureTarget, 'outlineWidthMultiply', mtoonAssetMaterial.outlineWidthMultiplyMap);
|
|
1431
|
+
if (mtoonAssetMaterial.outlineColorFactor) {
|
|
1432
|
+
mtoonMaterial.outlineColorFactor = mtoonAssetMaterial.outlineColorFactor;
|
|
1433
|
+
}
|
|
1434
|
+
if (mtoonAssetMaterial.outlineLightingMixFactor !== undefined) {
|
|
1435
|
+
mtoonMaterial.outlineLightingMixFactor = mtoonAssetMaterial.outlineLightingMixFactor;
|
|
1436
|
+
}
|
|
1437
|
+
if (mtoonAssetMaterial.outlineUsesTangentNormals !== undefined) {
|
|
1438
|
+
mtoonMaterial.outlineUsesTangentNormals = mtoonAssetMaterial.outlineUsesTangentNormals;
|
|
1439
|
+
}
|
|
1440
|
+
await setMaterialTexture(mtoonTextureTarget, 'uvAnimationMask', mtoonAssetMaterial.uvAnimationMaskMap);
|
|
1441
|
+
if (mtoonAssetMaterial.uvAnimationScrollXSpeedFactor !== undefined) {
|
|
1442
|
+
mtoonMaterial.uvAnimationScrollXSpeedFactor = mtoonAssetMaterial.uvAnimationScrollXSpeedFactor;
|
|
1443
|
+
}
|
|
1444
|
+
if (mtoonAssetMaterial.uvAnimationScrollYSpeedFactor !== undefined) {
|
|
1445
|
+
mtoonMaterial.uvAnimationScrollYSpeedFactor = mtoonAssetMaterial.uvAnimationScrollYSpeedFactor;
|
|
1446
|
+
}
|
|
1447
|
+
if (mtoonAssetMaterial.uvAnimationRotationSpeedFactor !== undefined) {
|
|
1448
|
+
mtoonMaterial.uvAnimationRotationSpeedFactor = mtoonAssetMaterial.uvAnimationRotationSpeedFactor;
|
|
1449
|
+
}
|
|
1450
|
+
if (mtoonAssetMaterial.transparentWithZWrite !== undefined) {
|
|
1451
|
+
mtoonMaterial.transparentWithZWrite = mtoonAssetMaterial.transparentWithZWrite;
|
|
1452
|
+
}
|
|
1453
|
+
if (mtoonAssetMaterial.renderQueueOffsetNumber !== undefined) {
|
|
1454
|
+
mtoonMaterial.renderQueueOffsetNumber = mtoonAssetMaterial.renderQueueOffsetNumber;
|
|
1455
|
+
}
|
|
1456
|
+
if (mtoonAssetMaterial.common.alphaMode === 'blend') {
|
|
1457
|
+
mtoonMaterial.blendMode = 'blend';
|
|
1458
|
+
} else if (mtoonAssetMaterial.common.alphaMode === 'mask') {
|
|
1459
|
+
mtoonMaterial.alphaCutoff = mtoonAssetMaterial.common.alphaCutoff;
|
|
1460
|
+
}
|
|
1461
|
+
if (mtoonAssetMaterial.common.doubleSided) {
|
|
1462
|
+
mtoonMaterial.cullMode = 'none';
|
|
1463
|
+
}
|
|
1464
|
+
return mtoonMaterial;
|
|
1126
1465
|
} else if (assetMaterial.type === 'pbrSpecularGlossiness') {
|
|
1127
1466
|
const assetPBRMaterial = assetMaterial;
|
|
1128
1467
|
const pbrMaterial = new PBRSpecularGlossinessMaterial();
|