Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GLTFExporter: Added forceIndices for non-indexed geometry #13410

Merged
merged 3 commits into from
Feb 23, 2018
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 4 additions & 3 deletions editor/js/Menubar.File.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,9 +197,10 @@ Menubar.File = function ( editor ) {

saveArrayBuffer( result, 'scene.glb' );

}, { binary: true } );


// forceIndices: true to allow compatibility with facebook
// https://github.com/mrdoob/three.js/issues/13397
}, { binary: true, forceIndices: true } );

} );
options.add( option );

Expand Down
15 changes: 14 additions & 1 deletion examples/js/exporters/GLTFExporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ THREE.GLTFExporter.prototype = {
onlyVisible: true,
truncateDrawRange: true,
embedImages: true,
animations: []
animations: [],
forceIndices: false
};

options = Object.assign( {}, DEFAULT_OPTIONS, options );
Expand Down Expand Up @@ -809,6 +810,18 @@ THREE.GLTFExporter.prototype = {

gltfMesh.primitives[ 0 ].indices = processAccessor( geometry.index, geometry );

} else if ( options.forceIndices ) {

var numFaces = geometry.attributes.position.count;
var indices = new Uint32Array( numFaces );
for ( var i = 0; i < numFaces; i ++ ) {

indices[ i ] = i;

}

gltfMesh.primitives[ 0 ].indices = processAccessor( new THREE.Uint32BufferAttribute( indices, 1 ), geometry );

}

// We've just one primitive per mesh
Expand Down
4 changes: 3 additions & 1 deletion examples/misc_exporter_gltf.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
<label><input id="option_visible" name="visible" type="checkbox" checked="checked"/>Only Visible</label>
<label><input id="option_drawrange" name="visible" type="checkbox" checked="checked"/>Truncate drawRange</label>
<label><input id="option_binary" name="visible" type="checkbox">Binary (<code>.glb</code>)</label>
<label><input id="option_forceindices" name="visible" type="checkbox">Force indices</label>
</div>

<script src="../build/three.js"></script>
Expand All @@ -50,7 +51,8 @@
trs: document.getElementById('option_trs').checked,
onlyVisible: document.getElementById('option_visible').checked,
truncateDrawRange: document.getElementById('option_drawrange').checked,
binary: document.getElementById('option_binary').checked
binary: document.getElementById('option_binary').checked,
forceIndices: document.getElementById('option_forceindices').checked
};
gltfExporter.parse( input, function( result ) {

Expand Down