openfl / away3d

An open source, real-time 3D engine for OpenFL
Apache License 2.0
206 stars 34 forks source link

If _billboardAxis is not null in ParticleBillboardState, the display object will disappear. #43

Closed rainyt closed 3 years ago

rainyt commented 3 years ago
override public function setRenderState(stage3DProxy:Stage3DProxy, renderable:IRenderable, animationSubGeometry:AnimationSubGeometry, animationRegisterCache:AnimationRegisterCache, camera:Camera3D):Void
    {
        // TODO: not used

        var comps:Vector<Vector3D>;
        if (_billboardAxis != null) {
            var pos:Vector3D = renderable.getRenderSceneTransform(camera).position;
            var look:Vector3D = camera.sceneTransform.position.subtract(pos);
            var right:Vector3D = look.crossProduct(_billboardAxis);
            right.normalize();
            look = _billboardAxis.crossProduct(right);
            look.normalize();

            //create a quick inverse projection matrix
            _matrix.copyFrom(renderable.getRenderSceneTransform(camera));
            comps = Matrix3DUtils.decompose(_matrix, Orientation3D.AXIS_ANGLE);
            _matrix.copyColumnFrom(0, right);
            _matrix.copyColumnFrom(1, _billboardAxis);
            _matrix.copyColumnFrom(2, look);
            _matrix.copyColumnFrom(3, pos);
            _matrix.appendRotation(-comps[1].w*MathConsts.RADIANS_TO_DEGREES, comps[1]);
        } else {
            //create a quick inverse projection matrix
            _matrix.copyFrom(renderable.getRenderSceneTransform(camera));
            _matrix.append(camera.inverseSceneTransform);

            //decompose using axis angle rotations
            comps = Matrix3DUtils.decompose(_matrix, Orientation3D.AXIS_ANGLE);

            //recreate the matrix with just the rotation data
            _matrix.identity();
            _matrix.appendRotation(-comps[1].w*MathConsts.RADIANS_TO_DEGREES, comps[1]);
        }

        //set a new matrix transform constant
        animationRegisterCache.setVertexConstFromMatrix(animationRegisterCache.getRegisterIndex(_animationNode, ParticleBillboardNode.MATRIX_INDEX), _matrix);
    }

If _billboardAxis is not null in ParticleBillboardState, the display object will disappear.