浏览代码

CCDIKSolver rotationMin/Max support

Takahiro 7 年之前
父节点
当前提交
d19a0fd742
共有 1 个文件被更改,包括 22 次插入0 次删除
  1. 22 0
      examples/js/animation/CCDIKSolver.js

+ 22 - 0
examples/js/animation/CCDIKSolver.js

@@ -55,6 +55,8 @@ THREE.CCDIKSolver = ( function () {
 			var invLinkQ = new THREE.Quaternion();
 			var linkScale = new THREE.Vector3();
 			var axis = new THREE.Vector3();
+			var vector = new THREE.Vector3();
+			var vector2 = new THREE.Vector3();
 
 			return function update() {
 
@@ -90,6 +92,8 @@ THREE.CCDIKSolver = ( function () {
 							if ( links[ k ].enabled === false ) break;
 
 							var limitation = links[ k ].limitation;
+							var rotationMin = links[ k ].rotationMin;
+							var rotationMax = links[ k ].rotationMax;
 
 							// don't use getWorldPosition/Quaternion() here for the performance
 							// because they call updateMatrixWorld( true ) inside.
@@ -157,6 +161,24 @@ THREE.CCDIKSolver = ( function () {
 
 							}
 
+							if ( rotationMin !== undefined ) {
+
+								link.rotation.setFromVector3(
+									link.rotation
+										.toVector3( vector )
+										.max( vector2.fromArray( rotationMin ) ) );
+
+							}
+
+							if ( rotationMax !== undefined ) {
+
+								link.rotation.setFromVector3(
+									link.rotation
+										.toVector3( vector )
+										.min( vector2.fromArray( rotationMax ) ) );
+
+							}
+
 							link.updateMatrixWorld( true );
 
 							rotated = true;