コード例 #1
0
        /**
         *  Create surface for overlay
         */
        public ArrayMesh createSurfaceOverlay(ArrayMesh mesh, string slotName, string urlPath, string overlayName, List <UMAReciepeBindPose> origBindPoses)
        {
            var file     = ResourceLoader.Load <PackedScene>(urlPath);
            var instance = file.Instance();
            var meshes   = new List <MeshInstance>();

            if (instance is Spatial)
            {
                foreach (var child in (instance as Spatial).GetChildren())
                {
                    if (child is MeshInstance)
                    {
                        meshes.Add(child as MeshInstance);
                    }
                }
            }

            if (instance is MeshInstance)
            {
                meshes.Add(instance as MeshInstance);
            }

            var mdt = new MeshDataTool();
            var idx = mesh.SurfaceFindByName(slotName);

            mdt.CreateFromSurface(mesh, idx);


            int totalSurfaces = 0;

            foreach (var mi in meshes)
            {
                var newMesh = (mi as MeshInstance).Mesh;
                var newSkin = (mi as MeshInstance).Skin;

                for (int surface = 0; surface < newMesh.GetSurfaceCount(); surface++)
                {
                    mesh.AddSurfaceFromArrays(Mesh.PrimitiveType.Triangles, createSurfaceByBones(newMesh as ArrayMesh, surface, newSkin, origBindPoses));
                    var lastId = mesh.GetSurfaceCount() - 1;

                    var mat = newMesh.SurfaceGetMaterial(surface);
                    mat.ResourceLocalToScene = true;

                    if (mat is SpatialMaterial)
                    {
                        (mat as SpatialMaterial).ParamsGrow       = true;
                        (mat as SpatialMaterial).ParamsGrowAmount = 0.005f;
                    }

                    mesh.SurfaceSetMaterial(lastId, mat);
                    mesh.SurfaceSetName(lastId, (totalSurfaces == 0) ? overlayName : overlayName + "/" + totalSurfaces);
                    totalSurfaces++;
                }

                changes++;
            }


            return(mesh);
        }
コード例 #2
0
        /**
         *  Create surface overlay
         */
        public ArrayMesh createSurface(ArrayMesh mesh, string urlPath, string overlayName)
        {
            var file     = ResourceLoader.Load <PackedScene>(urlPath);
            var instance = file.Instance();
            var meshes   = new List <MeshInstance>();

            if (instance is Spatial)
            {
                foreach (var child in (instance as Spatial).GetChildren())
                {
                    if (child is MeshInstance)
                    {
                        meshes.Add(child as MeshInstance);
                    }
                }
            }

            if (instance is MeshInstance)
            {
                meshes.Add(instance as MeshInstance);
            }

            int totalSurfaces = 0;

            foreach (var mi in meshes)
            {
                var newMesh = (mi as MeshInstance).Mesh;
                for (int surface = 0; surface < newMesh.GetSurfaceCount(); surface++)
                {
                    mesh.AddSurfaceFromArrays(Mesh.PrimitiveType.Triangles, newMesh.SurfaceGetArrays(surface));
                    var lastId = mesh.GetSurfaceCount() - 1;

                    var mat = newMesh.SurfaceGetMaterial(surface);
                    mat.ResourceLocalToScene = true;
                    mesh.SurfaceSetMaterial(lastId, mat);
                    mesh.SurfaceSetName(lastId, (totalSurfaces == 0) ? overlayName : overlayName + "/" + totalSurfaces);
                    totalSurfaces++;
                }

                changes++;
            }


            return(mesh);
        }
コード例 #3
0
        public static void CopyTo(this IMeshSurface surface, ArrayMesh target)
        {
            Ensure.That(surface, nameof(surface)).IsNotNull();
            Ensure.That(surface, nameof(surface)).IsNotNull();

            var index = target.SurfaceFindByName(surface.Key);

            if (index != -1)
            {
                target.SurfaceRemove(index);
            }

            var existingShapes = target.GetBlendShapeNames().ToHashSet();

            surface.BlendShapes.Map(b => b.Key).Filter(k => !existingShapes.Contains(k)).Iter(target.AddBlendShape);

            target.BlendShapeMode = surface.BlendShapeMode;

            var newIndex = target.GetSurfaceCount();

            Array CopyBlendShape(IMeshData <MorphableVertex> source)
            {
                var shape = new Array();

                source.Export()
                .Cast <object>()
                .Map((i, a) => i == (int)ArrayMesh.ArrayType.Index ? null : a)
                .Iter(a => shape.Add(a));

                return(shape);
            }

            var data   = surface.Data.Export();
            var shapes = new Array(surface.BlendShapes.Map(CopyBlendShape));

            target.AddSurfaceFromArrays(surface.PrimitiveType, data, shapes);
            target.SurfaceSetName(newIndex, surface.Key);

            surface.Material.Iter(m => target.SurfaceSetMaterial(newIndex, m));
        }