Exemple #1
0
        void OnWillRenderObject()
        {
            if (neutrinoEffect_ == null || neutrinoEffectModel_ == null)
            {
                return;
            }

            Transform camTrans = Camera.current.transform;

            Neutrino._math.vec3 cameraRight =
                Neutrino._math.vec3_(camTrans.right.x, camTrans.right.y, camTrans.right.z);
            Neutrino._math.vec3 cameraUp =
                Neutrino._math.vec3_(camTrans.up.x, camTrans.up.y, camTrans.up.z);
            Neutrino._math.vec3 cameraDir =
                Neutrino._math.vec3_(camTrans.forward.x, camTrans.forward.y, camTrans.forward.z);

            Neutrino._math.quat rot = Neutrino._math.quat_(transform.rotation.w, transform.rotation.x, transform.rotation.y, transform.rotation.z);

            if (simulateInWorldSpace)
            {
                Neutrino._math.vec3 pos = Neutrino._math.vec3_(transform.position.x / transform.localScale.x,
                                                               transform.position.y / transform.localScale.y,
                                                               transform.position.z / transform.localScale.z);

                neutrinoEffect_.updateRenderBuffer(cameraRight, cameraUp, cameraDir, pos, rot);
            }
            else
            {
                Neutrino._math.quat invRot           = Neutrino._math.inverseq_(rot);
                Neutrino._math.vec3 localCameraRight = Neutrino._math.applyv3quat_(cameraRight, invRot);
                Neutrino._math.vec3 localCameraUp    = Neutrino._math.applyv3quat_(cameraUp, invRot);
                Neutrino._math.vec3 localCameraDir   = Neutrino._math.applyv3quat_(cameraDir, invRot);

                neutrinoEffect_.updateRenderBuffer(localCameraRight, localCameraUp, localCameraDir, null, null);
            }

            renderBuffer_.updateMesh();

            Material[] subMeshMaterials = new Material[renderBuffer_.RenderCallsCount];

            for (uint renderCallIndex = 0; renderCallIndex < renderBuffer_.RenderCallsCount; ++renderCallIndex)
            {
                subMeshMaterials[renderCallIndex] = materials_[renderBuffer_.RenderCalls[renderCallIndex].renderStyleIndex_];
            }

            MeshRenderer mr = gameObject.GetComponent <MeshRenderer>();

            mr.sharedMaterials = subMeshMaterials;
        }
Exemple #2
0
        void Update()
        {
            if (!neutrinoInited_)
            {
                initNeutrino();
            }

            if (neutrinoEffect_ == null || neutrinoEffectModel_ == null)
            {
                return;
            }

                        #if UNITY_EDITOR
            float frameTime = Time.realtimeSinceStartup - lastFrameTime_;
            lastFrameTime_ = Time.realtimeSinceStartup;

            if (frameTime > 1)
            {
                frameTime = 1;
            }
                        #else
            float frameTime = Time.time - lastFrameTime_;
            lastFrameTime_ = Time.time;
                        #endif
            Neutrino._math.quat rot = Neutrino._math.quat_(transform.rotation.w, transform.rotation.x, transform.rotation.y, transform.rotation.z);

            if (simulateInWorldSpace)
            {
                Neutrino._math.vec3 pos = Neutrino._math.vec3_(transform.position.x / transform.localScale.x,
                                                               transform.position.y / transform.localScale.y,
                                                               transform.position.z / transform.localScale.z);

                neutrinoEffect_.update(frameTime, pos, rot);
            }
            else
            {
                neutrinoEffect_.update(frameTime, null, null);
            }

                        #if UNITY_EDITOR
            SceneView.RepaintAll();
                        #endif
        }