Skip to content

armgit / 67.js

Public Imported from GitHub
0

3D engine that AI agents drive

Merge branch 'worktree-agent-ac94db60707e86e34' into feat/scene-kits

Nguyen Xuan An017c497b561a
diff --cc docs/gltf.md
index 88ce5ef5,6008f4e8..5a297fa4
--- a/docs/gltf.md
+++ b/docs/gltf.md
@@@ -123,10 -124,53 +124,53 @@@ Disposal is idempotent, and subsequent
The bridge supports triangle meshes, PNG/JPEG base color textures, rigid animations, and metallic-roughness material factors.
It also supports `KHR_mesh_quantization` and `KHR_materials_emissive_strength`.
--The importer rejects alpha blending, alpha masking, double-sided materials and vertex transparency.
++Alpha masking, alpha blending and double-sided materials import onto `alphaMode`, `alphaCutoff`, `opacity` and `doubleSided` (see the material maps guide). Vertex transparency is still rejected.
It supports base-color, normal, metallic-roughness, occlusion and emissive texture channels.
- It rejects texture transforms, DRACO, KTX2, GPU instancing, and unsupported extensions, including optional extensions.
+ It rejects unknown extensions, including optional ones.
Line and point primitives are unsupported.
+
+ ## Extensions
+
+ | Extension | Behavior |
+ | --- | --- |
+ | `KHR_mesh_quantization`, `KHR_materials_emissive_strength` | Supported. |
+ | `KHR_texture_transform` | Offset, rotation and scale are baked into `geometry.uvs`. All maps of one material must share one transform, otherwise the import fails. `texCoord` overrides are rejected. |
+ | `EXT_mesh_gpu_instancing` | The node expands into one part per instance and primitive. Parts of one primitive share one geometry object, so the renderer batches them. Skinned or morphed instancing is rejected. |
+ | `KHR_draco_mesh_compression` | Needs `options.decoders.draco`. |
+ | `EXT_meshopt_compression` | Needs `options.decoders.meshopt`. |
+ | `KHR_texture_basisu` | Needs `options.decoders.ktx2`. |
+ | `KHR_materials_clearcoat`, `_transmission`, `_ior`, `_specular`, `_sheen`, `_volume` | Accepted but not rendered. Each one used adds a line to `asset.warnings`. Listing one in `extensionsRequired` fails the import. |
+
+ `KHR_materials_transmission` with a factor above zero sets `material.transmission` to that factor.
+ It is a hint only: the renderer does not draw transmission yet.
+
+ Without the matching decoder, a file that uses a compression extension fails with `Unsupported glTF extension` and the option name.
+
+ ### Decoders
+
+ The decoders are the Three.js loaders. 67.js does not bundle or fetch their wasm files, so you choose where they are served.
+
+ ```js
+ import { DRACOLoader } from 'three/addons/loaders/DRACOLoader.js';
+ import { KTX2Loader } from 'three/addons/loaders/KTX2Loader.js';
+ import { MeshoptDecoder } from 'three/addons/libs/meshopt_decoder.module.js';
+
+ const draco = new DRACOLoader().setDecoderPath('/vendor/draco/'); // copy three/examples/jsm/libs/draco/
+ const ktx2 = new KTX2Loader().setTranscoderPath('/vendor/basis/'); // copy three/examples/jsm/libs/basis/
+ // Transcode to RGBA8 only: the renderer uploads plain pixels, not GPU-compressed formats.
+ ktx2.workerConfig = { astcSupported: false, astcHDRSupported: false, etc1Supported: false, etc2Supported: false, dxtSupported: false, bptcSupported: false, pvrtcSupported: false };
+
+ const asset = await loadGltf('/models/car.glb', { decoders: { draco, ktx2, meshopt: MeshoptDecoder } });
+ ```
+
+ Any subset works. Draco and KTX2 decode in browser workers. Dispose the loaders yourself when done (`draco.dispose()`, `ktx2.dispose()`).
+ A KTX2 texture that decodes to a GPU-compressed format fails with a message that points back to this setting.
+ KTX2 dimensions count toward `maxTexturePixels` before decoding.
+
+ ### Instancing limits
+
+ `maxInstances` (default 4,096) caps the instances of one node, and `maxParts` still caps the total number of parts.
+ Both are checked from the accessor counts before any data is decoded.
The bridge does not import cameras, lights or scene environments into Renderer67.
The caller supplies its own camera and lighting.
diff --cc src/gltf.js
index ea743d13,8f832e46..bc064f1c
--- a/src/gltf.js
+++ b/src/gltf.js
@@@ -6,14 -6,19 +6,20 @@@ import { MAX_MORPH_TARGETS, createMorph
export const GLTF_CAPABILITIES = Object.freeze({
formats: ['glb', 'gltf'],
- supported: ['triangle meshes', 'world transforms', 'rigid node animations', 'four-influence skeletal skinning', 'joint node animations', 'relative POSITION/NORMAL morph targets', 'morph weight animations', 'PNG/JPEG base color textures', 'normal/occlusion/emissive/metallic-roughness textures', 'TEXCOORD_0', 'linear RGB vertex colors', 'metallic roughness factors', 'emissive factors', 'alpha mask and blend modes', 'double-sided materials', 'KHR_mesh_quantization', 'KHR_materials_emissive_strength'],
- unsupported: ['more than four skin influences', 'singular weighted skin transforms', 'reflected skin transforms', 'TANGENT morph targets', 'morph targets without authored base normals', 'vertex alpha below one', 'texture transforms', 'DRACO', 'KTX2', 'GPU instancing'],
- supported: ['triangle meshes', 'world transforms', 'rigid node animations', 'four-influence skeletal skinning', 'joint node animations', 'relative POSITION/NORMAL morph targets', 'morph weight animations', 'PNG/JPEG base color textures', 'normal/occlusion/emissive/metallic-roughness textures', 'TEXCOORD_0', 'linear RGB vertex colors', 'metallic roughness factors', 'emissive factors', 'KHR_mesh_quantization', 'KHR_materials_emissive_strength', 'KHR_texture_transform baked into UVs', 'EXT_mesh_gpu_instancing expanded into parts', 'KHR_draco_mesh_compression with options.decoders.draco', 'EXT_meshopt_compression with options.decoders.meshopt', 'KHR_texture_basisu with options.decoders.ktx2'],
++ supported: ['triangle meshes', 'world transforms', 'rigid node animations', 'four-influence skeletal skinning', 'joint node animations', 'relative POSITION/NORMAL morph targets', 'morph weight animations', 'PNG/JPEG base color textures', 'normal/occlusion/emissive/metallic-roughness textures', 'TEXCOORD_0', 'linear RGB vertex colors', 'metallic roughness factors', 'emissive factors', 'alpha mask and blend modes', 'double-sided materials', 'KHR_mesh_quantization', 'KHR_materials_emissive_strength', 'KHR_texture_transform baked into UVs', 'EXT_mesh_gpu_instancing expanded into parts', 'KHR_draco_mesh_compression with options.decoders.draco', 'EXT_meshopt_compression with options.decoders.meshopt', 'KHR_texture_basisu with options.decoders.ktx2'],
+ ignoredExtensions: ['KHR_materials_clearcoat', 'KHR_materials_transmission', 'KHR_materials_ior', 'KHR_materials_specular', 'KHR_materials_sheen', 'KHR_materials_volume'],
- unsupported: ['more than four skin influences', 'singular weighted skin transforms', 'reflected skin transforms', 'TANGENT morph targets', 'morph targets without authored base normals', 'vertex alpha below one', 'alpha blending or masking', 'double-sided materials', 'different texture transforms on one material', 'skinned or morphed GPU instancing', 'rendering of ignored material extensions'],
++ unsupported: ['more than four skin influences', 'singular weighted skin transforms', 'reflected skin transforms', 'TANGENT morph targets', 'morph targets without authored base normals', 'vertex alpha below one', 'different texture transforms on one material', 'skinned or morphed GPU instancing', 'rendering of ignored material extensions'],
});
const DEFAULT_MAX_BYTES = 32 * 1024 * 1024;
const DEFAULT_MAX_VERTICES = 2_000_000;
- const ALLOWED_EXTENSIONS = new Set(['KHR_mesh_quantization', 'KHR_materials_emissive_strength']);
+const GLTF_ALPHA_MODES = { OPAQUE: 'opaque', MASK: 'mask', BLEND: 'blend' };
+ const DEFAULT_MAX_INSTANCES = 4096;
+ const ALLOWED_EXTENSIONS = new Set(['KHR_mesh_quantization', 'KHR_materials_emissive_strength', 'KHR_texture_transform', 'EXT_mesh_gpu_instancing']);
+ const DECODER_BY_EXTENSION = { KHR_draco_mesh_compression: 'draco', EXT_meshopt_compression: 'meshopt', KHR_texture_basisu: 'ktx2' };
+ // Accepted when optional, because 67.js does not render them. Rejected when listed in extensionsRequired.
+ const IGNORED_EXTENSIONS = new Set(GLTF_CAPABILITIES.ignoredExtensions);
+ const IDENTITY_UV_TRANSFORM = Object.freeze({ offset: [0, 0], rotation: 0, scale: [1, 1] });
const WRAPPING = { 1000: 10497, 1001: 33071, 1002: 33648 };
const FILTERING = { 1003: 9728, 1004: 9984, 1005: 9986, 1006: 9729, 1007: 9985, 1008: 9987 };
const MATERIAL_TEXTURES = [
@@@ -670,10 -819,9 +822,13 @@@ function convertMaterial(source, limits
normalScale: [definition.normalTexture?.scale ?? 1, definition.normalTexture?.scale ?? 1],
occlusionStrength: source.aoMapIntensity,
};
+ material.alphaMode = GLTF_ALPHA_MODES[definition.alphaMode ?? 'OPAQUE'];
+ material.alphaCutoff = definition.alphaCutoff ?? 0.5;
+ material.opacity = definition.pbrMetallicRoughness?.baseColorFactor?.[3] ?? 1;
+ material.doubleSided = definition.doubleSided ?? false;
+ // Hint only: transmission is not rendered yet.
+ const transmission = definition.extensions?.KHR_materials_transmission?.transmissionFactor ?? 0;
+ if (transmission > 0) material.transmission = transmission;
if (!material.emissiveColor.some(value => value > 0)) material.emission = 0;
if (!Number.isFinite(Math.fround(material.emission)) || material.emission < 0) throw new Error('Emissive intensity must be a finite nonnegative float.');
for (const [field, , colorSpace] of MATERIAL_TEXTURES) {
diff --cc tests/gltf.test.js
index 4a32b2e0,b31b7374..e23b1e3d
--- a/tests/gltf.test.js
+++ b/tests/gltf.test.js
@@@ -172,12 -148,11 +172,12 @@@ test('unsupported features fail explici
}, /Unsupported morph/],
[document => { document.meshes[0].primitives[0].attributes.COLOR_0 = 1; }, /COLOR_0/],
[document => { document.meshes[0].primitives[0].mode = 1; }, /TRIANGLES/],
- [document => { document.materials[0].alphaMode = 'BLEND'; }, /alpha mode/],
- [document => { document.materials[0].doubleSided = true; }, /Double-sided/],
+ [document => { document.materials[0].alphaMode = 'DITHER'; }, /alpha mode/],
+ [document => { document.materials[0].alphaCutoff = 2; }, /alphaCutoff/],
+ [document => { document.materials[0].doubleSided = 'yes'; }, /doubleSided/],
[document => { document.materials[0].normalTexture = { index: 0 }; }, /normalTexture texture index/],
[document => { document.extensionsRequired = ['KHR_draco_mesh_compression']; }, /KHR_draco/],
- [document => { document.materials[0].extensions = { KHR_materials_clearcoat: {} }; }, /KHR_materials_clearcoat/],
+ [document => { document.materials[0].extensions = { KHR_materials_unknown_vendor: {} }; }, /KHR_materials_unknown_vendor/],
[document => { document.buffers[0].uri = 'external.bin'; }, /baseUrl/],
[document => { document.nodes[2].children = [0]; }, /Cyclic/],
[document => { document.materials[0].pbrMetallicRoughness.metallicFactor = 2; }, /metallic/],