mirror of
https://github.com/DanielnetoDotCom/YouPHPTube
synced 2025-10-06 03:50:04 +02:00
This commit is contained in:
parent
f0f62670c5
commit
7e26256cac
4563 changed files with 1246712 additions and 17558 deletions
663
node_modules/three/examples/js/exporters/ColladaExporter.js
generated
vendored
Normal file
663
node_modules/three/examples/js/exporters/ColladaExporter.js
generated
vendored
Normal file
|
@ -0,0 +1,663 @@
|
|||
/**
|
||||
* https://github.com/gkjohnson/collada-exporter-js
|
||||
*
|
||||
* Usage:
|
||||
* var exporter = new THREE.ColladaExporter();
|
||||
*
|
||||
* var data = exporter.parse(mesh);
|
||||
*
|
||||
* Format Definition:
|
||||
* https://www.khronos.org/collada/
|
||||
*/
|
||||
|
||||
THREE.ColladaExporter = function () {};
|
||||
|
||||
THREE.ColladaExporter.prototype = {
|
||||
|
||||
constructor: THREE.ColladaExporter,
|
||||
|
||||
parse: function ( object, onDone, options ) {
|
||||
|
||||
options = options || {};
|
||||
|
||||
options = Object.assign( {
|
||||
version: '1.4.1',
|
||||
author: null,
|
||||
textureDirectory: '',
|
||||
}, options );
|
||||
|
||||
if ( options.textureDirectory !== '' ) {
|
||||
|
||||
options.textureDirectory = `${ options.textureDirectory }/`
|
||||
.replace( /\\/g, '/' )
|
||||
.replace( /\/+/g, '/' );
|
||||
|
||||
}
|
||||
|
||||
var version = options.version;
|
||||
if ( version !== '1.4.1' && version !== '1.5.0' ) {
|
||||
|
||||
console.warn( `ColladaExporter : Version ${ version } not supported for export. Only 1.4.1 and 1.5.0.` );
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
// Convert the urdf xml into a well-formatted, indented format
|
||||
function format( urdf ) {
|
||||
|
||||
var IS_END_TAG = /^<\//;
|
||||
var IS_SELF_CLOSING = /(\?>$)|(\/>$)/;
|
||||
var HAS_TEXT = /<[^>]+>[^<]*<\/[^<]+>/;
|
||||
|
||||
var pad = ( ch, num ) => ( num > 0 ? ch + pad( ch, num - 1 ) : '' );
|
||||
|
||||
var tagnum = 0;
|
||||
return urdf
|
||||
.match( /(<[^>]+>[^<]+<\/[^<]+>)|(<[^>]+>)/g )
|
||||
.map( tag => {
|
||||
|
||||
if ( ! HAS_TEXT.test( tag ) && ! IS_SELF_CLOSING.test( tag ) && IS_END_TAG.test( tag ) ) {
|
||||
|
||||
tagnum --;
|
||||
|
||||
}
|
||||
|
||||
var res = `${ pad( ' ', tagnum ) }${ tag }`;
|
||||
|
||||
if ( ! HAS_TEXT.test( tag ) && ! IS_SELF_CLOSING.test( tag ) && ! IS_END_TAG.test( tag ) ) {
|
||||
|
||||
tagnum ++;
|
||||
|
||||
}
|
||||
|
||||
return res;
|
||||
|
||||
} )
|
||||
.join( '\n' );
|
||||
|
||||
}
|
||||
|
||||
// Convert an image into a png format for saving
|
||||
function base64ToBuffer( str ) {
|
||||
|
||||
var b = atob( str );
|
||||
var buf = new Uint8Array( b.length );
|
||||
|
||||
for ( var i = 0, l = buf.length; i < l; i ++ ) {
|
||||
|
||||
buf[ i ] = b.charCodeAt( i );
|
||||
|
||||
}
|
||||
|
||||
return buf;
|
||||
|
||||
}
|
||||
|
||||
var canvas, ctx;
|
||||
function imageToData( image, ext ) {
|
||||
|
||||
canvas = canvas || document.createElement( 'canvas' );
|
||||
ctx = ctx || canvas.getContext( '2d' );
|
||||
|
||||
canvas.width = image.width;
|
||||
canvas.height = image.height;
|
||||
|
||||
ctx.drawImage( image, 0, 0 );
|
||||
|
||||
// Get the base64 encoded data
|
||||
var base64data = canvas
|
||||
.toDataURL( `image/${ ext }`, 1 )
|
||||
.replace( /^data:image\/(png|jpg);base64,/, '' );
|
||||
|
||||
// Convert to a uint8 array
|
||||
return base64ToBuffer( base64data );
|
||||
|
||||
}
|
||||
|
||||
// gets the attribute array. Generate a new array if the attribute is interleaved
|
||||
var getFuncs = [ 'getX', 'getY', 'getZ', 'getW' ];
|
||||
function attrBufferToArray( attr ) {
|
||||
|
||||
if ( attr.isInterleavedBufferAttribute ) {
|
||||
|
||||
// use the typed array constructor to save on memory
|
||||
var arr = new attr.array.constructor( attr.count * attr.itemSize );
|
||||
var size = attr.itemSize;
|
||||
for ( var i = 0, l = attr.count; i < l; i ++ ) {
|
||||
|
||||
for ( var j = 0; j < size; j ++ ) {
|
||||
|
||||
arr[ i * size + j ] = attr[ getFuncs[ j ] ]( i );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return arr;
|
||||
|
||||
} else {
|
||||
|
||||
return attr.array;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Returns an array of the same type starting at the `st` index,
|
||||
// and `ct` length
|
||||
function subArray( arr, st, ct ) {
|
||||
|
||||
if ( Array.isArray( arr ) ) return arr.slice( st, st + ct );
|
||||
else return new arr.constructor( arr.buffer, st * arr.BYTES_PER_ELEMENT, ct );
|
||||
|
||||
}
|
||||
|
||||
// Returns the string for a geometry's attribute
|
||||
function getAttribute( attr, name, params, type ) {
|
||||
|
||||
var array = attrBufferToArray( attr );
|
||||
var res =
|
||||
`<source id="${ name }">` +
|
||||
|
||||
`<float_array id="${ name }-array" count="${ array.length }">` +
|
||||
array.join( ' ' ) +
|
||||
'</float_array>' +
|
||||
|
||||
'<technique_common>' +
|
||||
`<accessor source="#${ name }-array" count="${ Math.floor( array.length / attr.itemSize ) }" stride="${ attr.itemSize }">` +
|
||||
|
||||
params.map( n => `<param name="${ n }" type="${ type }" />` ).join( '' ) +
|
||||
|
||||
'</accessor>' +
|
||||
'</technique_common>' +
|
||||
'</source>';
|
||||
|
||||
return res;
|
||||
|
||||
}
|
||||
|
||||
// Returns the string for a node's transform information
|
||||
var transMat;
|
||||
function getTransform( o ) {
|
||||
|
||||
// ensure the object's matrix is up to date
|
||||
// before saving the transform
|
||||
o.updateMatrix();
|
||||
|
||||
transMat = transMat || new THREE.Matrix4();
|
||||
transMat.copy( o.matrix );
|
||||
transMat.transpose();
|
||||
return `<matrix>${ transMat.toArray().join( ' ' ) }</matrix>`;
|
||||
|
||||
}
|
||||
|
||||
// Process the given piece of geometry into the geometry library
|
||||
// Returns the mesh id
|
||||
function processGeometry( g ) {
|
||||
|
||||
var info = geometryInfo.get( g );
|
||||
|
||||
if ( ! info ) {
|
||||
|
||||
// convert the geometry to bufferGeometry if it isn't already
|
||||
var bufferGeometry = g;
|
||||
|
||||
if ( bufferGeometry.isBufferGeometry !== true ) {
|
||||
|
||||
throw new Error( 'THREE.ColladaExporter: Geometry is not of type THREE.BufferGeometry.' );
|
||||
|
||||
}
|
||||
|
||||
var meshid = `Mesh${ libraryGeometries.length + 1 }`;
|
||||
|
||||
var indexCount =
|
||||
bufferGeometry.index ?
|
||||
bufferGeometry.index.count * bufferGeometry.index.itemSize :
|
||||
bufferGeometry.attributes.position.count;
|
||||
|
||||
var groups =
|
||||
bufferGeometry.groups != null && bufferGeometry.groups.length !== 0 ?
|
||||
bufferGeometry.groups :
|
||||
[ { start: 0, count: indexCount, materialIndex: 0 } ];
|
||||
|
||||
|
||||
var gname = g.name ? ` name="${ g.name }"` : '';
|
||||
var gnode = `<geometry id="${ meshid }"${ gname }><mesh>`;
|
||||
|
||||
// define the geometry node and the vertices for the geometry
|
||||
var posName = `${ meshid }-position`;
|
||||
var vertName = `${ meshid }-vertices`;
|
||||
gnode += getAttribute( bufferGeometry.attributes.position, posName, [ 'X', 'Y', 'Z' ], 'float' );
|
||||
gnode += `<vertices id="${ vertName }"><input semantic="POSITION" source="#${ posName }" /></vertices>`;
|
||||
|
||||
// NOTE: We're not optimizing the attribute arrays here, so they're all the same length and
|
||||
// can therefore share the same triangle indices. However, MeshLab seems to have trouble opening
|
||||
// models with attributes that share an offset.
|
||||
// MeshLab Bug#424: https://sourceforge.net/p/meshlab/bugs/424/
|
||||
|
||||
// serialize normals
|
||||
var triangleInputs = `<input semantic="VERTEX" source="#${ vertName }" offset="0" />`;
|
||||
if ( 'normal' in bufferGeometry.attributes ) {
|
||||
|
||||
var normName = `${ meshid }-normal`;
|
||||
gnode += getAttribute( bufferGeometry.attributes.normal, normName, [ 'X', 'Y', 'Z' ], 'float' );
|
||||
triangleInputs += `<input semantic="NORMAL" source="#${ normName }" offset="0" />`;
|
||||
|
||||
}
|
||||
|
||||
// serialize uvs
|
||||
if ( 'uv' in bufferGeometry.attributes ) {
|
||||
|
||||
var uvName = `${ meshid }-texcoord`;
|
||||
gnode += getAttribute( bufferGeometry.attributes.uv, uvName, [ 'S', 'T' ], 'float' );
|
||||
triangleInputs += `<input semantic="TEXCOORD" source="#${ uvName }" offset="0" set="0" />`;
|
||||
|
||||
}
|
||||
|
||||
// serialize lightmap uvs
|
||||
if ( 'uv2' in bufferGeometry.attributes ) {
|
||||
|
||||
var uvName = `${ meshid }-texcoord2`;
|
||||
gnode += getAttribute( bufferGeometry.attributes.uv2, uvName, [ 'S', 'T' ], 'float' );
|
||||
triangleInputs += `<input semantic="TEXCOORD" source="#${ uvName }" offset="0" set="1" />`;
|
||||
|
||||
}
|
||||
|
||||
// serialize colors
|
||||
if ( 'color' in bufferGeometry.attributes ) {
|
||||
|
||||
var colName = `${ meshid }-color`;
|
||||
gnode += getAttribute( bufferGeometry.attributes.color, colName, [ 'X', 'Y', 'Z' ], 'uint8' );
|
||||
triangleInputs += `<input semantic="COLOR" source="#${ colName }" offset="0" />`;
|
||||
|
||||
}
|
||||
|
||||
var indexArray = null;
|
||||
if ( bufferGeometry.index ) {
|
||||
|
||||
indexArray = attrBufferToArray( bufferGeometry.index );
|
||||
|
||||
} else {
|
||||
|
||||
indexArray = new Array( indexCount );
|
||||
for ( var i = 0, l = indexArray.length; i < l; i ++ ) indexArray[ i ] = i;
|
||||
|
||||
}
|
||||
|
||||
for ( var i = 0, l = groups.length; i < l; i ++ ) {
|
||||
|
||||
var group = groups[ i ];
|
||||
var subarr = subArray( indexArray, group.start, group.count );
|
||||
var polycount = subarr.length / 3;
|
||||
gnode += `<triangles material="MESH_MATERIAL_${ group.materialIndex }" count="${ polycount }">`;
|
||||
gnode += triangleInputs;
|
||||
|
||||
gnode += `<p>${ subarr.join( ' ' ) }</p>`;
|
||||
gnode += '</triangles>';
|
||||
|
||||
}
|
||||
|
||||
gnode += '</mesh></geometry>';
|
||||
|
||||
libraryGeometries.push( gnode );
|
||||
|
||||
info = { meshid: meshid, bufferGeometry: bufferGeometry };
|
||||
geometryInfo.set( g, info );
|
||||
|
||||
}
|
||||
|
||||
return info;
|
||||
|
||||
}
|
||||
|
||||
// Process the given texture into the image library
|
||||
// Returns the image library
|
||||
function processTexture( tex ) {
|
||||
|
||||
var texid = imageMap.get( tex );
|
||||
if ( texid == null ) {
|
||||
|
||||
texid = `image-${ libraryImages.length + 1 }`;
|
||||
|
||||
var ext = 'png';
|
||||
var name = tex.name || texid;
|
||||
var imageNode = `<image id="${ texid }" name="${ name }">`;
|
||||
|
||||
if ( version === '1.5.0' ) {
|
||||
|
||||
imageNode += `<init_from><ref>${ options.textureDirectory }${ name }.${ ext }</ref></init_from>`;
|
||||
|
||||
} else {
|
||||
|
||||
// version image node 1.4.1
|
||||
imageNode += `<init_from>${ options.textureDirectory }${ name }.${ ext }</init_from>`;
|
||||
|
||||
}
|
||||
|
||||
imageNode += '</image>';
|
||||
|
||||
libraryImages.push( imageNode );
|
||||
imageMap.set( tex, texid );
|
||||
textures.push( {
|
||||
directory: options.textureDirectory,
|
||||
name,
|
||||
ext,
|
||||
data: imageToData( tex.image, ext ),
|
||||
original: tex
|
||||
} );
|
||||
|
||||
}
|
||||
|
||||
return texid;
|
||||
|
||||
}
|
||||
|
||||
// Process the given material into the material and effect libraries
|
||||
// Returns the material id
|
||||
function processMaterial( m ) {
|
||||
|
||||
var matid = materialMap.get( m );
|
||||
|
||||
if ( matid == null ) {
|
||||
|
||||
matid = `Mat${ libraryEffects.length + 1 }`;
|
||||
|
||||
var type = 'phong';
|
||||
|
||||
if ( m.isMeshLambertMaterial === true ) {
|
||||
|
||||
type = 'lambert';
|
||||
|
||||
} else if ( m.isMeshBasicMaterial === true ) {
|
||||
|
||||
type = 'constant';
|
||||
|
||||
if ( m.map !== null ) {
|
||||
|
||||
// The Collada spec does not support diffuse texture maps with the
|
||||
// constant shader type.
|
||||
// mrdoob/three.js#15469
|
||||
console.warn( 'ColladaExporter: Texture maps not supported with MeshBasicMaterial.' );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
var emissive = m.emissive ? m.emissive : new THREE.Color( 0, 0, 0 );
|
||||
var diffuse = m.color ? m.color : new THREE.Color( 0, 0, 0 );
|
||||
var specular = m.specular ? m.specular : new THREE.Color( 1, 1, 1 );
|
||||
var shininess = m.shininess || 0;
|
||||
var reflectivity = m.reflectivity || 0;
|
||||
|
||||
// Do not export and alpha map for the reasons mentioned in issue (#13792)
|
||||
// in three.js alpha maps are black and white, but collada expects the alpha
|
||||
// channel to specify the transparency
|
||||
var transparencyNode = '';
|
||||
if ( m.transparent === true ) {
|
||||
|
||||
transparencyNode +=
|
||||
'<transparent>' +
|
||||
(
|
||||
m.map ?
|
||||
'<texture texture="diffuse-sampler"></texture>' :
|
||||
'<float>1</float>'
|
||||
) +
|
||||
'</transparent>';
|
||||
|
||||
if ( m.opacity < 1 ) {
|
||||
|
||||
transparencyNode += `<transparency><float>${ m.opacity }</float></transparency>`;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
var techniqueNode = `<technique sid="common"><${ type }>` +
|
||||
|
||||
'<emission>' +
|
||||
|
||||
(
|
||||
m.emissiveMap ?
|
||||
'<texture texture="emissive-sampler" texcoord="TEXCOORD" />' :
|
||||
`<color sid="emission">${ emissive.r } ${ emissive.g } ${ emissive.b } 1</color>`
|
||||
) +
|
||||
|
||||
'</emission>' +
|
||||
|
||||
(
|
||||
type !== 'constant' ?
|
||||
'<diffuse>' +
|
||||
|
||||
(
|
||||
m.map ?
|
||||
'<texture texture="diffuse-sampler" texcoord="TEXCOORD" />' :
|
||||
`<color sid="diffuse">${ diffuse.r } ${ diffuse.g } ${ diffuse.b } 1</color>`
|
||||
) +
|
||||
'</diffuse>'
|
||||
: ''
|
||||
) +
|
||||
|
||||
(
|
||||
type !== 'constant' ?
|
||||
'<bump>' +
|
||||
|
||||
(
|
||||
m.normalMap ? '<texture texture="bump-sampler" texcoord="TEXCOORD" />' : ''
|
||||
) +
|
||||
'</bump>'
|
||||
: ''
|
||||
) +
|
||||
|
||||
(
|
||||
type === 'phong' ?
|
||||
`<specular><color sid="specular">${ specular.r } ${ specular.g } ${ specular.b } 1</color></specular>` +
|
||||
|
||||
'<shininess>' +
|
||||
|
||||
(
|
||||
m.specularMap ?
|
||||
'<texture texture="specular-sampler" texcoord="TEXCOORD" />' :
|
||||
`<float sid="shininess">${ shininess }</float>`
|
||||
) +
|
||||
|
||||
'</shininess>'
|
||||
: ''
|
||||
) +
|
||||
|
||||
`<reflective><color>${ diffuse.r } ${ diffuse.g } ${ diffuse.b } 1</color></reflective>` +
|
||||
|
||||
`<reflectivity><float>${ reflectivity }</float></reflectivity>` +
|
||||
|
||||
transparencyNode +
|
||||
|
||||
`</${ type }></technique>`;
|
||||
|
||||
var effectnode =
|
||||
`<effect id="${ matid }-effect">` +
|
||||
'<profile_COMMON>' +
|
||||
|
||||
(
|
||||
m.map ?
|
||||
'<newparam sid="diffuse-surface"><surface type="2D">' +
|
||||
`<init_from>${ processTexture( m.map ) }</init_from>` +
|
||||
'</surface></newparam>' +
|
||||
'<newparam sid="diffuse-sampler"><sampler2D><source>diffuse-surface</source></sampler2D></newparam>' :
|
||||
''
|
||||
) +
|
||||
|
||||
(
|
||||
m.specularMap ?
|
||||
'<newparam sid="specular-surface"><surface type="2D">' +
|
||||
`<init_from>${ processTexture( m.specularMap ) }</init_from>` +
|
||||
'</surface></newparam>' +
|
||||
'<newparam sid="specular-sampler"><sampler2D><source>specular-surface</source></sampler2D></newparam>' :
|
||||
''
|
||||
) +
|
||||
|
||||
(
|
||||
m.emissiveMap ?
|
||||
'<newparam sid="emissive-surface"><surface type="2D">' +
|
||||
`<init_from>${ processTexture( m.emissiveMap ) }</init_from>` +
|
||||
'</surface></newparam>' +
|
||||
'<newparam sid="emissive-sampler"><sampler2D><source>emissive-surface</source></sampler2D></newparam>' :
|
||||
''
|
||||
) +
|
||||
|
||||
(
|
||||
m.normalMap ?
|
||||
'<newparam sid="bump-surface"><surface type="2D">' +
|
||||
`<init_from>${ processTexture( m.normalMap ) }</init_from>` +
|
||||
'</surface></newparam>' +
|
||||
'<newparam sid="bump-sampler"><sampler2D><source>bump-surface</source></sampler2D></newparam>' :
|
||||
''
|
||||
) +
|
||||
|
||||
techniqueNode +
|
||||
|
||||
(
|
||||
m.side === THREE.DoubleSide ?
|
||||
'<extra><technique profile="THREEJS"><double_sided sid="double_sided" type="int">1</double_sided></technique></extra>' :
|
||||
''
|
||||
) +
|
||||
|
||||
'</profile_COMMON>' +
|
||||
|
||||
'</effect>';
|
||||
|
||||
var materialName = m.name ? ` name="${ m.name }"` : '';
|
||||
var materialNode = `<material id="${ matid }"${ materialName }><instance_effect url="#${ matid }-effect" /></material>`;
|
||||
|
||||
libraryMaterials.push( materialNode );
|
||||
libraryEffects.push( effectnode );
|
||||
materialMap.set( m, matid );
|
||||
|
||||
}
|
||||
|
||||
return matid;
|
||||
|
||||
}
|
||||
|
||||
// Recursively process the object into a scene
|
||||
function processObject( o ) {
|
||||
|
||||
var node = `<node name="${ o.name }">`;
|
||||
|
||||
node += getTransform( o );
|
||||
|
||||
if ( o.isMesh === true && o.geometry !== null ) {
|
||||
|
||||
// function returns the id associated with the mesh and a "BufferGeometry" version
|
||||
// of the geometry in case it's not a geometry.
|
||||
var geomInfo = processGeometry( o.geometry );
|
||||
var meshid = geomInfo.meshid;
|
||||
var geometry = geomInfo.bufferGeometry;
|
||||
|
||||
// ids of the materials to bind to the geometry
|
||||
var matids = null;
|
||||
var matidsArray = [];
|
||||
|
||||
// get a list of materials to bind to the sub groups of the geometry.
|
||||
// If the amount of subgroups is greater than the materials, than reuse
|
||||
// the materials.
|
||||
var mat = o.material || new THREE.MeshBasicMaterial();
|
||||
var materials = Array.isArray( mat ) ? mat : [ mat ];
|
||||
|
||||
if ( geometry.groups.length > materials.length ) {
|
||||
|
||||
matidsArray = new Array( geometry.groups.length );
|
||||
|
||||
} else {
|
||||
|
||||
matidsArray = new Array( materials.length );
|
||||
|
||||
}
|
||||
|
||||
matids = matidsArray.fill().map( ( v, i ) => processMaterial( materials[ i % materials.length ] ) );
|
||||
|
||||
node +=
|
||||
`<instance_geometry url="#${ meshid }">` +
|
||||
|
||||
(
|
||||
matids != null ?
|
||||
'<bind_material><technique_common>' +
|
||||
matids.map( ( id, i ) =>
|
||||
|
||||
`<instance_material symbol="MESH_MATERIAL_${ i }" target="#${ id }" >` +
|
||||
|
||||
'<bind_vertex_input semantic="TEXCOORD" input_semantic="TEXCOORD" input_set="0" />' +
|
||||
|
||||
'</instance_material>'
|
||||
).join( '' ) +
|
||||
'</technique_common></bind_material>' :
|
||||
''
|
||||
) +
|
||||
|
||||
'</instance_geometry>';
|
||||
|
||||
}
|
||||
|
||||
o.children.forEach( c => node += processObject( c ) );
|
||||
|
||||
node += '</node>';
|
||||
|
||||
return node;
|
||||
|
||||
}
|
||||
|
||||
var geometryInfo = new WeakMap();
|
||||
var materialMap = new WeakMap();
|
||||
var imageMap = new WeakMap();
|
||||
var textures = [];
|
||||
|
||||
var libraryImages = [];
|
||||
var libraryGeometries = [];
|
||||
var libraryEffects = [];
|
||||
var libraryMaterials = [];
|
||||
var libraryVisualScenes = processObject( object );
|
||||
|
||||
var specLink = version === '1.4.1' ? 'http://www.collada.org/2005/11/COLLADASchema' : 'https://www.khronos.org/collada/';
|
||||
var dae =
|
||||
'<?xml version="1.0" encoding="UTF-8" standalone="no" ?>' +
|
||||
`<COLLADA xmlns="${ specLink }" version="${ version }">` +
|
||||
'<asset>' +
|
||||
(
|
||||
'<contributor>' +
|
||||
'<authoring_tool>three.js Collada Exporter</authoring_tool>' +
|
||||
( options.author !== null ? `<author>${ options.author }</author>` : '' ) +
|
||||
'</contributor>' +
|
||||
`<created>${ ( new Date() ).toISOString() }</created>` +
|
||||
`<modified>${ ( new Date() ).toISOString() }</modified>` +
|
||||
'<up_axis>Y_UP</up_axis>'
|
||||
) +
|
||||
'</asset>';
|
||||
|
||||
dae += `<library_images>${ libraryImages.join( '' ) }</library_images>`;
|
||||
|
||||
dae += `<library_effects>${ libraryEffects.join( '' ) }</library_effects>`;
|
||||
|
||||
dae += `<library_materials>${ libraryMaterials.join( '' ) }</library_materials>`;
|
||||
|
||||
dae += `<library_geometries>${ libraryGeometries.join( '' ) }</library_geometries>`;
|
||||
|
||||
dae += `<library_visual_scenes><visual_scene id="Scene" name="scene">${ libraryVisualScenes }</visual_scene></library_visual_scenes>`;
|
||||
|
||||
dae += '<scene><instance_visual_scene url="#Scene"/></scene>';
|
||||
|
||||
dae += '</COLLADA>';
|
||||
|
||||
var res = {
|
||||
data: format( dae ),
|
||||
textures
|
||||
};
|
||||
|
||||
if ( typeof onDone === 'function' ) {
|
||||
|
||||
requestAnimationFrame( () => onDone( res ) );
|
||||
|
||||
}
|
||||
|
||||
return res;
|
||||
|
||||
}
|
||||
|
||||
};
|
248
node_modules/three/examples/js/exporters/DRACOExporter.js
generated
vendored
Normal file
248
node_modules/three/examples/js/exporters/DRACOExporter.js
generated
vendored
Normal file
|
@ -0,0 +1,248 @@
|
|||
/**
|
||||
* Export draco compressed files from threejs geometry objects.
|
||||
*
|
||||
* Draco files are compressed and usually are smaller than conventional 3D file formats.
|
||||
*
|
||||
* The exporter receives a options object containing
|
||||
* - decodeSpeed, indicates how to tune the encoder regarding decode speed (0 gives better speed but worst quality)
|
||||
* - encodeSpeed, indicates how to tune the encoder parameters (0 gives better speed but worst quality)
|
||||
* - encoderMethod
|
||||
* - quantization, indicates the presision of each type of data stored in the draco file in the order (POSITION, NORMAL, COLOR, TEX_COORD, GENERIC)
|
||||
* - exportUvs
|
||||
* - exportNormals
|
||||
*/
|
||||
|
||||
/* global DracoEncoderModule */
|
||||
|
||||
THREE.DRACOExporter = function () {};
|
||||
|
||||
THREE.DRACOExporter.prototype = {
|
||||
|
||||
constructor: THREE.DRACOExporter,
|
||||
|
||||
parse: function ( object, options ) {
|
||||
|
||||
if ( object.isBufferGeometry === true ) {
|
||||
|
||||
throw new Error( 'DRACOExporter: The first parameter of parse() is now an instance of Mesh or Points.' );
|
||||
|
||||
}
|
||||
|
||||
if ( DracoEncoderModule === undefined ) {
|
||||
|
||||
throw new Error( 'THREE.DRACOExporter: required the draco_decoder to work.' );
|
||||
|
||||
}
|
||||
|
||||
if ( options === undefined ) {
|
||||
|
||||
options = {
|
||||
|
||||
decodeSpeed: 5,
|
||||
encodeSpeed: 5,
|
||||
encoderMethod: THREE.DRACOExporter.MESH_EDGEBREAKER_ENCODING,
|
||||
quantization: [ 16, 8, 8, 8, 8 ],
|
||||
exportUvs: true,
|
||||
exportNormals: true,
|
||||
exportColor: false,
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
var geometry = object.geometry;
|
||||
|
||||
var dracoEncoder = DracoEncoderModule();
|
||||
var encoder = new dracoEncoder.Encoder();
|
||||
var builder;
|
||||
var dracoObject;
|
||||
|
||||
|
||||
if ( geometry.isBufferGeometry !== true ) {
|
||||
|
||||
throw new Error( 'THREE.DRACOExporter.parse(geometry, options): geometry is not a THREE.BufferGeometry instance.' );
|
||||
|
||||
}
|
||||
|
||||
if ( object.isMesh === true ) {
|
||||
|
||||
builder = new dracoEncoder.MeshBuilder();
|
||||
dracoObject = new dracoEncoder.Mesh();
|
||||
|
||||
var vertices = geometry.getAttribute( 'position' );
|
||||
builder.AddFloatAttributeToMesh( dracoObject, dracoEncoder.POSITION, vertices.count, vertices.itemSize, vertices.array );
|
||||
|
||||
var faces = geometry.getIndex();
|
||||
|
||||
if ( faces !== null ) {
|
||||
|
||||
builder.AddFacesToMesh( dracoObject, faces.count / 3, faces.array );
|
||||
|
||||
} else {
|
||||
|
||||
var faces = new ( vertices.count > 65535 ? Uint32Array : Uint16Array )( vertices.count );
|
||||
|
||||
for ( var i = 0; i < faces.length; i ++ ) {
|
||||
|
||||
faces[ i ] = i;
|
||||
|
||||
}
|
||||
|
||||
builder.AddFacesToMesh( dracoObject, vertices.count, faces );
|
||||
|
||||
}
|
||||
|
||||
if ( options.exportNormals === true ) {
|
||||
|
||||
var normals = geometry.getAttribute( 'normal' );
|
||||
|
||||
if ( normals !== undefined ) {
|
||||
|
||||
builder.AddFloatAttributeToMesh( dracoObject, dracoEncoder.NORMAL, normals.count, normals.itemSize, normals.array );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if ( options.exportUvs === true ) {
|
||||
|
||||
var uvs = geometry.getAttribute( 'uv' );
|
||||
|
||||
if ( uvs !== undefined ) {
|
||||
|
||||
builder.AddFloatAttributeToMesh( dracoObject, dracoEncoder.TEX_COORD, uvs.count, uvs.itemSize, uvs.array );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if ( options.exportColor === true ) {
|
||||
|
||||
var colors = geometry.getAttribute( 'color' );
|
||||
|
||||
if ( colors !== undefined ) {
|
||||
|
||||
builder.AddFloatAttributeToMesh( dracoObject, dracoEncoder.COLOR, colors.count, colors.itemSize, colors.array );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
} else if ( object.isPoints === true ) {
|
||||
|
||||
builder = new dracoEncoder.PointCloudBuilder();
|
||||
dracoObject = new dracoEncoder.PointCloud();
|
||||
|
||||
var vertices = geometry.getAttribute( 'position' );
|
||||
builder.AddFloatAttribute( dracoObject, dracoEncoder.POSITION, vertices.count, vertices.itemSize, vertices.array );
|
||||
|
||||
if ( options.exportColor === true ) {
|
||||
|
||||
var colors = geometry.getAttribute( 'color' );
|
||||
|
||||
if ( colors !== undefined ) {
|
||||
|
||||
builder.AddFloatAttribute( dracoObject, dracoEncoder.COLOR, colors.count, colors.itemSize, colors.array );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
throw new Error( 'DRACOExporter: Unsupported object type.' );
|
||||
|
||||
}
|
||||
|
||||
//Compress using draco encoder
|
||||
|
||||
var encodedData = new dracoEncoder.DracoInt8Array();
|
||||
|
||||
//Sets the desired encoding and decoding speed for the given options from 0 (slowest speed, but the best compression) to 10 (fastest, but the worst compression).
|
||||
|
||||
var encodeSpeed = ( options.encodeSpeed !== undefined ) ? options.encodeSpeed : 5;
|
||||
var decodeSpeed = ( options.decodeSpeed !== undefined ) ? options.decodeSpeed : 5;
|
||||
|
||||
encoder.SetSpeedOptions( encodeSpeed, decodeSpeed );
|
||||
|
||||
// Sets the desired encoding method for a given geometry.
|
||||
|
||||
if ( options.encoderMethod !== undefined ) {
|
||||
|
||||
encoder.SetEncodingMethod( options.encoderMethod );
|
||||
|
||||
}
|
||||
|
||||
// Sets the quantization (number of bits used to represent) compression options for a named attribute.
|
||||
// The attribute values will be quantized in a box defined by the maximum extent of the attribute values.
|
||||
if ( options.quantization !== undefined ) {
|
||||
|
||||
for ( var i = 0; i < 5; i ++ ) {
|
||||
|
||||
if ( options.quantization[ i ] !== undefined ) {
|
||||
|
||||
encoder.SetAttributeQuantization( i, options.quantization[ i ] );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
var length;
|
||||
|
||||
if ( object.isMesh === true ) {
|
||||
|
||||
length = encoder.EncodeMeshToDracoBuffer( dracoObject, encodedData );
|
||||
|
||||
} else {
|
||||
|
||||
length = encoder.EncodePointCloudToDracoBuffer( dracoObject, true, encodedData );
|
||||
|
||||
}
|
||||
|
||||
dracoEncoder.destroy( dracoObject );
|
||||
|
||||
if ( length === 0 ) {
|
||||
|
||||
throw new Error( 'THREE.DRACOExporter: Draco encoding failed.' );
|
||||
|
||||
}
|
||||
|
||||
//Copy encoded data to buffer.
|
||||
var outputData = new Int8Array( new ArrayBuffer( length ) );
|
||||
|
||||
for ( var i = 0; i < length; i ++ ) {
|
||||
|
||||
outputData[ i ] = encodedData.GetValue( i );
|
||||
|
||||
}
|
||||
|
||||
dracoEncoder.destroy( encodedData );
|
||||
dracoEncoder.destroy( encoder );
|
||||
dracoEncoder.destroy( builder );
|
||||
|
||||
return outputData;
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
// Encoder methods
|
||||
|
||||
THREE.DRACOExporter.MESH_EDGEBREAKER_ENCODING = 1;
|
||||
THREE.DRACOExporter.MESH_SEQUENTIAL_ENCODING = 0;
|
||||
|
||||
// Geometry type
|
||||
|
||||
THREE.DRACOExporter.POINT_CLOUD = 0;
|
||||
THREE.DRACOExporter.TRIANGULAR_MESH = 1;
|
||||
|
||||
// Attribute type
|
||||
|
||||
THREE.DRACOExporter.INVALID = - 1;
|
||||
THREE.DRACOExporter.POSITION = 0;
|
||||
THREE.DRACOExporter.NORMAL = 1;
|
||||
THREE.DRACOExporter.COLOR = 2;
|
||||
THREE.DRACOExporter.TEX_COORD = 3;
|
||||
THREE.DRACOExporter.GENERIC = 4;
|
2328
node_modules/three/examples/js/exporters/GLTFExporter.js
generated
vendored
Normal file
2328
node_modules/three/examples/js/exporters/GLTFExporter.js
generated
vendored
Normal file
File diff suppressed because it is too large
Load diff
208
node_modules/three/examples/js/exporters/MMDExporter.js
generated
vendored
Normal file
208
node_modules/three/examples/js/exporters/MMDExporter.js
generated
vendored
Normal file
|
@ -0,0 +1,208 @@
|
|||
/**
|
||||
* Dependencies
|
||||
* - mmd-parser https://github.com/takahirox/mmd-parser
|
||||
*/
|
||||
|
||||
THREE.MMDExporter = function () {
|
||||
|
||||
// Unicode to Shift_JIS table
|
||||
var u2sTable;
|
||||
|
||||
function unicodeToShiftjis( str ) {
|
||||
|
||||
if ( u2sTable === undefined ) {
|
||||
|
||||
var encoder = new MMDParser.CharsetEncoder(); // eslint-disable-line no-undef
|
||||
var table = encoder.s2uTable;
|
||||
u2sTable = {};
|
||||
|
||||
var keys = Object.keys( table );
|
||||
|
||||
for ( var i = 0, il = keys.length; i < il; i ++ ) {
|
||||
|
||||
var key = keys[ i ];
|
||||
|
||||
var value = table[ key ];
|
||||
key = parseInt( key );
|
||||
|
||||
u2sTable[ value ] = key;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
var array = [];
|
||||
|
||||
for ( var i = 0, il = str.length; i < il; i ++ ) {
|
||||
|
||||
var code = str.charCodeAt( i );
|
||||
|
||||
var value = u2sTable[ code ];
|
||||
|
||||
if ( value === undefined ) {
|
||||
|
||||
throw 'cannot convert charcode 0x' + code.toString( 16 );
|
||||
|
||||
} else if ( value > 0xff ) {
|
||||
|
||||
array.push( ( value >> 8 ) & 0xff );
|
||||
array.push( value & 0xff );
|
||||
|
||||
} else {
|
||||
|
||||
array.push( value & 0xff );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return new Uint8Array( array );
|
||||
|
||||
}
|
||||
|
||||
function getBindBones( skin ) {
|
||||
|
||||
// any more efficient ways?
|
||||
var poseSkin = skin.clone();
|
||||
poseSkin.pose();
|
||||
return poseSkin.skeleton.bones;
|
||||
|
||||
}
|
||||
|
||||
/* TODO: implement
|
||||
// mesh -> pmd
|
||||
this.parsePmd = function ( object ) {
|
||||
|
||||
};
|
||||
*/
|
||||
|
||||
/* TODO: implement
|
||||
// mesh -> pmx
|
||||
this.parsePmx = function ( object ) {
|
||||
|
||||
};
|
||||
*/
|
||||
|
||||
/*
|
||||
* skeleton -> vpd
|
||||
* Returns Shift_JIS encoded Uint8Array. Otherwise return strings.
|
||||
*/
|
||||
this.parseVpd = function ( skin, outputShiftJis, useOriginalBones ) {
|
||||
|
||||
if ( skin.isSkinnedMesh !== true ) {
|
||||
|
||||
console.warn( 'THREE.MMDExporter: parseVpd() requires SkinnedMesh instance.' );
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
function toStringsFromNumber( num ) {
|
||||
|
||||
if ( Math.abs( num ) < 1e-6 ) num = 0;
|
||||
|
||||
var a = num.toString();
|
||||
|
||||
if ( a.indexOf( '.' ) === - 1 ) {
|
||||
|
||||
a += '.';
|
||||
|
||||
}
|
||||
|
||||
a += '000000';
|
||||
|
||||
var index = a.indexOf( '.' );
|
||||
|
||||
var d = a.slice( 0, index );
|
||||
var p = a.slice( index + 1, index + 7 );
|
||||
|
||||
return d + '.' + p;
|
||||
|
||||
}
|
||||
|
||||
function toStringsFromArray( array ) {
|
||||
|
||||
var a = [];
|
||||
|
||||
for ( var i = 0, il = array.length; i < il; i ++ ) {
|
||||
|
||||
a.push( toStringsFromNumber( array[ i ] ) );
|
||||
|
||||
}
|
||||
|
||||
return a.join( ',' );
|
||||
|
||||
}
|
||||
|
||||
skin.updateMatrixWorld( true );
|
||||
|
||||
var bones = skin.skeleton.bones;
|
||||
var bones2 = getBindBones( skin );
|
||||
|
||||
var position = new THREE.Vector3();
|
||||
var quaternion = new THREE.Quaternion();
|
||||
var quaternion2 = new THREE.Quaternion();
|
||||
var matrix = new THREE.Matrix4();
|
||||
|
||||
var array = [];
|
||||
array.push( 'Vocaloid Pose Data file' );
|
||||
array.push( '' );
|
||||
array.push( ( skin.name !== '' ? skin.name.replace( /\s/g, '_' ) : 'skin' ) + '.osm;' );
|
||||
array.push( bones.length + ';' );
|
||||
array.push( '' );
|
||||
|
||||
for ( var i = 0, il = bones.length; i < il; i ++ ) {
|
||||
|
||||
var bone = bones[ i ];
|
||||
var bone2 = bones2[ i ];
|
||||
|
||||
/*
|
||||
* use the bone matrix saved before solving IK.
|
||||
* see CCDIKSolver for the detail.
|
||||
*/
|
||||
if ( useOriginalBones === true &&
|
||||
bone.userData.ik !== undefined &&
|
||||
bone.userData.ik.originalMatrix !== undefined ) {
|
||||
|
||||
matrix.fromArray( bone.userData.ik.originalMatrix );
|
||||
|
||||
} else {
|
||||
|
||||
matrix.copy( bone.matrix );
|
||||
|
||||
}
|
||||
|
||||
position.setFromMatrixPosition( matrix );
|
||||
quaternion.setFromRotationMatrix( matrix );
|
||||
|
||||
var pArray = position.sub( bone2.position ).toArray();
|
||||
var qArray = quaternion2.copy( bone2.quaternion ).conjugate().multiply( quaternion ).toArray();
|
||||
|
||||
// right to left
|
||||
pArray[ 2 ] = - pArray[ 2 ];
|
||||
qArray[ 0 ] = - qArray[ 0 ];
|
||||
qArray[ 1 ] = - qArray[ 1 ];
|
||||
|
||||
array.push( 'Bone' + i + '{' + bone.name );
|
||||
array.push( ' ' + toStringsFromArray( pArray ) + ';' );
|
||||
array.push( ' ' + toStringsFromArray( qArray ) + ';' );
|
||||
array.push( '}' );
|
||||
array.push( '' );
|
||||
|
||||
}
|
||||
|
||||
array.push( '' );
|
||||
|
||||
var lines = array.join( '\n' );
|
||||
|
||||
return ( outputShiftJis === true ) ? unicodeToShiftjis( lines ) : lines;
|
||||
|
||||
};
|
||||
|
||||
/* TODO: implement
|
||||
// animation + skeleton -> vmd
|
||||
this.parseVmd = function ( object ) {
|
||||
|
||||
};
|
||||
*/
|
||||
|
||||
};
|
304
node_modules/three/examples/js/exporters/OBJExporter.js
generated
vendored
Normal file
304
node_modules/three/examples/js/exporters/OBJExporter.js
generated
vendored
Normal file
|
@ -0,0 +1,304 @@
|
|||
THREE.OBJExporter = function () {};
|
||||
|
||||
THREE.OBJExporter.prototype = {
|
||||
|
||||
constructor: THREE.OBJExporter,
|
||||
|
||||
parse: function ( object ) {
|
||||
|
||||
var output = '';
|
||||
|
||||
var indexVertex = 0;
|
||||
var indexVertexUvs = 0;
|
||||
var indexNormals = 0;
|
||||
|
||||
var vertex = new THREE.Vector3();
|
||||
var color = new THREE.Color();
|
||||
var normal = new THREE.Vector3();
|
||||
var uv = new THREE.Vector2();
|
||||
|
||||
var i, j, k, l, m, face = [];
|
||||
|
||||
var parseMesh = function ( mesh ) {
|
||||
|
||||
var nbVertex = 0;
|
||||
var nbNormals = 0;
|
||||
var nbVertexUvs = 0;
|
||||
|
||||
var geometry = mesh.geometry;
|
||||
|
||||
var normalMatrixWorld = new THREE.Matrix3();
|
||||
|
||||
if ( geometry.isBufferGeometry !== true ) {
|
||||
|
||||
throw new Error( 'THREE.OBJExporter: Geometry is not of type THREE.BufferGeometry.' );
|
||||
|
||||
}
|
||||
|
||||
// shortcuts
|
||||
var vertices = geometry.getAttribute( 'position' );
|
||||
var normals = geometry.getAttribute( 'normal' );
|
||||
var uvs = geometry.getAttribute( 'uv' );
|
||||
var indices = geometry.getIndex();
|
||||
|
||||
// name of the mesh object
|
||||
output += 'o ' + mesh.name + '\n';
|
||||
|
||||
// name of the mesh material
|
||||
if ( mesh.material && mesh.material.name ) {
|
||||
|
||||
output += 'usemtl ' + mesh.material.name + '\n';
|
||||
|
||||
}
|
||||
|
||||
// vertices
|
||||
|
||||
if ( vertices !== undefined ) {
|
||||
|
||||
for ( i = 0, l = vertices.count; i < l; i ++, nbVertex ++ ) {
|
||||
|
||||
vertex.x = vertices.getX( i );
|
||||
vertex.y = vertices.getY( i );
|
||||
vertex.z = vertices.getZ( i );
|
||||
|
||||
// transform the vertex to world space
|
||||
vertex.applyMatrix4( mesh.matrixWorld );
|
||||
|
||||
// transform the vertex to export format
|
||||
output += 'v ' + vertex.x + ' ' + vertex.y + ' ' + vertex.z + '\n';
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// uvs
|
||||
|
||||
if ( uvs !== undefined ) {
|
||||
|
||||
for ( i = 0, l = uvs.count; i < l; i ++, nbVertexUvs ++ ) {
|
||||
|
||||
uv.x = uvs.getX( i );
|
||||
uv.y = uvs.getY( i );
|
||||
|
||||
// transform the uv to export format
|
||||
output += 'vt ' + uv.x + ' ' + uv.y + '\n';
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// normals
|
||||
|
||||
if ( normals !== undefined ) {
|
||||
|
||||
normalMatrixWorld.getNormalMatrix( mesh.matrixWorld );
|
||||
|
||||
for ( i = 0, l = normals.count; i < l; i ++, nbNormals ++ ) {
|
||||
|
||||
normal.x = normals.getX( i );
|
||||
normal.y = normals.getY( i );
|
||||
normal.z = normals.getZ( i );
|
||||
|
||||
// transform the normal to world space
|
||||
normal.applyMatrix3( normalMatrixWorld ).normalize();
|
||||
|
||||
// transform the normal to export format
|
||||
output += 'vn ' + normal.x + ' ' + normal.y + ' ' + normal.z + '\n';
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// faces
|
||||
|
||||
if ( indices !== null ) {
|
||||
|
||||
for ( i = 0, l = indices.count; i < l; i += 3 ) {
|
||||
|
||||
for ( m = 0; m < 3; m ++ ) {
|
||||
|
||||
j = indices.getX( i + m ) + 1;
|
||||
|
||||
face[ m ] = ( indexVertex + j ) + ( normals || uvs ? '/' + ( uvs ? ( indexVertexUvs + j ) : '' ) + ( normals ? '/' + ( indexNormals + j ) : '' ) : '' );
|
||||
|
||||
}
|
||||
|
||||
// transform the face to export format
|
||||
output += 'f ' + face.join( ' ' ) + '\n';
|
||||
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
for ( i = 0, l = vertices.count; i < l; i += 3 ) {
|
||||
|
||||
for ( m = 0; m < 3; m ++ ) {
|
||||
|
||||
j = i + m + 1;
|
||||
|
||||
face[ m ] = ( indexVertex + j ) + ( normals || uvs ? '/' + ( uvs ? ( indexVertexUvs + j ) : '' ) + ( normals ? '/' + ( indexNormals + j ) : '' ) : '' );
|
||||
|
||||
}
|
||||
|
||||
// transform the face to export format
|
||||
output += 'f ' + face.join( ' ' ) + '\n';
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// update index
|
||||
indexVertex += nbVertex;
|
||||
indexVertexUvs += nbVertexUvs;
|
||||
indexNormals += nbNormals;
|
||||
|
||||
};
|
||||
|
||||
var parseLine = function ( line ) {
|
||||
|
||||
var nbVertex = 0;
|
||||
|
||||
var geometry = line.geometry;
|
||||
var type = line.type;
|
||||
|
||||
if ( geometry.isBufferGeometry !== true ) {
|
||||
|
||||
throw new Error( 'THREE.OBJExporter: Geometry is not of type THREE.BufferGeometry.' );
|
||||
|
||||
}
|
||||
|
||||
// shortcuts
|
||||
var vertices = geometry.getAttribute( 'position' );
|
||||
|
||||
// name of the line object
|
||||
output += 'o ' + line.name + '\n';
|
||||
|
||||
if ( vertices !== undefined ) {
|
||||
|
||||
for ( i = 0, l = vertices.count; i < l; i ++, nbVertex ++ ) {
|
||||
|
||||
vertex.x = vertices.getX( i );
|
||||
vertex.y = vertices.getY( i );
|
||||
vertex.z = vertices.getZ( i );
|
||||
|
||||
// transform the vertex to world space
|
||||
vertex.applyMatrix4( line.matrixWorld );
|
||||
|
||||
// transform the vertex to export format
|
||||
output += 'v ' + vertex.x + ' ' + vertex.y + ' ' + vertex.z + '\n';
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if ( type === 'Line' ) {
|
||||
|
||||
output += 'l ';
|
||||
|
||||
for ( j = 1, l = vertices.count; j <= l; j ++ ) {
|
||||
|
||||
output += ( indexVertex + j ) + ' ';
|
||||
|
||||
}
|
||||
|
||||
output += '\n';
|
||||
|
||||
}
|
||||
|
||||
if ( type === 'LineSegments' ) {
|
||||
|
||||
for ( j = 1, k = j + 1, l = vertices.count; j < l; j += 2, k = j + 1 ) {
|
||||
|
||||
output += 'l ' + ( indexVertex + j ) + ' ' + ( indexVertex + k ) + '\n';
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// update index
|
||||
indexVertex += nbVertex;
|
||||
|
||||
};
|
||||
|
||||
var parsePoints = function ( points ) {
|
||||
|
||||
var nbVertex = 0;
|
||||
|
||||
var geometry = points.geometry;
|
||||
|
||||
if ( geometry.isBufferGeometry !== true ) {
|
||||
|
||||
throw new Error( 'THREE.OBJExporter: Geometry is not of type THREE.BufferGeometry.' );
|
||||
|
||||
}
|
||||
|
||||
var vertices = geometry.getAttribute( 'position' );
|
||||
var colors = geometry.getAttribute( 'color' );
|
||||
|
||||
output += 'o ' + points.name + '\n';
|
||||
|
||||
if ( vertices !== undefined ) {
|
||||
|
||||
for ( i = 0, l = vertices.count; i < l; i ++, nbVertex ++ ) {
|
||||
|
||||
vertex.fromBufferAttribute( vertices, i );
|
||||
vertex.applyMatrix4( points.matrixWorld );
|
||||
|
||||
output += 'v ' + vertex.x + ' ' + vertex.y + ' ' + vertex.z;
|
||||
|
||||
if ( colors !== undefined ) {
|
||||
|
||||
color.fromBufferAttribute( colors, i );
|
||||
|
||||
output += ' ' + color.r + ' ' + color.g + ' ' + color.b;
|
||||
|
||||
}
|
||||
|
||||
output += '\n';
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
output += 'p ';
|
||||
|
||||
for ( j = 1, l = vertices.count; j <= l; j ++ ) {
|
||||
|
||||
output += ( indexVertex + j ) + ' ';
|
||||
|
||||
}
|
||||
|
||||
output += '\n';
|
||||
|
||||
// update index
|
||||
indexVertex += nbVertex;
|
||||
|
||||
};
|
||||
|
||||
object.traverse( function ( child ) {
|
||||
|
||||
if ( child.isMesh === true ) {
|
||||
|
||||
parseMesh( child );
|
||||
|
||||
}
|
||||
|
||||
if ( child.isLine === true ) {
|
||||
|
||||
parseLine( child );
|
||||
|
||||
}
|
||||
|
||||
if ( child.isPoints === true ) {
|
||||
|
||||
parsePoints( child );
|
||||
|
||||
}
|
||||
|
||||
} );
|
||||
|
||||
return output;
|
||||
|
||||
}
|
||||
|
||||
};
|
523
node_modules/three/examples/js/exporters/PLYExporter.js
generated
vendored
Normal file
523
node_modules/three/examples/js/exporters/PLYExporter.js
generated
vendored
Normal file
|
@ -0,0 +1,523 @@
|
|||
/**
|
||||
* https://github.com/gkjohnson/ply-exporter-js
|
||||
*
|
||||
* Usage:
|
||||
* var exporter = new THREE.PLYExporter();
|
||||
*
|
||||
* // second argument is a list of options
|
||||
* exporter.parse(mesh, data => console.log(data), { binary: true, excludeAttributes: [ 'color' ], littleEndian: true });
|
||||
*
|
||||
* Format Definition:
|
||||
* http://paulbourke.net/dataformats/ply/
|
||||
*/
|
||||
|
||||
THREE.PLYExporter = function () {};
|
||||
|
||||
THREE.PLYExporter.prototype = {
|
||||
|
||||
constructor: THREE.PLYExporter,
|
||||
|
||||
parse: function ( object, onDone, options ) {
|
||||
|
||||
if ( onDone && typeof onDone === 'object' ) {
|
||||
|
||||
console.warn( 'THREE.PLYExporter: The options parameter is now the third argument to the "parse" function. See the documentation for the new API.' );
|
||||
options = onDone;
|
||||
onDone = undefined;
|
||||
|
||||
}
|
||||
|
||||
// Iterate over the valid meshes in the object
|
||||
function traverseMeshes( cb ) {
|
||||
|
||||
object.traverse( function ( child ) {
|
||||
|
||||
if ( child.isMesh === true ) {
|
||||
|
||||
var mesh = child;
|
||||
var geometry = mesh.geometry;
|
||||
|
||||
if ( geometry.isBufferGeometry !== true ) {
|
||||
|
||||
throw new Error( 'THREE.PLYExporter: Geometry is not of type THREE.BufferGeometry.' );
|
||||
|
||||
}
|
||||
|
||||
if ( geometry.hasAttribute( 'position' ) === true ) {
|
||||
|
||||
cb( mesh, geometry );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
} );
|
||||
|
||||
}
|
||||
|
||||
// Default options
|
||||
var defaultOptions = {
|
||||
binary: false,
|
||||
excludeAttributes: [], // normal, uv, color, index
|
||||
littleEndian: false
|
||||
};
|
||||
|
||||
options = Object.assign( defaultOptions, options );
|
||||
|
||||
var excludeAttributes = options.excludeAttributes;
|
||||
var includeNormals = false;
|
||||
var includeColors = false;
|
||||
var includeUVs = false;
|
||||
|
||||
// count the vertices, check which properties are used,
|
||||
// and cache the BufferGeometry
|
||||
var vertexCount = 0;
|
||||
var faceCount = 0;
|
||||
object.traverse( function ( child ) {
|
||||
|
||||
if ( child.isMesh === true ) {
|
||||
|
||||
var mesh = child;
|
||||
var geometry = mesh.geometry;
|
||||
|
||||
if ( geometry.isBufferGeometry !== true ) {
|
||||
|
||||
throw new Error( 'THREE.PLYExporter: Geometry is not of type THREE.BufferGeometry.' );
|
||||
|
||||
}
|
||||
|
||||
var vertices = geometry.getAttribute( 'position' );
|
||||
var normals = geometry.getAttribute( 'normal' );
|
||||
var uvs = geometry.getAttribute( 'uv' );
|
||||
var colors = geometry.getAttribute( 'color' );
|
||||
var indices = geometry.getIndex();
|
||||
|
||||
if ( vertices === undefined ) {
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
vertexCount += vertices.count;
|
||||
faceCount += indices ? indices.count / 3 : vertices.count / 3;
|
||||
|
||||
if ( normals !== undefined ) includeNormals = true;
|
||||
|
||||
if ( uvs !== undefined ) includeUVs = true;
|
||||
|
||||
if ( colors !== undefined ) includeColors = true;
|
||||
|
||||
}
|
||||
|
||||
} );
|
||||
|
||||
var includeIndices = excludeAttributes.indexOf( 'index' ) === - 1;
|
||||
includeNormals = includeNormals && excludeAttributes.indexOf( 'normal' ) === - 1;
|
||||
includeColors = includeColors && excludeAttributes.indexOf( 'color' ) === - 1;
|
||||
includeUVs = includeUVs && excludeAttributes.indexOf( 'uv' ) === - 1;
|
||||
|
||||
|
||||
if ( includeIndices && faceCount !== Math.floor( faceCount ) ) {
|
||||
|
||||
// point cloud meshes will not have an index array and may not have a
|
||||
// number of vertices that is divisble by 3 (and therefore representable
|
||||
// as triangles)
|
||||
console.error(
|
||||
|
||||
'PLYExporter: Failed to generate a valid PLY file with triangle indices because the ' +
|
||||
'number of indices is not divisible by 3.'
|
||||
|
||||
);
|
||||
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
var indexByteCount = 4;
|
||||
|
||||
var header =
|
||||
'ply\n' +
|
||||
`format ${ options.binary ? ( options.littleEndian ? 'binary_little_endian' : 'binary_big_endian' ) : 'ascii' } 1.0\n` +
|
||||
`element vertex ${vertexCount}\n` +
|
||||
|
||||
// position
|
||||
'property float x\n' +
|
||||
'property float y\n' +
|
||||
'property float z\n';
|
||||
|
||||
if ( includeNormals === true ) {
|
||||
|
||||
// normal
|
||||
header +=
|
||||
'property float nx\n' +
|
||||
'property float ny\n' +
|
||||
'property float nz\n';
|
||||
|
||||
}
|
||||
|
||||
if ( includeUVs === true ) {
|
||||
|
||||
// uvs
|
||||
header +=
|
||||
'property float s\n' +
|
||||
'property float t\n';
|
||||
|
||||
}
|
||||
|
||||
if ( includeColors === true ) {
|
||||
|
||||
// colors
|
||||
header +=
|
||||
'property uchar red\n' +
|
||||
'property uchar green\n' +
|
||||
'property uchar blue\n';
|
||||
|
||||
}
|
||||
|
||||
if ( includeIndices === true ) {
|
||||
|
||||
// faces
|
||||
header +=
|
||||
`element face ${faceCount}\n` +
|
||||
'property list uchar int vertex_index\n';
|
||||
|
||||
}
|
||||
|
||||
header += 'end_header\n';
|
||||
|
||||
|
||||
// Generate attribute data
|
||||
var vertex = new THREE.Vector3();
|
||||
var normalMatrixWorld = new THREE.Matrix3();
|
||||
var result = null;
|
||||
|
||||
if ( options.binary === true ) {
|
||||
|
||||
// Binary File Generation
|
||||
var headerBin = new TextEncoder().encode( header );
|
||||
|
||||
// 3 position values at 4 bytes
|
||||
// 3 normal values at 4 bytes
|
||||
// 3 color channels with 1 byte
|
||||
// 2 uv values at 4 bytes
|
||||
var vertexListLength = vertexCount * ( 4 * 3 + ( includeNormals ? 4 * 3 : 0 ) + ( includeColors ? 3 : 0 ) + ( includeUVs ? 4 * 2 : 0 ) );
|
||||
|
||||
// 1 byte shape desciptor
|
||||
// 3 vertex indices at ${indexByteCount} bytes
|
||||
var faceListLength = includeIndices ? faceCount * ( indexByteCount * 3 + 1 ) : 0;
|
||||
var output = new DataView( new ArrayBuffer( headerBin.length + vertexListLength + faceListLength ) );
|
||||
new Uint8Array( output.buffer ).set( headerBin, 0 );
|
||||
|
||||
|
||||
var vOffset = headerBin.length;
|
||||
var fOffset = headerBin.length + vertexListLength;
|
||||
var writtenVertices = 0;
|
||||
traverseMeshes( function ( mesh, geometry ) {
|
||||
|
||||
var vertices = geometry.getAttribute( 'position' );
|
||||
var normals = geometry.getAttribute( 'normal' );
|
||||
var uvs = geometry.getAttribute( 'uv' );
|
||||
var colors = geometry.getAttribute( 'color' );
|
||||
var indices = geometry.getIndex();
|
||||
|
||||
normalMatrixWorld.getNormalMatrix( mesh.matrixWorld );
|
||||
|
||||
for ( var i = 0, l = vertices.count; i < l; i ++ ) {
|
||||
|
||||
vertex.x = vertices.getX( i );
|
||||
vertex.y = vertices.getY( i );
|
||||
vertex.z = vertices.getZ( i );
|
||||
|
||||
vertex.applyMatrix4( mesh.matrixWorld );
|
||||
|
||||
|
||||
// Position information
|
||||
output.setFloat32( vOffset, vertex.x, options.littleEndian );
|
||||
vOffset += 4;
|
||||
|
||||
output.setFloat32( vOffset, vertex.y, options.littleEndian );
|
||||
vOffset += 4;
|
||||
|
||||
output.setFloat32( vOffset, vertex.z, options.littleEndian );
|
||||
vOffset += 4;
|
||||
|
||||
// Normal information
|
||||
if ( includeNormals === true ) {
|
||||
|
||||
if ( normals != null ) {
|
||||
|
||||
vertex.x = normals.getX( i );
|
||||
vertex.y = normals.getY( i );
|
||||
vertex.z = normals.getZ( i );
|
||||
|
||||
vertex.applyMatrix3( normalMatrixWorld ).normalize();
|
||||
|
||||
output.setFloat32( vOffset, vertex.x, options.littleEndian );
|
||||
vOffset += 4;
|
||||
|
||||
output.setFloat32( vOffset, vertex.y, options.littleEndian );
|
||||
vOffset += 4;
|
||||
|
||||
output.setFloat32( vOffset, vertex.z, options.littleEndian );
|
||||
vOffset += 4;
|
||||
|
||||
} else {
|
||||
|
||||
output.setFloat32( vOffset, 0, options.littleEndian );
|
||||
vOffset += 4;
|
||||
|
||||
output.setFloat32( vOffset, 0, options.littleEndian );
|
||||
vOffset += 4;
|
||||
|
||||
output.setFloat32( vOffset, 0, options.littleEndian );
|
||||
vOffset += 4;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// UV information
|
||||
if ( includeUVs === true ) {
|
||||
|
||||
if ( uvs != null ) {
|
||||
|
||||
output.setFloat32( vOffset, uvs.getX( i ), options.littleEndian );
|
||||
vOffset += 4;
|
||||
|
||||
output.setFloat32( vOffset, uvs.getY( i ), options.littleEndian );
|
||||
vOffset += 4;
|
||||
|
||||
} else if ( includeUVs !== false ) {
|
||||
|
||||
output.setFloat32( vOffset, 0, options.littleEndian );
|
||||
vOffset += 4;
|
||||
|
||||
output.setFloat32( vOffset, 0, options.littleEndian );
|
||||
vOffset += 4;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Color information
|
||||
if ( includeColors === true ) {
|
||||
|
||||
if ( colors != null ) {
|
||||
|
||||
output.setUint8( vOffset, Math.floor( colors.getX( i ) * 255 ) );
|
||||
vOffset += 1;
|
||||
|
||||
output.setUint8( vOffset, Math.floor( colors.getY( i ) * 255 ) );
|
||||
vOffset += 1;
|
||||
|
||||
output.setUint8( vOffset, Math.floor( colors.getZ( i ) * 255 ) );
|
||||
vOffset += 1;
|
||||
|
||||
} else {
|
||||
|
||||
output.setUint8( vOffset, 255 );
|
||||
vOffset += 1;
|
||||
|
||||
output.setUint8( vOffset, 255 );
|
||||
vOffset += 1;
|
||||
|
||||
output.setUint8( vOffset, 255 );
|
||||
vOffset += 1;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if ( includeIndices === true ) {
|
||||
|
||||
// Create the face list
|
||||
|
||||
if ( indices !== null ) {
|
||||
|
||||
for ( var i = 0, l = indices.count; i < l; i += 3 ) {
|
||||
|
||||
output.setUint8( fOffset, 3 );
|
||||
fOffset += 1;
|
||||
|
||||
output.setUint32( fOffset, indices.getX( i + 0 ) + writtenVertices, options.littleEndian );
|
||||
fOffset += indexByteCount;
|
||||
|
||||
output.setUint32( fOffset, indices.getX( i + 1 ) + writtenVertices, options.littleEndian );
|
||||
fOffset += indexByteCount;
|
||||
|
||||
output.setUint32( fOffset, indices.getX( i + 2 ) + writtenVertices, options.littleEndian );
|
||||
fOffset += indexByteCount;
|
||||
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
for ( var i = 0, l = vertices.count; i < l; i += 3 ) {
|
||||
|
||||
output.setUint8( fOffset, 3 );
|
||||
fOffset += 1;
|
||||
|
||||
output.setUint32( fOffset, writtenVertices + i, options.littleEndian );
|
||||
fOffset += indexByteCount;
|
||||
|
||||
output.setUint32( fOffset, writtenVertices + i + 1, options.littleEndian );
|
||||
fOffset += indexByteCount;
|
||||
|
||||
output.setUint32( fOffset, writtenVertices + i + 2, options.littleEndian );
|
||||
fOffset += indexByteCount;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
// Save the amount of verts we've already written so we can offset
|
||||
// the face index on the next mesh
|
||||
writtenVertices += vertices.count;
|
||||
|
||||
} );
|
||||
|
||||
result = output.buffer;
|
||||
|
||||
} else {
|
||||
|
||||
// Ascii File Generation
|
||||
// count the number of vertices
|
||||
var writtenVertices = 0;
|
||||
var vertexList = '';
|
||||
var faceList = '';
|
||||
|
||||
traverseMeshes( function ( mesh, geometry ) {
|
||||
|
||||
var vertices = geometry.getAttribute( 'position' );
|
||||
var normals = geometry.getAttribute( 'normal' );
|
||||
var uvs = geometry.getAttribute( 'uv' );
|
||||
var colors = geometry.getAttribute( 'color' );
|
||||
var indices = geometry.getIndex();
|
||||
|
||||
normalMatrixWorld.getNormalMatrix( mesh.matrixWorld );
|
||||
|
||||
// form each line
|
||||
for ( var i = 0, l = vertices.count; i < l; i ++ ) {
|
||||
|
||||
vertex.x = vertices.getX( i );
|
||||
vertex.y = vertices.getY( i );
|
||||
vertex.z = vertices.getZ( i );
|
||||
|
||||
vertex.applyMatrix4( mesh.matrixWorld );
|
||||
|
||||
|
||||
// Position information
|
||||
var line =
|
||||
vertex.x + ' ' +
|
||||
vertex.y + ' ' +
|
||||
vertex.z;
|
||||
|
||||
// Normal information
|
||||
if ( includeNormals === true ) {
|
||||
|
||||
if ( normals != null ) {
|
||||
|
||||
vertex.x = normals.getX( i );
|
||||
vertex.y = normals.getY( i );
|
||||
vertex.z = normals.getZ( i );
|
||||
|
||||
vertex.applyMatrix3( normalMatrixWorld ).normalize();
|
||||
|
||||
line += ' ' +
|
||||
vertex.x + ' ' +
|
||||
vertex.y + ' ' +
|
||||
vertex.z;
|
||||
|
||||
} else {
|
||||
|
||||
line += ' 0 0 0';
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// UV information
|
||||
if ( includeUVs === true ) {
|
||||
|
||||
if ( uvs != null ) {
|
||||
|
||||
line += ' ' +
|
||||
uvs.getX( i ) + ' ' +
|
||||
uvs.getY( i );
|
||||
|
||||
} else if ( includeUVs !== false ) {
|
||||
|
||||
line += ' 0 0';
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Color information
|
||||
if ( includeColors === true ) {
|
||||
|
||||
if ( colors != null ) {
|
||||
|
||||
line += ' ' +
|
||||
Math.floor( colors.getX( i ) * 255 ) + ' ' +
|
||||
Math.floor( colors.getY( i ) * 255 ) + ' ' +
|
||||
Math.floor( colors.getZ( i ) * 255 );
|
||||
|
||||
} else {
|
||||
|
||||
line += ' 255 255 255';
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
vertexList += line + '\n';
|
||||
|
||||
}
|
||||
|
||||
// Create the face list
|
||||
if ( includeIndices === true ) {
|
||||
|
||||
if ( indices !== null ) {
|
||||
|
||||
for ( var i = 0, l = indices.count; i < l; i += 3 ) {
|
||||
|
||||
faceList += `3 ${ indices.getX( i + 0 ) + writtenVertices }`;
|
||||
faceList += ` ${ indices.getX( i + 1 ) + writtenVertices }`;
|
||||
faceList += ` ${ indices.getX( i + 2 ) + writtenVertices }\n`;
|
||||
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
for ( var i = 0, l = vertices.count; i < l; i += 3 ) {
|
||||
|
||||
faceList += `3 ${ writtenVertices + i } ${ writtenVertices + i + 1 } ${ writtenVertices + i + 2 }\n`;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
faceCount += indices ? indices.count / 3 : vertices.count / 3;
|
||||
|
||||
}
|
||||
|
||||
writtenVertices += vertices.count;
|
||||
|
||||
} );
|
||||
|
||||
result = `${ header }${vertexList}${ includeIndices ? `${faceList}\n` : '\n' }`;
|
||||
|
||||
}
|
||||
|
||||
if ( typeof onDone === 'function' ) requestAnimationFrame( () => onDone( result ) );
|
||||
return result;
|
||||
|
||||
}
|
||||
|
||||
};
|
203
node_modules/three/examples/js/exporters/STLExporter.js
generated
vendored
Normal file
203
node_modules/three/examples/js/exporters/STLExporter.js
generated
vendored
Normal file
|
@ -0,0 +1,203 @@
|
|||
/**
|
||||
* Usage:
|
||||
* var exporter = new THREE.STLExporter();
|
||||
*
|
||||
* // second argument is a list of options
|
||||
* var data = exporter.parse( mesh, { binary: true } );
|
||||
*
|
||||
*/
|
||||
|
||||
THREE.STLExporter = function () {};
|
||||
|
||||
THREE.STLExporter.prototype = {
|
||||
|
||||
constructor: THREE.STLExporter,
|
||||
|
||||
parse: function ( scene, options ) {
|
||||
|
||||
if ( options === undefined ) options = {};
|
||||
|
||||
var binary = options.binary !== undefined ? options.binary : false;
|
||||
|
||||
//
|
||||
|
||||
var objects = [];
|
||||
var triangles = 0;
|
||||
|
||||
scene.traverse( function ( object ) {
|
||||
|
||||
if ( object.isMesh ) {
|
||||
|
||||
var geometry = object.geometry;
|
||||
|
||||
if ( geometry.isBufferGeometry !== true ) {
|
||||
|
||||
throw new Error( 'THREE.STLExporter: Geometry is not of type THREE.BufferGeometry.' );
|
||||
|
||||
}
|
||||
|
||||
var index = geometry.index;
|
||||
var positionAttribute = geometry.getAttribute( 'position' );
|
||||
|
||||
triangles += ( index !== null ) ? ( index.count / 3 ) : ( positionAttribute.count / 3 );
|
||||
|
||||
objects.push( {
|
||||
object3d: object,
|
||||
geometry: geometry
|
||||
} );
|
||||
|
||||
}
|
||||
|
||||
} );
|
||||
|
||||
var output;
|
||||
var offset = 80; // skip header
|
||||
|
||||
if ( binary === true ) {
|
||||
|
||||
var bufferLength = triangles * 2 + triangles * 3 * 4 * 4 + 80 + 4;
|
||||
var arrayBuffer = new ArrayBuffer( bufferLength );
|
||||
output = new DataView( arrayBuffer );
|
||||
output.setUint32( offset, triangles, true ); offset += 4;
|
||||
|
||||
} else {
|
||||
|
||||
output = '';
|
||||
output += 'solid exported\n';
|
||||
|
||||
}
|
||||
|
||||
var vA = new THREE.Vector3();
|
||||
var vB = new THREE.Vector3();
|
||||
var vC = new THREE.Vector3();
|
||||
var cb = new THREE.Vector3();
|
||||
var ab = new THREE.Vector3();
|
||||
var normal = new THREE.Vector3();
|
||||
|
||||
for ( var i = 0, il = objects.length; i < il; i ++ ) {
|
||||
|
||||
var object = objects[ i ].object3d;
|
||||
var geometry = objects[ i ].geometry;
|
||||
|
||||
var index = geometry.index;
|
||||
var positionAttribute = geometry.getAttribute( 'position' );
|
||||
|
||||
if ( index !== null ) {
|
||||
|
||||
// indexed geometry
|
||||
|
||||
for ( var j = 0; j < index.count; j += 3 ) {
|
||||
|
||||
var a = index.getX( j + 0 );
|
||||
var b = index.getX( j + 1 );
|
||||
var c = index.getX( j + 2 );
|
||||
|
||||
writeFace( a, b, c, positionAttribute, object );
|
||||
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
// non-indexed geometry
|
||||
|
||||
for ( var j = 0; j < positionAttribute.count; j += 3 ) {
|
||||
|
||||
var a = j + 0;
|
||||
var b = j + 1;
|
||||
var c = j + 2;
|
||||
|
||||
writeFace( a, b, c, positionAttribute, object );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if ( binary === false ) {
|
||||
|
||||
output += 'endsolid exported\n';
|
||||
|
||||
}
|
||||
|
||||
return output;
|
||||
|
||||
function writeFace( a, b, c, positionAttribute, object ) {
|
||||
|
||||
vA.fromBufferAttribute( positionAttribute, a );
|
||||
vB.fromBufferAttribute( positionAttribute, b );
|
||||
vC.fromBufferAttribute( positionAttribute, c );
|
||||
|
||||
if ( object.isSkinnedMesh === true ) {
|
||||
|
||||
object.boneTransform( a, vA );
|
||||
object.boneTransform( b, vB );
|
||||
object.boneTransform( c, vC );
|
||||
|
||||
}
|
||||
|
||||
vA.applyMatrix4( object.matrixWorld );
|
||||
vB.applyMatrix4( object.matrixWorld );
|
||||
vC.applyMatrix4( object.matrixWorld );
|
||||
|
||||
writeNormal( vA, vB, vC );
|
||||
|
||||
writeVertex( vA );
|
||||
writeVertex( vB );
|
||||
writeVertex( vC );
|
||||
|
||||
if ( binary === true ) {
|
||||
|
||||
output.setUint16( offset, 0, true ); offset += 2;
|
||||
|
||||
} else {
|
||||
|
||||
output += '\t\tendloop\n';
|
||||
output += '\tendfacet\n';
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function writeNormal( vA, vB, vC ) {
|
||||
|
||||
cb.subVectors( vC, vB );
|
||||
ab.subVectors( vA, vB );
|
||||
cb.cross( ab ).normalize();
|
||||
|
||||
normal.copy( cb ).normalize();
|
||||
|
||||
if ( binary === true ) {
|
||||
|
||||
output.setFloat32( offset, normal.x, true ); offset += 4;
|
||||
output.setFloat32( offset, normal.y, true ); offset += 4;
|
||||
output.setFloat32( offset, normal.z, true ); offset += 4;
|
||||
|
||||
} else {
|
||||
|
||||
output += '\tfacet normal ' + normal.x + ' ' + normal.y + ' ' + normal.z + '\n';
|
||||
output += '\t\touter loop\n';
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function writeVertex( vertex ) {
|
||||
|
||||
if ( binary === true ) {
|
||||
|
||||
output.setFloat32( offset, vertex.x, true ); offset += 4;
|
||||
output.setFloat32( offset, vertex.y, true ); offset += 4;
|
||||
output.setFloat32( offset, vertex.z, true ); offset += 4;
|
||||
|
||||
} else {
|
||||
|
||||
output += '\t\t\tvertex ' + vertex.x + ' ' + vertex.y + ' ' + vertex.z + '\n';
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue