bind method
dynamic
bind()
Implementation
bind() {
var targetObject = node;
var parsedPath = this.parsedPath;
var objectName = parsedPath["objectName"];
var propertyName = parsedPath["propertyName"];
var propertyIndex = parsedPath["propertyIndex"];
if (targetObject == null) {
targetObject =
PropertyBinding.findNode(rootNode, parsedPath["nodeName"]) ||
rootNode;
node = targetObject;
}
// set fail state so we can just 'return' on error
getValue = _getValue_unavailable;
setValue = _setValue_unavailable;
// ensure there is a value node
if (targetObject == null) {
print('THREE.PropertyBinding: Trying to update node for track: ' +
path +
' but it wasn\'t found.');
return;
}
if (objectName != null) {
var objectIndex = parsedPath["objectIndex"];
// special cases were we need to reach deeper into the hierarchy to get the face materials....
switch (objectName) {
case 'materials':
if (!targetObject.material) {
print(
'THREE.PropertyBinding: Can not bind to material as node does not have a material. ${this}');
return;
}
if (!targetObject.material.materials) {
print(
'THREE.PropertyBinding: Can not bind to material.materials as node.material does not have a materials array. ${this}');
return;
}
targetObject = targetObject.material.materials;
break;
case 'bones':
if (!targetObject.skeleton) {
print(
'THREE.PropertyBinding: Can not bind to bones as node does not have a skeleton. ${this}');
return;
}
// potential future optimization: skip this if propertyIndex is already an integer
// and convert the integer string to a true integer.
targetObject = targetObject.skeleton.bones;
// support resolving morphTarget names into indices.
for (var i = 0; i < targetObject.length; i++) {
if (targetObject[i].name == objectIndex) {
objectIndex = i;
break;
}
}
break;
default:
if (targetObject.getProperty(objectName) == null) {
print(
'THREE.PropertyBinding: Can not bind to objectName of node null. ${this}');
return;
}
// targetObject = targetObject[ objectName ];
targetObject = targetObject.getProperty(objectName);
}
if (objectIndex != null) {
if (targetObject[objectIndex] == null) {
print(
'THREE.PropertyBinding: Trying to bind to objectIndex of objectName, but is null.${this} $targetObject');
return;
}
targetObject = targetObject[objectIndex];
}
}
// resolve property
var nodeProperty = targetObject.getProperty(propertyName);
if (nodeProperty == null) {
var nodeName = parsedPath["nodeName"];
print(
'THREE.PropertyBinding: Trying to update property for track: $nodeName $propertyName but it wasn\'t found. $targetObject');
return;
}
// determine versioning scheme
var versioning = Versioning["None"];
this.targetObject = targetObject;
// if ( targetObject.needsUpdate != null ) { // material
if ( targetObject.runtimeType.toString().endsWith("Material")||targetObject.type.endsWith("Material")) { //GL -- needed release version web!!
versioning = Versioning["NeedsUpdate"];
} else if (targetObject.matrixWorldNeedsUpdate != null) {
// node transform
versioning = Versioning["MatrixWorldNeedsUpdate"];
}
// determine how the property gets bound
var bindingType = BindingType["Direct"];
if (propertyIndex != null) {
// access a sub element of the property array (only primitives are supported right now)
if (propertyName == 'morphTargetInfluences') {
// potential optimization, skip this if propertyIndex is already an integer, and convert the integer string to a true integer.
// support resolving morphTarget names into indices.
if (!targetObject.geometry) {
print(
'THREE.PropertyBinding: Can not bind to morphTargetInfluences because node does not have a geometry. ${this}');
return;
}
if (targetObject.geometry is BufferGeometry) {
if (!targetObject.geometry.morphAttributes) {
print(
'THREE.PropertyBinding: Can not bind to morphTargetInfluences because node does not have a geometry.morphAttributes. ${this}');
return;
}
if (targetObject.morphTargetDictionary[propertyIndex] != null) {
propertyIndex = targetObject.morphTargetDictionary[propertyIndex];
}
} else {
print(
'THREE.PropertyBinding: Can not bind to morphTargetInfluences on THREE.Geometry. Use THREE.BufferGeometry instead. ${this}');
return;
}
}
bindingType = BindingType["ArrayElement"];
resolvedProperty = nodeProperty;
this.propertyIndex = propertyIndex;
// } else if ( nodeProperty.fromArray != null && nodeProperty.toArray != null ) {
} else if (nodeProperty is Color || nodeProperty is Vector3 || nodeProperty is Quaternion) {// GL
// ["Color", "Vector3", "Quaternion"]
// .contains(nodeProperty.runtimeType.toString())) {
// must use copy for Object3D.Euler/Quaternion
bindingType = BindingType["HasFromToArray"];
resolvedProperty = nodeProperty;
} else if (nodeProperty is List) {
bindingType = BindingType["EntireArray"];
resolvedProperty = nodeProperty;
} else {
this.propertyName = propertyName;
}
// select getter / setter
getValue = getterByBindingType(bindingType!);
setValue = setterByBindingTypeAndVersioning(bindingType, versioning);
}