Explorar el Código

Exporters: Add Object3D.pivot support. (#32769)

mrdoob hace 1 mes
padre
commit
2a1c19b998
Se han modificado 2 ficheros con 29 adiciones y 4 borrados
  1. 7 1
      examples/jsm/exporters/GLTFExporter.js
  2. 22 3
      examples/jsm/exporters/USDZExporter.js

+ 7 - 1
examples/jsm/exporters/GLTFExporter.js

@@ -2357,7 +2357,7 @@ class GLTFWriter {
 
 		const nodeDef = {};
 
-		if ( options.trs ) {
+		if ( options.trs && object.pivot === null ) {
 
 			const rotation = object.quaternion.toArray();
 			const position = object.position.toArray();
@@ -2395,6 +2395,12 @@ class GLTFWriter {
 
 			}
 
+			if ( object.pivot !== null ) {
+
+				console.warn( 'THREE.GLTFExporter: Pivot not supported by GLTF. Baking into matrix.', object );
+
+			}
+
 		}
 
 		// We don't export empty strings name because it represents no-name in Three.js.

+ 22 - 3
examples/jsm/exporters/USDZExporter.js

@@ -501,7 +501,6 @@ function buildHierarchy( object, parentNode, materials, usedNames, files, option
 function buildXform( object, usedNames ) {
 
 	const name = getName( object, usedNames );
-	const transform = buildMatrix( object.matrix );
 
 	if ( object.matrix.determinant() < 0 ) {
 
@@ -514,8 +513,28 @@ function buildXform( object, usedNames ) {
 
 	const node = new USDNode( name, 'Xform' );
 
-	node.addProperty( `matrix4d xformOp:transform = ${transform}` );
-	node.addProperty( 'uniform token[] xformOpOrder = ["xformOp:transform"]' );
+	if ( object.pivot !== null ) {
+
+		// Export with pivot using separate transform ops
+		const p = object.position;
+		const q = object.quaternion;
+		const s = object.scale;
+		const piv = object.pivot;
+
+		node.addProperty( `float3 xformOp:translate = (${p.x.toPrecision( PRECISION )}, ${p.y.toPrecision( PRECISION )}, ${p.z.toPrecision( PRECISION )})` );
+		node.addProperty( `float3 xformOp:translate:pivot = (${piv.x.toPrecision( PRECISION )}, ${piv.y.toPrecision( PRECISION )}, ${piv.z.toPrecision( PRECISION )})` );
+		node.addProperty( `quatf xformOp:orient = (${q.w.toPrecision( PRECISION )}, ${q.x.toPrecision( PRECISION )}, ${q.y.toPrecision( PRECISION )}, ${q.z.toPrecision( PRECISION )})` );
+		node.addProperty( `float3 xformOp:scale = (${s.x.toPrecision( PRECISION )}, ${s.y.toPrecision( PRECISION )}, ${s.z.toPrecision( PRECISION )})` );
+		node.addProperty( 'uniform token[] xformOpOrder = ["xformOp:translate", "xformOp:translate:pivot", "xformOp:orient", "xformOp:scale", "!invert!xformOp:translate:pivot"]' );
+
+	} else {
+
+		// Export as single transform matrix
+		const transform = buildMatrix( object.matrix );
+		node.addProperty( `matrix4d xformOp:transform = ${transform}` );
+		node.addProperty( 'uniform token[] xformOpOrder = ["xformOp:transform"]' );
+
+	}
 
 	return node;
 

粤ICP备19079148号