Sfoglia il codice sorgente

3MFLoader: Add Preliminary Support for Loading Implicit Functions (#29667)

* Begin adding an implicit function node parser

* Begin adding TSL Node Generation

There has to be a better way...

* Remove references to TSL

* Remove vestigial testing code

* Fix deep scan issue...

* Update 3MFLoader.js

Clean up.

---------

Co-authored-by: Michael Herzog <michael.herzog@human-interactive.org>
Johnathon Selstad 1 anno fa
parent
commit
aee03e7623

+ 89 - 0
examples/jsm/loaders/3MFLoader.js

@@ -375,6 +375,70 @@ class ThreeMFLoader extends Loader {
 
 
 		}
 		}
 
 
+		function parseImplicitIONode( implicitIONode ) {
+
+			const portNodes = implicitIONode.children;
+			const portArguments = {};
+			for ( let i = 0; i < portNodes.length; i ++ ) {
+
+				const args = { type: portNodes[ i ].nodeName.substring( 2 ) };
+				for ( let j = 0; j < portNodes[ i ].attributes.length; j ++ ) {
+
+					const attrib = portNodes[ i ].attributes[ j ];
+					if ( attrib.specified ) {
+		 				args[ attrib.name ] = attrib.value; 
+					}
+				}
+
+				portArguments[ portNodes[ i ].getAttribute( 'identifier' ) ] = args;
+
+			}
+
+			return portArguments;
+
+		}
+
+		function parseImplicitFunctionNode( implicitFunctionNode ) {
+
+			const implicitFunctionData = {
+				id: implicitFunctionNode.getAttribute( 'id' ),
+				displayname: implicitFunctionNode.getAttribute( 'displayname' )
+			};
+
+			const functionNodes = implicitFunctionNode.children;
+
+			const operations = {};
+
+			for ( let i = 0; i < functionNodes.length; i ++ ) {
+
+				const operatorNode = functionNodes[ i ];
+
+				if ( operatorNode.nodeName === 'i:in' || operatorNode.nodeName === 'i:out' ) {
+
+					operations[ operatorNode.nodeName === 'i:in' ? "inputs" : "outputs" ] = parseImplicitIONode( operatorNode );
+
+				} else {
+
+					const inputNodes = operatorNode.children;
+					let portArguments = { "op": operatorNode.nodeName.substring( 2 ), "identifier": operatorNode.getAttribute( 'identifier' ) };
+					for ( let i = 0; i < inputNodes.length; i ++ ) {
+
+						portArguments[ inputNodes[ i ].nodeName.substring( 2 ) ] = parseImplicitIONode( inputNodes[ i ] );
+
+					}
+
+					operations[ portArguments[ "identifier" ] ] = portArguments;
+
+				}
+
+			}
+
+			implicitFunctionData[ 'operations' ] = operations;
+
+			return implicitFunctionData;
+
+		}
+
 		function parseMetallicDisplaypropertiesNode( metallicDisplaypropetiesNode ) {
 		function parseMetallicDisplaypropertiesNode( metallicDisplaypropetiesNode ) {
 
 
 			const metallicDisplaypropertiesData = {
 			const metallicDisplaypropertiesData = {
@@ -673,6 +737,25 @@ class ThreeMFLoader extends Loader {
 
 
 			//
 			//
 
 
+			const implicitFunctionNodes = resourcesNode.querySelectorAll( 'implicitfunction' );
+
+			if ( implicitFunctionNodes.length > 0 ) {
+
+				resourcesData[ 'implicitfunction' ] = {};
+
+			}
+
+
+			for ( let i = 0; i < implicitFunctionNodes.length; i ++ ) {
+
+				const implicitFunctionNode = implicitFunctionNodes[ i ];
+				const implicitFunctionData = parseImplicitFunctionNode( implicitFunctionNode );
+				resourcesData[ 'implicitfunction' ][ implicitFunctionData[ 'id' ] ] = implicitFunctionData;
+
+			}
+
+			//
+
 			resourcesData[ 'pbmetallicdisplayproperties' ] = {};
 			resourcesData[ 'pbmetallicdisplayproperties' ] = {};
 			const pbmetallicdisplaypropertiesNodes = resourcesNode.querySelectorAll( 'pbmetallicdisplayproperties' );
 			const pbmetallicdisplaypropertiesNodes = resourcesNode.querySelectorAll( 'pbmetallicdisplayproperties' );
 
 
@@ -1367,6 +1450,12 @@ class ThreeMFLoader extends Loader {
 
 
 			}
 			}
 
 
+			if ( modelData.resources.implicitfunction ) {
+
+				console.warn( 'THREE.ThreeMFLoader: Implicit Functions are implemented in data-only.', modelData.resources.implicitfunction );
+
+			}
+
 		}
 		}
 
 
 		function buildObjects( data3mf ) {
 		function buildObjects( data3mf ) {

+ 6 - 0
examples/models/3mf/README.md

@@ -23,3 +23,9 @@ License: BSD 2-Clause "Simplified" License
 Source: https://github.com/3MFConsortium/3mf-samples (original name `pyramid_vertexcolor.3mf`)
 Source: https://github.com/3MFConsortium/3mf-samples (original name `pyramid_vertexcolor.3mf`)
 
 
 License: BSD 2-Clause "Simplified" License
 License: BSD 2-Clause "Simplified" License
+
+### volumetric.3mf 
+
+Source: https://github.com/3MFConsortium/gladius (original name `SphereInACage.3mf`)
+
+License: BSD 2-Clause "Simplified" License

BIN
examples/models/3mf/volumetric.3mf


+ 2 - 1
examples/webgl_loader_3mf.html

@@ -46,7 +46,8 @@
 				'cube_gears',
 				'cube_gears',
 				'facecolors',
 				'facecolors',
 				'multipletextures',
 				'multipletextures',
-				'vertexcolors'
+				'vertexcolors',
+				'volumetric'
 			];
 			];
 
 
 			init();
 			init();

粤ICP备19079148号