public WorkingObject(Allocator allocator)
 {
     m_allocator    = allocator;
     m_mesh         = null;
     m_materials    = new DisposableList <WorkingMaterial>();
     m_localToWorld = Matrix4x4.identity;
 }
Exemple #2
0
        public static WorkingMesh ToWorkingMesh(this Mesh mesh, Allocator allocator)
        {
            var bindposes = mesh.bindposes;
            var wm        = new WorkingMesh(allocator, mesh.vertexCount, mesh.GetTriangleCount(), mesh.subMeshCount, bindposes.Length);

            mesh.ApplyToWorkingMesh(ref wm, bindposes);

            return(wm);
        }
        public void SetMesh(WorkingMesh mesh)
        {
            if (m_mesh == mesh)
            {
                return;
            }

            if (m_mesh != null)
            {
                m_mesh.Dispose();
                m_mesh = null;
            }

            m_mesh = mesh;
        }
        public void FromRenderer(MeshRenderer renderer)
        {
            //clean old data
            m_mesh?.Dispose();
            m_materials?.Dispose();

            MeshFilter filter = renderer.GetComponent <MeshFilter>();

            if (filter != null && filter.sharedMesh != null)
            {
                m_mesh = filter.sharedMesh.ToWorkingMesh(m_allocator);
            }

            foreach (var mat in renderer.sharedMaterials)
            {
                m_materials.Add(mat.ToWorkingMaterial(m_allocator));
            }

            m_localToWorld = renderer.localToWorldMatrix;
        }
Exemple #5
0
 // Taking bindposes optional parameter is ugly, but saves an additional array allocation if it was already
 // accessed to get the length
 public static void ApplyToWorkingMesh(this Mesh mesh, ref WorkingMesh wm, Matrix4x4[] bindposes = null)
 {
     wm.indexFormat  = mesh.indexFormat;
     wm.vertices     = mesh.vertices;
     wm.normals      = mesh.normals;
     wm.tangents     = mesh.tangents;
     wm.uv           = mesh.uv;
     wm.uv2          = mesh.uv2;
     wm.uv3          = mesh.uv3;
     wm.uv4          = mesh.uv4;
     wm.colors       = mesh.colors;
     wm.boneWeights  = mesh.boneWeights;
     wm.bindposes    = bindposes ?? mesh.bindposes;
     wm.subMeshCount = mesh.subMeshCount;
     for (int i = 0; i < mesh.subMeshCount; i++)
     {
         wm.SetTriangles(mesh.GetTriangles(i), i);
     }
     wm.name   = mesh.name;
     wm.bounds = mesh.bounds;
 }