public virtual void UpdateParticleEditorInformation()
 {
     for (int i = 0; i < actor.positions.Length; i++)
     {
         if (actor.active[i])
         {
             wsPositions[i]    = actor.GetParticlePosition(i);
             wsOrientations[i] = actor.GetParticleOrientation(i);
             facingCamera[i]   = true;
         }
     }
 }
        void DrawParticles(ObiActor actor)
        {
            using (m_DrawParticlesPerfMarker.Auto())
            {

                if (mesh == null || material == null || !render || !isActiveAndEnabled || !actor.isActiveAndEnabled || actor.solver == null)
                {
                    return;
                }

                ObiSolver solver = actor.solver;

                // figure out the size of our instance batches:
                meshesPerBatch = Constants.maxInstancesPerBatch;
                batchCount = actor.particleCount / meshesPerBatch + 1;
                meshesPerBatch = Mathf.Min(meshesPerBatch, actor.particleCount);

                Vector4 basis1 = new Vector4(1, 0, 0, 0);
                Vector4 basis2 = new Vector4(0, 1, 0, 0);
                Vector4 basis3 = new Vector4(0, 0, 1, 0);

                //Convert particle data to mesh instances:
                for (int i = 0; i < batchCount; i++)
                {

                    matrices.Clear();
                    colors.Clear();
                    mpb = new MaterialPropertyBlock();
                    int limit = Mathf.Min((i + 1) * meshesPerBatch, actor.activeParticleCount);

                    for (int j = i * meshesPerBatch; j < limit; ++j)
                    {
                        int solverIndex = actor.solverIndices[j];
                        actor.GetParticleAnisotropy(solverIndex, ref basis1, ref basis2, ref basis3);
                        matrices.Add(Matrix4x4.TRS(actor.GetParticlePosition(solverIndex),
                                                   actor.GetParticleOrientation(solverIndex),
                                                   Vector3.Scale(new Vector3(basis1[3], basis2[3], basis3[3]), instanceScale)));
                        colors.Add(actor.GetParticleColor(solverIndex));
                    }

                    if (colors.Count > 0)
                        mpb.SetVectorArray("_Color", colors);

                    // Send the meshes to be drawn:
                    Graphics.DrawMeshInstanced(mesh, 0, material, matrices, mpb);
                }
            }

        }
Пример #3
0
        void ScenePreCull(Camera cam)
        {
            if (mesh == null || material == null || !render || !isActiveAndEnabled || !actor.isActiveAndEnabled || !actor.Initialized)
            {
                return;
            }

            ObiSolver solver = actor.Solver;

            // figure out the size of our instance batches:
            meshesPerBatch = Constants.maxInstancesPerBatch;
            batchCount     = actor.positions.Length / meshesPerBatch + 1;
            meshesPerBatch = Mathf.Min(meshesPerBatch, actor.positions.Length);

            Vector4 basis1;
            Vector4 basis2;
            Vector4 basis3;

            //Convert particle data to mesh instances:
            for (int i = 0; i < batchCount; i++)
            {
                matrices.Clear();
                colors.Clear();
                mpb = new MaterialPropertyBlock();
                int limit = Mathf.Min((i + 1) * meshesPerBatch, actor.active.Length);

                for (int j = i * meshesPerBatch; j < limit; ++j)
                {
                    if (actor.active[j])
                    {
                        actor.GetParticleAnisotropy(j, out basis1, out basis2, out basis3);
                        matrices.Add(Matrix4x4.TRS(actor.GetParticlePosition(j),
                                                   actor.GetParticleOrientation(j),
                                                   Vector3.Scale(new Vector3(basis1[3], basis2[3], basis3[3]), instanceScale)));
                        colors.Add((actor.colors != null && j < actor.colors.Length) ? actor.colors[j] : Color.white);
                    }
                }

                if (colors.Count > 0)
                {
                    mpb.SetVectorArray("_Color", colors);
                }

                // Send the meshes to be drawn:
                Graphics.DrawMeshInstanced(mesh, 0, material, matrices, mpb);
            }
        }