Skip to content

Commit

Permalink
3MFLoader: Add Preliminary Support for Loading Implicit Functions (#2…
Browse files Browse the repository at this point in the history
…9667)

* 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 <[email protected]>
  • Loading branch information
zalo and Mugen87 authored Oct 16, 2024
1 parent fdd528d commit aee03e7
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 1 deletion.
89 changes: 89 additions & 0 deletions examples/jsm/loaders/3MFLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) {

const metallicDisplaypropertiesData = {
Expand Down Expand Up @@ -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' ] = {};
const pbmetallicdisplaypropertiesNodes = resourcesNode.querySelectorAll( 'pbmetallicdisplayproperties' );

Expand Down Expand Up @@ -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 ) {
Expand Down
6 changes: 6 additions & 0 deletions examples/models/3mf/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,9 @@ License: BSD 2-Clause "Simplified" License
Source: https://github.com/3MFConsortium/3mf-samples (original name `pyramid_vertexcolor.3mf`)

License: BSD 2-Clause "Simplified" License

### volumetric.3mf

Source: https://github.com/3MFConsortium/gladius (original name `SphereInACage.3mf`)

License: BSD 2-Clause "Simplified" License
Binary file added examples/models/3mf/volumetric.3mf
Binary file not shown.
3 changes: 2 additions & 1 deletion examples/webgl_loader_3mf.html
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@
'cube_gears',
'facecolors',
'multipletextures',
'vertexcolors'
'vertexcolors',
'volumetric'
];

init();
Expand Down

0 comments on commit aee03e7

Please sign in to comment.