コード例 #1
0
        /**
         *  Clean up old surfacess
         **/
        private ArrayMesh cleanOldSlots(ArrayMesh oldMesh, UMAReciepe reciepe)
        {
            List <string> oldSurfaces = new List <string>();

            for (int surface = 0; surface < oldMesh.GetSurfaceCount(); surface++)
            {
                oldSurfaces.Add(oldMesh.SurfaceGetName(surface));
            }

            var allSlotNames = reciepe.slots.Select(tf => tf.Key).ToList();

            //clean up current surface by new slots
            foreach (var oldSurface in oldSurfaces)
            {
                bool exist = false;
                foreach (var reicpeSlotName in allSlotNames)
                {
                    if (oldSurface.Contains(reicpeSlotName))
                    {
                        exist = true;
                    }
                }

                if (!exist)
                {
                    Console.WriteLine("[UMA] Delete surface " + oldSurface);
                    oldMesh.SurfaceRemove(oldMesh.SurfaceFindByName(oldSurface));

                    changes++;
                }
            }

            return(oldMesh);
        }
コード例 #2
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);
        }
コード例 #3
0
    protected ArrayMesh changeSkinColorSurface(ArrayMesh oldMesh, UMAReciepe reciepe)
    {
        var skinableSlots = new Dictionary <string, string>();

        foreach (var slot in reciepe.slots)
        {
            var   origSlot = _slotList[slot.Key];
            var   slotName = slot.Key;
            float glow     = origSlot.Glow;

            if (origSlot.skinGroup.ToString() != "None")
            {
                skinableSlots.Add(slot.Key, origSlot.skinGroup.ToString());
            }

            foreach (var overlay in slot.Value)
            {
                var overlayName = slotName + "/Overlay_" + overlay.Key;
                var origOverlay = origSlot.overlayList[overlay.Key];

                if (origOverlay != null)
                {
                    string materialPath = null;
                    if (!String.IsNullOrEmpty(overlay.Value.usedMaterial) && origOverlay.isSkinable)
                    {
                        materialPath = System.IO.Path.Combine(origOverlay.fabricPath, overlay.Value.usedMaterial + ".tres");
                    }
                    bool  useAlbedoColor = origOverlay.useSkinColor;
                    Color albedoColor    = overlay.Value.overlayAlbedoColor;

                    assignMaterialOverlay(oldMesh, overlayName, useAlbedoColor, albedoColor, materialPath, glow);
                }
            }
        }

        foreach (var skinableSlot in skinableSlots)
        {
            var color = reciepe.skinColor.FirstOrDefault(df => df.Key == skinableSlot.Value);
            if (color.Key == null)
            {
                continue;
            }

            var surface = oldMesh.SurfaceFindByName(skinableSlot.Key);
            if (surface >= 0)
            {
                var mat = oldMesh.SurfaceGetMaterial(surface);
                if (mat != null && mat is SpatialMaterial)
                {
                    (mat as SpatialMaterial).AlbedoColor = color.Value;
                }
            }
        }

        return(oldMesh);
    }
コード例 #4
0
        private ArrayMesh cleanOldOverlays(ArrayMesh oldMesh, UMAReciepe reciepe)
        {
            List <string> oldSurfaces = new List <string>();

            for (int surface = 0; surface < oldMesh.GetSurfaceCount(); surface++)
            {
                oldSurfaces.Add(oldMesh.SurfaceGetName(surface));
            }

            foreach (var oldSurface in oldSurfaces)
            {
                bool exist = false;

                if (!oldSurface.Contains("Overlay_"))
                {
                    continue;
                }

                foreach (var slot in reciepe.slots)
                {
                    var slotName = slot.Key;

                    foreach (var overlay in slot.Value)
                    {
                        var overlayName = slotName + "/Overlay_" + overlay.Key;

                        if (oldSurface.Contains(overlayName))
                        {
                            exist = true;
                        }
                    }
                }

                if (!exist)
                {
                    Console.WriteLine("[UMA] Delete overlay " + oldSurface);
                    oldMesh.SurfaceRemove(oldMesh.SurfaceFindByName(oldSurface));

                    changes++;
                }
            }

            return(oldMesh);
        }
コード例 #5
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));
        }