public void Capture(Mesh mesh, Cloth cloth, MeshBuffer mbuf, AlembicRecorderSettings settings)
            {
                if (mesh == null || cloth == null)
                {
                    mbuf.Clear();
                    return;
                }

                if (remap.Count != mesh.vertexCount)
                {
                    GenerateRemapIndices(mesh, mbuf);
                }

                // capture cloth points and normals
                vertices.Assign(cloth.vertices);
                if (numRemappedVertices != vertices.Count)
                {
                    Debug.LogWarning("numRemappedVertices != vertices.Count");
                    return;
                }

                if (settings.meshNormals)
                {
                    normals.Assign(cloth.normals);
                }
                else
                {
                    normals.Clear();
                }

                // apply root bone transform
                if (rootBone != null)
                {
                    var mat = Matrix4x4.TRS(rootBone.localPosition, rootBone.localRotation, Vector3.one);
                    aeApplyMatrixP(vertices, vertices.Count, ref mat);
                    aeApplyMatrixV(normals, normals.Count, ref mat);
                }

                // remap vertices and normals
                for (int vi = 0; vi < remap.Count; ++vi)
                {
                    mbuf.points[vi] = vertices[remap[vi]];
                }
                if (normals.Count > 0)
                {
                    mbuf.normals.ResizeDiscard(remap.Count);
                    for (int vi = 0; vi < remap.Count; ++vi)
                    {
                        mbuf.normals[vi] = normals[remap[vi]];
                    }
                }

                // capture other components
                if (settings.meshUV0)
                {
                    mbuf.uv0.LockList(ls => mesh.GetUVs(0, ls));
                }
                else
                {
                    mbuf.uv0.Clear();
                }

                if (settings.meshUV1)
                {
                    mbuf.uv1.LockList(ls => mesh.GetUVs(1, ls));
                }
                else
                {
                    mbuf.uv1.Clear();
                }

                if (settings.meshColors)
                {
                    mbuf.colors.LockList(ls => mesh.GetColors(ls));
                }
                else
                {
                    mbuf.colors.Clear();
                }
            }
Ejemplo n.º 2
0
            public void Capture(Mesh mesh,
                                bool captureNormals, bool captureUV0, bool captureUV1, bool captureColors)
            {
                points.LockList(ls => mesh.GetVertices(ls));

                if (captureNormals)
                {
                    normals.LockList(ls => mesh.GetNormals(ls));
                }
                else
                {
                    normals.Clear();
                }

                if (captureUV0)
                {
                    uv0.LockList(ls => mesh.GetUVs(0, ls));
                }
                else
                {
                    uv0.Clear();
                }

                if (captureUV1)
                {
                    uv1.LockList(ls => mesh.GetUVs(1, ls));
                }
                else
                {
                    uv1.Clear();
                }

                if (captureColors)
                {
                    colors.LockList(ls => mesh.GetColors(ls));
                }
                else
                {
                    colors.Clear();
                }

                {
                    int submeshCount = mesh.subMeshCount;
                    if (submeshCount == 1)
                    {
                        indices.LockList(ls => mesh.GetTriangles(ls, 0));
                    }
                    else
                    {
                        indices.Assign(mesh.triangles);

                        while (facesets.Count < submeshCount)
                        {
                            facesets.Add(new PinnedList <int>());
                        }

                        int offsetTriangle = 0;
                        for (int smi = 0; smi < submeshCount; ++smi)
                        {
                            tmpIndices.LockList(ls => { mesh.GetTriangles(ls, smi); });
                            int numTriangles = tmpIndices.Count / 3;
                            facesets[smi].ResizeDiscard(numTriangles);
                            for (int ti = 0; ti < numTriangles; ++ti)
                            {
                                facesets[smi][ti] = ti + offsetTriangle;
                            }
                            offsetTriangle += numTriangles;
                        }
                    }
                }
            }