Beispiel #1
0
        public Submesh3DCollection Clone(Mesh3D owner)
        {
            var clone = new Submesh3DCollection(owner);

            for (int i = 0; i < Count; i++)
            {
                clone.Add(this[i].Clone());
            }
            return(clone);
        }
Beispiel #2
0
 private static bool IsAnyBoneAffectOnMesh(Mesh3D mesh)
 {
     foreach (var submesh in mesh.Submeshes)
     {
         if (submesh.BoneNames.Any())
         {
             return(true);
         }
     }
     return(false);
 }
Beispiel #3
0
        private int CalcHashForMesh(Mesh3D mesh)
        {
            int hashCode;

            unchecked {
                hashCode = mesh.Opaque.GetHashCode() +
                           17 * mesh.CullMode.GetHashCode() +
                           19 * mesh.HitTestTarget.GetHashCode() +
                           23 * mesh.SkinningMode.GetHashCode();
            }
            return(hashCode);
        }
Beispiel #4
0
        private void MergeMeshes(Dictionary <int, List <Mesh3D> > map, Node3D model)
        {
            const int meshLimit  = ushort.MaxValue;
            const int bonesLimit = 50;

            if (map.Count == 0)
            {
                return;
            }
            foreach (var pair in map)
            {
                var materialsMap = new Dictionary <IMaterial, Dictionary <Mesh3D, List <Submesh3D> > >();
                foreach (var mesh in pair.Value)
                {
                    foreach (var submesh in mesh.Submeshes)
                    {
                        var material = submesh.Material;
                        if (!materialsMap.ContainsKey(material))
                        {
                            materialsMap[material] = new Dictionary <Mesh3D, List <Submesh3D> >();
                        }
                        if (!materialsMap[material].ContainsKey(mesh))
                        {
                            materialsMap[material][mesh] = new List <Submesh3D>();
                        }
                        materialsMap[material][mesh].Add(submesh);
                    }
                }

                foreach (var meshDescriptor in materialsMap.Values)
                {
                    var first   = meshDescriptor.First().Key;
                    var newMesh = new Mesh3D {
                        Opaque        = first.Opaque,
                        CullMode      = first.CullMode,
                        SkinningMode  = first.SkinningMode,
                        HitTestTarget = first.HitTestTarget
                    };
                    Submesh3D curSubmesh = null;
                    foreach (var meshAndSubmeshes in meshDescriptor)
                    {
                        var meshIdx = 0;
                        while (meshIdx < meshAndSubmeshes.Value.Count)
                        {
                            var submeshToMerge     = meshAndSubmeshes.Value[meshIdx];
                            var meshLocalTransform = meshAndSubmeshes.Key.LocalTransform;
                            MeshUtils.TransformVertices(submeshToMerge.Mesh, (ref Mesh3D.Vertex v) => {
                                v.Pos = meshLocalTransform.TransformVector(v.Pos);
                            });
                            if (curSubmesh == null)
                            {
                                curSubmesh = submeshToMerge;
                                meshAndSubmeshes.Value.RemoveAt(meshIdx);
                                meshIdx++;
                                continue;
                            }
                            if (curSubmesh.Mesh.Indices.Length + submeshToMerge.Mesh.Indices.Length < meshLimit &&
                                curSubmesh.BoneNames.Count + submeshToMerge.BoneNames.Count < bonesLimit
                                )
                            {
                                curSubmesh = Combine(curSubmesh, submeshToMerge);
                                meshAndSubmeshes.Value.RemoveAt(meshIdx);
                            }
                            else
                            {
                                newMesh.Submeshes.Add(curSubmesh);
                                curSubmesh = null;
                            }
                        }
                        newMesh.Id += (newMesh.Id == null ? "" : "|") + meshAndSubmeshes.Key.Id;
                    }
                    newMesh.Submeshes.Add(curSubmesh);
                    model.AddNode(newMesh);
                }
                foreach (var mesh in materialsMap.Values.SelectMany(kv => kv.Keys))
                {
                    mesh.UnlinkAndDispose();
                }
            }
        }
Beispiel #5
0
 public Submesh3DCollection(Mesh3D owner)
 {
     this.owner = owner;
 }