Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
102 changes: 79 additions & 23 deletions examples/jsm/exporters/USDZExporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -567,35 +567,49 @@ function buildNode( object, parentNode, materials, usedNames, files, options ) {
if ( object.isMesh ) {

const geometry = object.geometry;
const material = object.material;
const isMultiMaterial = Array.isArray( object.material );

if ( ! material.isMeshStandardMaterial ) {
const meshMaterials = isMultiMaterial ? object.material : [ object.material ];

console.warn( 'THREE.USDZExporter: Use MeshStandardMaterial for best results.' );
for ( let i = 0; i < meshMaterials.length; i ++ ) {

}
const material = meshMaterials[ i ];

const geometryFileName = 'geometries/Geometry_' + geometry.id + '.usda';
if ( ! material.isMeshStandardMaterial ) {

if ( ! ( geometryFileName in files ) ) {
console.warn( 'THREE.USDZExporter: Use MeshStandardMaterial for best results.' );

const meshObject = buildMeshObject( geometry );
files[ geometryFileName ] = strToU8(
buildHeader() + '\n' + meshObject.toString()
);
}

if ( ! ( material.uuid in materials ) ) {

materials[ material.uuid ] = material;

}

}

if ( ! ( material.uuid in materials ) ) {
const resolvedMaterials = meshMaterials.map( ( m ) => materials[ m.uuid ] );

if ( isMultiMaterial === false ) {

const geometryFileName = `geometries/Geometry_${geometry.id}.usda`;

if ( ! ( geometryFileName in files ) ) {

materials[ material.uuid ] = material;
const meshObject = buildMeshObject( geometry );
files[ geometryFileName ] = strToU8(
buildHeader() + '\n' + meshObject.toString()
);

}

}

childNode = buildMesh(
object,
geometry,
materials[ material.uuid ],
resolvedMaterials,
usedNames,
options
);
Expand Down Expand Up @@ -706,19 +720,26 @@ function buildXform( object, usedNames, options ) {

}

function buildMesh( object, geometry, material, usedNames, options ) {
function buildMesh( object, geometry, materials, usedNames, options ) {

const node = buildXform( object, usedNames, options );

node.addMetadata(
'prepend references',
`@./geometries/Geometry_${geometry.id}.usda@</Geometry>`
);
node.addMetadata( 'prepend apiSchemas', '["MaterialBindingAPI"]' );
if ( materials.length === 1 ) {

node.addProperty(
`rel material:binding = </Materials/Material_${material.id}>`
);
node.addMetadata(
'prepend references',
`@./geometries/Geometry_${geometry.id}.usda@</Geometry>`
);
node.addMetadata( 'prepend apiSchemas', '["MaterialBindingAPI"]' );
node.addProperty(
`rel material:binding = </Materials/Material_${materials[ 0 ].id}>`
);

} else {

node.addChild( buildMeshNode( geometry, materials ) );

}

return node;

Expand Down Expand Up @@ -756,7 +777,7 @@ function buildMeshObject( geometry ) {

}

function buildMeshNode( geometry ) {
function buildMeshNode( geometry, materials = null ) {

const name = 'Geometry';
const attributes = geometry.attributes;
Expand Down Expand Up @@ -808,6 +829,41 @@ function buildMeshNode( geometry ) {

node.addProperty( 'uniform token subdivisionScheme = "none"' );

if ( materials !== null ) {

const groups = geometry.groups;

const totalFaces = ( geometry.index !== null
? geometry.index.count
: attributes.position.count ) / 3;

for ( let i = 0; i < groups.length; i ++ ) {

const group = groups[ i ];
const material = materials[ group.materialIndex ];

if ( material === undefined ) continue;

const startFace = Math.floor( group.start / 3 );
const endFace = Math.min( startFace + Math.floor( group.count / 3 ), totalFaces );

const indices = [];
for ( let j = startFace; j < endFace; j ++ ) indices.push( j );

const subsetNode = new USDNode( `subset_${i}`, 'GeomSubset' );
subsetNode.addMetadata( 'prepend apiSchemas', '["MaterialBindingAPI"]' );
subsetNode.addProperty( 'uniform token elementType = "face"' );
subsetNode.addProperty( 'uniform token familyName = "materialBind"' );
subsetNode.addProperty( `int[] indices = [${indices.join( ', ' )}]` );
subsetNode.addProperty(
`rel material:binding = </Materials/Material_${material.id}>`
);
node.addChild( subsetNode );

}

}

return node;

}
Expand Down
15 changes: 2 additions & 13 deletions manual/en/installation.html
Original file line number Diff line number Diff line change
Expand Up @@ -109,21 +109,10 @@ <h3>Development</h3>
</p>
</details>
<details>
<summary>Improve your editor auto-completion with <i>jsconfig</i> or <i>tsconfig</i></summary>
<summary>Using three.js with TypeScript</summary>
<p>
Place a <i>jsconfig.json</i> (or <i>tsconfig.json</i> for TypeScript projects) in your project's root. Adding the configuration below helps your editor locate three.js files for enhanced auto-completion.
Community-maintained TypeScript type definitions for three.js are available at [link:https://github.com/three-types/three-ts-types three-types/three-ts-types].
</p>
<pre class="prettyprint notranslate lang-js" translate="no">
{
"compilerOptions": {
// other options...
"paths": {
"three/webgpu": ["node_modules/three/build/three.webgpu.js"],
"three/tsl": ["node_modules/three/build/three.tsl.js"],
},
}
}
</pre>
</details>
</aside>
</li>
Expand Down
15 changes: 2 additions & 13 deletions manual/fr/installation.html
Original file line number Diff line number Diff line change
Expand Up @@ -109,21 +109,10 @@ <h3>Développement</h3>
</p>
</details>
<details>
<summary>Améliorez l'auto-complétion de votre éditeur avec <i>jsconfig</i> ou <i>tsconfig</i></summary>
<summary>Using three.js with TypeScript</summary>
<p>
Placez un fichier <i>jsconfig.json</i> (ou <i>tsconfig.json</i> pour les projets TypeScript) à la racine de votre projet. L'ajout de la configuration ci-dessous aide votre éditeur à localiser les fichiers three.js pour une auto-complétion améliorée.
Community-maintained TypeScript type definitions for three.js are available at [link:https://github.com/three-types/three-ts-types three-types/three-ts-types].
</p>
<pre class="prettyprint notranslate lang-js" translate="no">
{
"compilerOptions": {
// other options...
"paths": {
"three/webgpu": ["node_modules/three/build/three.webgpu.js"],
"three/tsl": ["node_modules/three/build/three.tsl.js"],
},
}
}
</pre>
</details>
</aside>
</li>
Expand Down
15 changes: 2 additions & 13 deletions manual/zh/installation.html
Original file line number Diff line number Diff line change
Expand Up @@ -109,21 +109,10 @@ <h3>开发</h3>
</p>
</details>
<details>
<summary>使用 <i>jsconfig</i> 或 <i>tsconfig</i> 改善编辑器自动补全</summary>
<summary>Using three.js with TypeScript</summary>
<p>
在项目根目录放置一个 <i>jsconfig.json</i>(TypeScript 项目则使用 <i>tsconfig.json</i>)。添加以下配置可以帮助编辑器定位 three.js 文件,从而增强自动补全功能。
Community-maintained TypeScript type definitions for three.js are available at [link:https://github.com/three-types/three-ts-types three-types/three-ts-types].
</p>
<pre class="prettyprint notranslate lang-js" translate="no">
{
"compilerOptions": {
// other options...
"paths": {
"three/webgpu": ["node_modules/three/build/three.webgpu.js"],
"three/tsl": ["node_modules/three/build/three.tsl.js"],
},
}
}
</pre>
</details>
</aside>
</li>
Expand Down