findNodes function
Implementation
void findNodes(MotionController motionController, Object3D? scene ) {
// Loop through the components and find the nodes needed for each components' visual responses
motionController.components.forEach((key, component ){
component as Component;
final type = component.type;
final touchPointNodeName = component.touchPointNodeName;
final visualResponses = component.visualResponses as Map;
if ( type == constants['ComponentType']['TOUCHPAD'] ) {
component.touchPointNode = scene?.getObjectByName( touchPointNodeName );
if ( component.touchPointNode != null) {
// Attach a touch dot to the touchpad.
final sphereGeometry = SphereGeometry( 0.001 );
final material = MeshBasicMaterial.fromMap( { 'color': 0x0000FF } );
final sphere = Mesh( sphereGeometry, material );
component.touchPointNode?.add( sphere );
}
else {
console.warning('Could not find touch dot, ${component.touchPointNodeName}, in touchpad component ${component.id}');
}
}
// Loop through all the visual responses to be applied to this component
visualResponses.forEach( (key, visualResponse ){
visualResponse as VisualResponse;
final valueNodeName = visualResponse.valueNodeName;
final minNodeName = visualResponse.minNodeName;
final maxNodeName = visualResponse.maxNodeName;
final valueNodeProperty = visualResponse.valueNodeProperty;
// If animating a transform, find the two nodes to be interpolated between.
if ( valueNodeProperty == constants['VisualResponseProperty']['TRANSFORM'] ) {
visualResponse.minNode = scene?.getObjectByName( minNodeName! );
visualResponse.maxNode = scene?.getObjectByName( maxNodeName! );
// If the extents cannot be found, skip this animation
if (visualResponse.minNode == null) {
console.warning('Could not find $minNodeName in the model');
return;
}
if (visualResponse.maxNode == null) {
console.warning('Could not find $maxNodeName in the model');
return;
}
}
// If the target node cannot be found, skip this animation
visualResponse.valueNode = scene?.getObjectByName( valueNodeName! );
if (visualResponse.valueNode == null) {
console.warning('Could not find $valueNodeName in the model');
}
});
});
}