Exemplo n.º 1
0
        public static TerrainData Convert(IExportContainer container, TerrainData origin)
        {
            TerrainData instance = new TerrainData(origin.AssetInfo);

            NamedObjectConverter.Convert(container, origin, instance);
            instance.SplatDatabase  = origin.SplatDatabase.Convert(container);
            instance.DetailDatabase = origin.DetailDatabase.Convert(container);
            instance.Heightmap      = origin.Heightmap.Convert(container);
            if (TerrainData.HasLightmap(container.ExportVersion))
            {
                instance.Lightmap = origin.Lightmap;
            }
            return(instance);
        }
Exemplo n.º 2
0
        public static Mesh Convert(IExportContainer container, Mesh origin)
        {
            Mesh instance = new Mesh(origin.AssetInfo);

            NamedObjectConverter.Convert(container, origin, instance);

            if (Mesh.HasBlendShapes(container.ExportVersion))
            {
                if (Mesh.HasBlendChannels(container.ExportVersion))
                {
                    instance.Shapes = GetShapes(container, origin);
                }
                else
                {
                    instance.BlendShapes   = GetBlendShapes(container, origin);
                    instance.ShapeVertices = GetShapeVertices(container, origin);
                }
            }
            if (Mesh.HasBindPose(container.ExportVersion))
            {
                instance.BindPose = GetBindPose(container, origin);
            }
            if (Mesh.HasBoneNameHashes(container.ExportVersion))
            {
                instance.BoneNameHashes   = GetBoneNameHashes(container, origin);
                instance.RootBoneNameHash = GetRootBoneNameHash(container, origin);
            }
            if (Mesh.HasBonesAABB(container.ExportVersion))
            {
                instance.BonesAABB = GetBonesAABB(container, origin);
                instance.VariableBoneCountWeights = GetVariableBoneCountWeights(container, origin);
            }
            if (Mesh.HasMeshCompression(container.ExportVersion))
            {
                instance.MeshCompression = GetMeshCompression(container, origin);
            }
            if (Mesh.HasStreamCompression(container.ExportVersion))
            {
                instance.StreamCompression = GetStreamCompression(container, origin);
            }
            if (Mesh.HasIsReadable(container.ExportVersion))
            {
                instance.IsReadable   = GetIsReadable(container, origin);
                instance.KeepVertices = GetKeepVertices(container, origin);
                instance.KeepIndices  = GetKeepIndices(container, origin);
            }
            if (Mesh.HasSkin(container.ExportVersion))
            {
                instance.Skin = origin.Skin;
            }

            if (Mesh.HasVertexData(container.ExportVersion))
            {
                if (Mesh.IsOnlyVertexData(container.ExportVersion))
                {
                    instance.VertexData = GetVertexData(container, origin);
                }
                else
                {
                    if (instance.MeshCompression == MeshCompression.Off)
                    {
                        instance.VertexData = GetVertexData(container, origin);
                    }
                    else
                    {
                        instance.Vertices = origin.Vertices.ToArray();
                        instance.UV       = origin.UV.ToArray();
                        instance.UV1      = origin.UV1.ToArray();
                        instance.Tangents = origin.Tangents.ToArray();
                        instance.Normals  = origin.Normals.ToArray();
                        instance.Colors   = origin.Colors.ToArray();
                    }
                }
            }
            else
            {
                instance.Vertices = origin.Vertices.ToArray();
                instance.UV       = origin.UV.ToArray();
                if (Mesh.HasUV1(container.ExportVersion))
                {
                    instance.UV1 = GetUV1(container, origin);
                }
                if (Mesh.HasTangentSpace(container.ExportVersion))
                {
                    instance.TangentSpace = origin.TangentSpace.ToArray();
                }
                else
                {
                    instance.Tangents = GetTangents(container, origin);
                    instance.Normals  = GetNormals(container, origin);
                }
                instance.Colors = origin.Colors.ToArray();
            }

            if (Mesh.HasCompressedMesh(container.ExportVersion))
            {
                instance.CompressedMesh = GetCompressedMesh(container, origin);
            }
            instance.LocalAABB = origin.LocalAABB;
            if (Mesh.HasCollisionTriangles(container.ExportVersion))
            {
                instance.CollisionTriangles   = origin.CollisionTriangles.ToArray();
                instance.CollisionVertexCount = origin.CollisionVertexCount;
            }
            instance.MeshUsageFlags = origin.MeshUsageFlags;
            if (Mesh.HasCollision(container.ExportVersion))
            {
                instance.CollisionData = GetCollisionData(container, origin);
            }
            if (Mesh.HasMeshMetrics(container.ExportVersion))
            {
                instance.MeshMetrics = GetMeshMetrics(container, origin);
            }
#if UNIVERSAL
            instance.MeshOptimizationFlags = origin.MeshOptimizationFlags;
#endif
            instance.StreamData = GetStreamData(container, origin);

            if (Mesh.HasLODData(container.ExportVersion))
            {
                instance.LODData = origin.LODData.Select(t => t.Convert(container)).ToArray();
            }
            else
            {
                if (Mesh.HasUse16bitIndices(container.ExportVersion))
                {
                    instance.Use16BitIndices = GetUse16bitIndices(container, origin);
                }
                else if (Mesh.HasIndexFormat(container.ExportVersion))
                {
                    instance.IndexFormat = GetIndexFormat(container, origin);
                }
                instance.IndexBuffer = GetIndexBuffer(container, origin);
                // since this method uses instance, we need to call it last
                instance.SubMeshes = GetSubMeshes(container, origin, instance);
            }

            return(instance);
        }