Пример #1
0
var StackedRotateAxis = function(name, axis, angle) {
    Object.call(this);
    this._axis = vec3.fromValues(0, 0, 1);
    if (axis) vec3.copy(this._axis, axis);
    this._target = Target.createFloatTarget(typeof angle === 'number' ? angle : 0.0);
    if (name) this.setName(name);
};
        addIntersection: function() {
            this._src = utils.arrayUniq(this._src);
            var src = this._src;

            var center = vec3.create();
            var maxDistance = -Number.MAX_VALUE;
            var referencePlane = this._intersector._iReferencePlane;
            for (var i = 0; i < src.length; ++i) {
                vec3.add(center, center, src[i]);
                var d = Plane.distanceToPlane(referencePlane, src[i]);
                if (d > maxDistance) maxDistance = d;
            }

            vec3.scale(center, center, 1.0 / src.length);

            var intersection = this.initIntersection(new PolytopeIntersection());
            intersection._distance = Plane.distanceToPlane(referencePlane, center);
            intersection._maxDistance = maxDistance;
            vec3.copy(intersection._localIntersectionPoint, center);

            var maxNum = this._maxNumIntersectionsPoints;
            intersection._numIntersectionPoints = src.length < maxNum ? src.length : maxNum;

            for (i = 0; i < intersection._numIntersectionPoints; ++i) {
                intersection._intersectionPoints.push(vec3.clone(this._src[i]));
            }
        },
Пример #3
0
            return function(matrix /*, nodeVisitor */) {
                if (this.scale[0] === 0.0 && this.scale[1] === 0.0 && this.scale[2] === 0.0) {
                    return false;
                }
                scaleInverse[0] = 1.0 / this._scale[0];
                scaleInverse[1] = 1.0 / this._scale[1];
                scaleInverse[2] = 1.0 / this._scale[2];
                if (this.referenceFrame === TransformEnums.RELATIVE_RF) {
                    mat4.fromTranslation(tmpMat, vec3.neg(neg, this._position));
                    mat4.mul(matrix, tmpMat, matrix);

                    if (!quat.zeroRotation(this._rotation)) {
                        mat4.fromQuat(tmpMat, quat.invert(rotInverse, this._rotation));
                        mat4.mul(matrix, tmpMat, matrix);
                    }
                    mat4.fromScaling(tmpMat, scaleInverse);
                    mat4.mul(matrix, tmpMat, matrix);

                    mat4.fromTranslation(tmpMat, this._pivotPoint);
                    mat4.mul(matrix, tmpMat, matrix);
                } else {
                    // absolute
                    mat4.fromQuat(this._matrix, quat.invert(rotInverse, this._rotation));
                    mat4.translate(matrix, matrix, vec3.neg(neg, this._position));

                    mat4.fromScaling(tmpMat, scaleInverse);
                    mat4.mul(matrix, tmpMat, matrix);

                    mat4.fromTranslation(tmpMat, this._pivotPoint);
                    mat4.mul(matrix, tmpMat, matrix);
                }
                return true;
            };
Пример #4
0
    registerUpdateCallback: function(callbackName, node) {
        var json = this._glTFJSON;

        var animationCallback = null;
        if (json.nodes[callbackName].jointName) animationCallback = new UpdateBone();
        else animationCallback = new UpdateMatrixTransform();

        animationCallback.setName(callbackName);

        var translation = vec3.create();
        mat4.getTranslation(translation, node.getMatrix());

        var rotationQuat = quat.create();
        mat4.getRotation(rotationQuat, node.getMatrix());

        var scale = vec3.create();
        mat4.getScale(scale, node.getMatrix());

        animationCallback
            .getStackedTransforms()
            .push(new StackedTranslate('translation', translation));
        animationCallback
            .getStackedTransforms()
            .push(new StackedQuaternion('rotation', rotationQuat));
        animationCallback.getStackedTransforms().push(new StackedScale('scale', scale));

        node.addUpdateCallback(animationCallback);
    },
Пример #5
0
var createVec3Target = function(defaultValue) {
    return createTarget(
        channelType.Vec3,
        vec3.copy(vec3.create(), defaultValue),
        vec3.copy(vec3.create(), defaultValue)
    );
};
Пример #6
0
functorDrawArrays[primitiveSet.LINE_LOOP] = (function() {
    var v1 = vec3.create();
    var v2 = vec3.create();
    return function(first, count, cb, vertices) {
        var last = first + count - 1;
        for (var i = first; i < last; ++i) {
            var j = i * 3;
            v1[0] = vertices[j];
            v1[1] = vertices[j + 1];
            v1[2] = vertices[j + 2];
            j = (i + 1) * 3;
            v2[0] = vertices[j];
            v2[1] = vertices[j + 1];
            v2[2] = vertices[j + 2];
            cb.operatorLine(v1, v2);
        }
        last = last * 3;
        v1[0] = vertices[last];
        v1[1] = vertices[last + 1];
        v1[2] = vertices[last + 2];
        first = first * 3;
        v2[0] = vertices[first];
        v2[1] = vertices[first + 1];
        v2[2] = vertices[first + 2];
        cb.operatorLine(v1, v2);
    };
})();
Пример #7
0
functorDrawArrays[primitiveSet.TRIANGLE_STRIP] = (function() {
    var v1 = vec3.create();
    var v2 = vec3.create();
    var v3 = vec3.create();
    return function(first, count, cb, vertices) {
        for (var i = 2, pos = first; i < count; ++i, ++pos) {
            var j = pos * 3;
            v1[0] = vertices[j];
            v1[1] = vertices[j + 1];
            v1[2] = vertices[j + 2];
            j = (pos + 1) * 3;
            v2[0] = vertices[j];
            v2[1] = vertices[j + 1];
            v2[2] = vertices[j + 2];
            j = (pos + 2) * 3;
            v3[0] = vertices[j];
            v3[1] = vertices[j + 1];
            v3[2] = vertices[j + 2];
            if (i % 2) {
                cb.operatorTriangle(v1, v3, v2);
            } else {
                cb.operatorTriangle(v1, v2, v3);
            }
        }
    };
})();
Пример #8
0
functorDrawElements[primitiveSet.TRIANGLE_STRIP] = (function() {
    var v1 = vec3.create();
    var v2 = vec3.create();
    var v3 = vec3.create();
    return function(offset, count, indexes, cb, vertices) {
        for (var i = 2, pos = offset; i < count; ++i, ++pos) {
            var j = indexes[pos] * 3;
            v1[0] = vertices[j];
            v1[1] = vertices[j + 1];
            v1[2] = vertices[j + 2];
            j = indexes[pos + 1] * 3;
            v2[0] = vertices[j];
            v2[1] = vertices[j + 1];
            v2[2] = vertices[j + 2];
            j = indexes[pos + 2] * 3;
            v3[0] = vertices[j];
            v3[1] = vertices[j + 1];
            v3[2] = vertices[j + 2];
            if (i % 2) {
                cb.operatorTriangle(v1, v3, v2);
            } else {
                cb.operatorTriangle(v1, v2, v3);
            }
        }
    };
})();
        intersectPoint: (function() {
            var tmp = vec3.create();
            var dir = vec3.create();

            return function(v0, p0) {
                // https://www.geometrictools.com/GTEngine/Include/Mathematics/GteDistPointSegment.h
                var st = this._start;

                vec3.sub(tmp, v0, st);
                vec3.sub(dir, this._end, st);
                // compute ratio (projection on line)
                var r = vec3.dot(tmp, dir) * this._invLength * this._invLength;

                // compute distance to segment
                var distToSegmentSqr = 1.0;
                if (r < 0.0) distToSegmentSqr = vec3.sqrLen(tmp);
                else if (r > 1.0) distToSegmentSqr = vec3.sqrDist(v0, this._end);
                else distToSegmentSqr = vec3.sqrLen(vec3.scaleAndAdd(tmp, tmp, dir, -r));

                if (distToSegmentSqr > this._threshold * this._threshold) {
                    return;
                }

                var intersection = this.initIntersection(new LineSegmentIntersection());
                intersection._i1 = p0;
                intersection._r1 = 1.0;

                vec3.scaleAndAdd(intersection._localIntersectionPoint, st, dir, r);
                intersection._ratio = r;
            };
        })(),
Пример #10
0
            updateCalculatedNearFar: (function() {
                var nearVec = vec3.create();
                var farVec = vec3.create();

                return function(matrix, drawable) {
                    var bb = drawable.getBoundingBox();
                    var dNear, dFar;

                    // efficient computation of near and far, only taking into account the nearest and furthest
                    // corners of the bounding box.
                    dNear = this.distance(bb.corner(this._bbCornerNear, nearVec), matrix);
                    dFar = this.distance(bb.corner(this._bbCornerFar, farVec), matrix);

                    if (dNear > dFar) {
                        var tmp = dNear;
                        dNear = dFar;
                        dFar = tmp;
                    }

                    if (dFar < 0.0) {
                        // whole object behind the eye point so discard
                        return false;
                    }

                    if (dNear < this._computedNear) {
                        this._computedNear = dNear;
                    }

                    if (dFar > this._computedFar) {
                        this._computedFar = dFar;
                    }

                    return true;
                };
            })(),
Пример #11
0
functorDrawElements[primitiveSet.LINE_LOOP] = (function() {
    var v1 = vec3.create();
    var v2 = vec3.create();
    return function(offset, count, indexes, cb, vertices) {
        var last = offset + count - 1;
        for (var i = offset; i < last; ++i) {
            var j = indexes[i] * 3;
            v1[0] = vertices[j];
            v1[1] = vertices[j + 1];
            v1[2] = vertices[j + 2];
            j = indexes[i + 1] * 3;
            v2[0] = vertices[j];
            v2[1] = vertices[j + 1];
            v2[2] = vertices[j + 2];
            cb.operatorLine(v1, v2);
        }
        last = indexes[last] * 3;
        v1[0] = vertices[last];
        v1[1] = vertices[last + 1];
        v1[2] = vertices[last + 2];
        var first = indexes[0] * 3;
        v2[0] = vertices[first];
        v2[1] = vertices[first + 1];
        v2[2] = vertices[first + 2];
        cb.operatorLine(v1, v2);
    };
})();
Пример #12
0
var KdNode = function(first, second) {
    this._bb = new BoundingBox();
    this._first = first;
    this._second = second;
    // These variables represent the local clipped ray (for intersection test)
    // They are mostly temporary because they are recomputed for each intersection test
    this._nodeRayStart = vec3.create();
    this._nodeRayEnd = vec3.create();
};
Пример #13
0
        generate: function(geometry, texCoordUnit) {
            this._texCoordUnit = texCoordUnit;

            if (this._texCoordUnit === undefined) this._texCoordUnit = 0;

            var size = geometry.getAttributes().Vertex.getElements().length;
            this._T = new utils.Float32Array(size);
            this._B = new utils.Float32Array(size);
            this._N = new utils.Float32Array(size);

            geometry.getPrimitiveSetList().forEach(function(primitive) {
                this.computePrimitiveSet(geometry, primitive);
            }, this);

            var nbElements = size / 3;
            var tangents = new utils.Float32Array(nbElements * 4);

            var tmp0 = vec3.create();
            var tmp1 = vec3.create();
            var t3 = vec3.create();

            for (var i = 0; i < nbElements; i++) {
                var t = this._T.subarray(i * 3, i * 3 + 3);
                var n = this._N.subarray(i * 3, i * 3 + 3);
                var b = this._B.subarray(i * 3, i * 3 + 3);

                vec3.normalize(n, n);

                // Gram-Schmidt orthogonalize
                // vec3 t3 = (t - n * (n * t));
                // t3.normalize();
                // finalTangent = Vec4(t3, 0.0);
                // Calculate handedness
                // finalTangent[3] = (((n ^ t) * b) < 0.0) ? -1.0 : 1.0;
                // The bitangent vector B is then given by B = (N × T) · Tw

                var nt = vec3.dot(n, t);
                vec3.scale(tmp1, n, nt);
                vec3.sub(tmp0, t, tmp1);
                vec3.normalize(t3, tmp0);

                vec3.cross(tmp0, n, t);
                var sign = vec3.dot(tmp0, b);
                sign = sign < 0.0 ? -1.0 : 0.0;

                // TODO perf : cache index var id = i * 4;
                tangents[i * 4] = t3[0];
                tangents[i * 4 + 1] = t3[1];
                tangents[i * 4 + 2] = t3[2];
                tangents[i * 4 + 3] = sign;
            }

            geometry.getAttributes().Normal.setElements(this._N);
            geometry.getAttributes().Tangent = new BufferArray('ARRAY_BUFFER', tangents, 4);
        },
Пример #14
0
        return function(p0, p1) {
            if (this._limitOneIntersection && this._hit) return;
            if ((this._primitiveMask & intersectionEnums.LINE_PRIMITIVES) === 0) return;

            var vertices = this._vertices;
            vec3.set(v0, vertices[3 * p0], vertices[3 * p0 + 1], vertices[3 * p0 + 2]);
            vec3.set(v1, vertices[3 * p1], vertices[3 * p1 + 1], vertices[3 * p1 + 2]);

            this.intersectLine(v0, v1, p0, p1);
            this._primitiveIndex++;
        };
Пример #15
0
        return function(p0, p1, p2) {
            if (this._limitOneIntersection && this._hit) return;
            if ((this._primitiveMask & intersectionEnums.TRIANGLE_PRIMITIVES) === 0) return;

            var vertices = this._vertices;
            vec3.set(v0, vertices[3 * p0], vertices[3 * p0 + 1], vertices[3 * p0 + 2]);
            vec3.set(v1, vertices[3 * p1], vertices[3 * p1 + 1], vertices[3 * p1 + 2]);
            vec3.set(v2, vertices[3 * p2], vertices[3 * p2 + 1], vertices[3 * p2 + 2]);

            this.intersectTriangle(v0, v1, v2, p0, p1, p2);
            this._primitiveIndex++;
        };
Пример #16
0
    HMDdevice.requestAnimationFrame(function() {
        var worldFactor = worldFactorOverride !== undefined ? worldFactorOverride : 1.0;

        var left = HMDdevice.getEyeParameters('left');
        var right = HMDdevice.getEyeParameters('right');

        var frameData = new window.VRFrameData();
        HMDdevice.getFrameData(frameData);

        // Compute projections and view matrices for both eyes
        var viewLeft = mat4.fromTranslation(
            mat4.create(),
            vec3.fromValues(-worldFactor * left.offset[0], left.offset[1], left.offset[2])
        );
        var viewRight = mat4.fromTranslation(
            mat4.create(),
            vec3.fromValues(-worldFactor * right.offset[0], right.offset[1], right.offset[2])
        );

        // Each eye is rendered on a texture whose width is half of the final combined texture
        var eyeTextureSize = {
            width: Math.max(left.renderWidth, right.renderWidth),
            height: Math.max(left.renderHeight, right.renderHeight)
        };

        var leftEyeTexture = createTexture(eyeTextureSize);
        var rightEyeTexture = createTexture(eyeTextureSize);

        // Setup the render cameras for both eyes
        var camRttLeft = createCameraRtt(leftEyeTexture, frameData.leftProjectionMatrix);
        var camRttRight = createCameraRtt(rightEyeTexture, frameData.rightProjectionMatrix);

        // The viewMatrix of each eye is updated with the current viewer's camera viewMatrix
        var rootViewMatrix = viewer.getCamera().getViewMatrix();
        camRttLeft.addUpdateCallback(new UpdateRttCameraCallback(rootViewMatrix, viewLeft));
        camRttRight.addUpdateCallback(new UpdateRttCameraCallback(rootViewMatrix, viewRight));

        // Render both textures on the canvas, using the viewer's camera viewport to render on the fullscreen canvas
        var camCanvas = createCameraCanvas(
            leftEyeTexture,
            rightEyeTexture,
            viewer.getCamera().getViewport()
        );

        camRttLeft.addChild(rttScene);
        camRttRight.addChild(rttScene);

        root.addChild(camRttLeft);
        root.addChild(camRttRight);
        root.addChild(camCanvas);
    });
Пример #17
0
 expandRadiusBySphere: function(sh) {
     if (sh.valid()) {
         if (this.valid()) {
             var r = vec3.distance(this._center, sh._center) + sh._radius;
             if (r > this._radius) {
                 this._radius = r;
             }
             // else do nothing as vertex is within sphere.
         } else {
             vec3.copy(this._center, sh._center);
             this._radius = sh._radius;
         }
     }
 },
Пример #18
0
        computeTransformedVertex: function(id, out) {
            out = out || vec3.create();

            var id3 = id * 3;

            var weights = this._targetWeights;
            var vList = this.getVertexAttributeList();

            var baseVerts = vList.Vertex.getElements();

            var sumWeights = 1.0 - this._computeEffectiveSumWeights();
            out[0] = sumWeights * baseVerts[id3];
            out[1] = sumWeights * baseVerts[id3 + 1];
            out[2] = sumWeights * baseVerts[id3 + 2];

            for (var j = 0, nb = weights.length; j < nb; ++j) {
                var weight = weights[j];
                if (Math.abs(weight) <= MorphGeometry.EFFECTIVE_EPS) continue;

                var morphElts = vList['Vertex_' + j].getElements();
                out[0] += weight * morphElts[id3];
                out[1] += weight * morphElts[id3 + 1];
                out[2] += weight * morphElts[id3 + 2];
            }

            return out;
        },
Пример #19
0
        _debugCenterGeometry: function(node, color) {
            // draw cross with slightly different color than the geometry
            var bb = node.getBound();

            var verts = new Float32Array(18);
            var off = bb.radius() * 0.1;
            verts[0] = off;
            verts[3] = -off;

            verts[7] = off;
            verts[10] = -off;

            verts[14] = off;
            verts[17] = -off;

            var geo = new Geometry();
            geo.getAttributes().Vertex = new BufferArray(BufferArray.ARRAY_BUFFER, verts, 3);
            var primitive = new DrawArrays(primitiveSet.LINES, 0, 6);
            geo.getPrimitives().push(primitive);

            var mt = new MatrixTransform();
            var center = bb.center();
            mt.getMatrix()[12] = center[0];
            mt.getMatrix()[13] = center[1];
            mt.getMatrix()[14] = center[2];

            mt.addChild(geo);
            this.nodePath[this.nodePath.length - 2].addChild(mt);
            color = vec3.fromValues(color[0] * 0.8, color[1] * 0.8, color[2] * 0.8);
            geo.getOrCreateStateSet().addUniform(Uniform.createFloat3(color, 'uColorDebug'));
            mt.setStateSet(this._stCenter);

            mt._isCenterDebug = true;
        },
Пример #20
0
        _debugGeometry: function(node) {
            var debugColor = this._debugColor;
            var debugSkinning = this._debugSkinning && node instanceof RigGeometry;

            if (!debugColor && !debugSkinning) {
                if (node._originalStateSet !== undefined) {
                    node.setStateSet(node._originalStateSet || undefined);
                }
                return;
            }

            if (node._originalStateSet === undefined) {
                node._originalStateSet = node.getStateSet() || null;
            }

            var stateSet = new StateSet();
            node.setStateSet(stateSet);

            if (debugSkinning) {
                stateSet.setShaderGeneratorName('debugSkinning');
                this._debugRigGeometry(node);
                return;
            }

            // debug color
            var color = vec3.fromValues(Math.random(), Math.random(), Math.random());
            stateSet.addUniform(Uniform.createFloat3(color, 'uColorDebug'));
            stateSet.setShaderGeneratorName('debugGeometry');

            this._debugCenterGeometry(node, color);
        },
Пример #21
0
        expandByBoundingBox: (function() {
            var v = vec3.create();
            var newbb = new BoundingBox();

            return function(bb) {
                if (!bb.valid()) return;

                if (!this.valid()) {
                    this.copyBoundingBox(bb);
                    return;
                }

                vec3.copy(newbb._min, bb._min);
                vec3.copy(newbb._max, bb._max);

                for (var i = 0; i < 8; i++) {
                    vec3.sub(v, bb.corner(i, v), this._center); // get the direction vector from corner
                    vec3.normalize(v, v); // normalise it.
                    vec3.scaleAndAdd(v, this._center, v, -this._radius); // move the vector in the opposite direction distance radius.
                    newbb.expandByVec3(v); // add it into the new bounding box.
                }

                newbb.center(this._center);
                this._radius = newbb.radius();
            };
        })(),
Пример #22
0
var BuildKdTree = function(kdTree) {
    this._kdTree = kdTree;
    this._bb = new BoundingBox();
    this._primitiveIndices = undefined; // Uint32Array
    this._centers = undefined; // Float32Array
    this._axisOrder = vec3.create();
    this._stackLength = 0;
};
Пример #23
0
functorDrawArrays[primitiveSet.LINES] = (function() {
    var v1 = vec3.create();
    var v2 = vec3.create();
    return function(first, count, cb, vertices) {
        for (var i = first; i < first + count - 1; i += 2) {
            var j = i * 3;
            v1[0] = vertices[j];
            v1[1] = vertices[j + 1];
            v1[2] = vertices[j + 2];
            j = (i + 1) * 3;
            v2[0] = vertices[j];
            v2[1] = vertices[j + 1];
            v2[2] = vertices[j + 2];
            cb.operatorLine(v1, v2);
        }
    };
})();
Пример #24
0
        computePixelSizeVector: (function() {
            var scale00 = vec3.create();
            var scale10 = vec3.create();
            return function(W, P, M) {
                // Where W = viewport, P = ProjectionMatrix, M = ModelViewMatrix
                // Comment from OSG:
                // pre adjust P00,P20,P23,P33 by multiplying them by the viewport window matrix.
                // here we do it in short hand with the knowledge of how the window matrix is formed
                // note P23,P33 are multiplied by an implicit 1 which would come from the window matrix.

                // scaling for horizontal pixels
                var P00 = P[0] * W.width() * 0.5;
                var P20_00 = P[8] * W.width() * 0.5 + P[11] * W.width() * 0.5;
                vec3.set(
                    scale00,
                    M[0] * P00 + M[2] * P20_00,
                    M[4] * P00 + M[6] * P20_00,
                    M[8] * P00 + M[10] * P20_00
                );

                // scaling for vertical pixels
                var P10 = P[5] * W.height() * 0.5;
                var P20_10 = P[9] * W.height() * 0.5 + P[11] * W.height() * 0.5;
                vec3.set(
                    scale10,
                    M[1] * P10 + M[2] * P20_10,
                    M[5] * P10 + M[6] * P20_10,
                    M[9] * P10 + M[10] * P20_10
                );

                var P23 = P[11];
                var P33 = P[15];
                var pixelSizeVector = vec4.fromValues(
                    M[2] * P23,
                    M[6] * P23,
                    M[10] * P23,
                    M[14] * P23 + M[15] * P33
                );

                var scaleRatio =
                    0.7071067811 / Math.sqrt(vec3.sqrLen(scale00) + vec3.sqrLen(scale10));
                vec4.scale(pixelSizeVector, pixelSizeVector, scaleRatio);
                return pixelSizeVector;
            };
        })()
Пример #25
0
            return function(out, matrix) {
                if (!this.valid()) return out;

                if (out._center !== this._center) {
                    vec3.copy(out._center, this._center);
                    out._radius = this._radius;
                }
                var sphCenter = out._center;
                var sphRadius = out._radius;

                mat4.getSqrScale(scaleVec, matrix);
                var scale = Math.sqrt(Math.max(Math.max(scaleVec[0], scaleVec[1]), scaleVec[2]));
                sphRadius = sphRadius * scale;
                out._radius = sphRadius;
                vec3.transformMat4(sphCenter, sphCenter, matrix);

                return out;
            };
Пример #26
0
functorDrawElements[primitiveSet.LINE_STRIP] = (function() {
    var v1 = vec3.create();
    var v2 = vec3.create();
    return function(offset, count, indexes, cb, vertices) {
        var end = offset + count;
        for (var i = offset; i < end - 1; ++i) {
            var j = indexes[i] * 3;
            v1[0] = vertices[j];
            v1[1] = vertices[j + 1];
            v1[2] = vertices[j + 2];
            j = indexes[i + 1] * 3;
            v2[0] = vertices[j];
            v2[1] = vertices[j + 1];
            v2[2] = vertices[j + 2];
            cb.operatorLine(v1, v2);
        }
    };
})();
Пример #27
0
 return function(v) {
     if (this.valid()) {
         vec3.sub(dv, v, this.center(dv));
         var r = vec3.length(dv);
         if (r > this.radius()) {
             var dr = (r - this.radius()) * 0.5;
             this._center[0] += dv[0] * (dr / r);
             this._center[1] += dv[1] * (dr / r);
             this._center[2] += dv[2] * (dr / r);
             this._radius += dr;
         }
     } else {
         this._center[0] = v[0];
         this._center[1] = v[1];
         this._center[2] = v[2];
         this._radius = 0.0;
     }
 };
Пример #28
0
    test('Quat.makeRotateFromTo', function() {
        //var q1 = quat.makeRotateFromTo( vec3.fromValues( 1.0, 0.0, 0.0 ), vec3.fromValues( 0.0, 1.0, 0.0 ), Quat.create() );
        var q1 = quat.rotationTo(
            quat.create(),
            vec3.fromValues(1.0, 0.0, 0.0),
            vec3.fromValues(0.0, 1.0, 0.0)
        );
        assert.equalVector(q1, quat.fromValues(0.0, 0.0, 0.707107, 0.707107), 1e-5);

        // it test both makeRotate and makeRotateFromTo
        var qyrot = quat.setAxisAngle(quat.create(), [0.0, 1.0, 0.0], Math.PI / 2.0);
        var q2 = quat.rotationTo(
            quat.create(),
            vec3.fromValues(0.0, 0.0, 1.0),
            vec3.fromValues(1.0, 0.0, 0.0)
        );
        assert.equalVector(q2, qyrot, 1e-5);
    });
Пример #29
0
var Vec3CubicBezierInterpolator = (function() {
    var v0 = vec3.create();
    var v1 = vec3.create();
    var v2 = vec3.create();
    var v3 = vec3.create();

    return function(t, channelInstance) {
        var channel = channelInstance.channel;
        var value = channelInstance.value;
        var keys = channel.keys;
        var times = channel.times;

        if (t >= times[times.length - 1]) {
            channelInstance.key = 0;
            vec3CopyKeyFrame(keys.length - 9, keys, value);
            return;
        } else if (t <= times[0]) {
            channelInstance.key = 0;
            vec3CopyKeyFrame(0, keys, value);
            return;
        }

        var i = channelInstance.key;
        if (t > times[i]) while (times[i + 1] < t) i++;
        else if (t < times[i]) while (times[i] > t) i--;

        var tt = (t - times[i]) / (times[i + 1] - times[i]);
        var oneMinusT = 1.0 - tt;
        var oneMinusT2 = oneMinusT * oneMinusT;
        var oneMinusT3 = oneMinusT2 * oneMinusT;
        var t2 = tt * tt;

        var id = i * 9;
        vec3.scale(v0, vec3.set(v0, keys[id++], keys[id++], keys[id++]), oneMinusT3);
        vec3.scale(v1, vec3.set(v1, keys[id++], keys[id++], keys[id++]), 3.0 * tt * oneMinusT2);
        vec3.scale(v2, vec3.set(v2, keys[id++], keys[id++], keys[id++]), 3.0 * t2 * oneMinusT);
        vec3.scale(v3, vec3.set(v3, keys[id++], keys[id++], keys[id++]), t2 * tt);

        value[0] = v0[0] + v1[0] + v2[0] + v3[0];
        value[1] = v0[1] + v1[1] + v2[1] + v3[1];
        value[2] = v0[2] + v1[2] + v2[2] + v3[2];
        channelInstance.key = i;
    };
})();
Пример #30
0
        return function(p0) {
            if (this._limitOneIntersection && this._hit) return;
            if ((this._primitiveMask & intersectionEnums.POINT_PRIMITIVES) === 0) return;

            var vertices = this._vertices;
            vec3.set(v0, vertices[3 * p0], vertices[3 * p0 + 1], vertices[3 * p0 + 2]);

            this.intersectPoint(v0, p0);
            this._primitiveIndex++;
        };