public override void UpdateUMAMesh(bool updatedAtlas, UMAData umaData, string[] textureNameList, int atlasResolution)
        {
            this.umaData         = umaData;
            this.textureNameList = textureNameList;
            this.atlasResolution = atlasResolution;

            combinedMeshList     = new List <SkinnedMeshCombiner.CombineInstance>();
            combinedMaterialList = new List <Material>();

            if (updatedAtlas)
            {
                CombineByShader();
            }
            else
            {
                CombineByMaterial();
            }

            if (umaData.firstBake)
            {
                umaData.myRenderer.sharedMesh = new Mesh();
            }
            else
            {
                umaData.cleanMesh(false);
            }

            var boneMap = new Dictionary <Transform, Transform>();

            SkinnedMeshCombiner.CombineMeshes(umaData.myRenderer, combinedMeshList.ToArray(), boneMap);

            if (updatedAtlas)
            {
                RecalculateUV();
            }

            umaData.umaRecipe.ClearDNAConverters();
            for (int i = 0; i < umaData.umaRecipe.slotDataList.Length; i++)
            {
                SlotData slotData = umaData.umaRecipe.slotDataList[i];
                if (slotData != null)
                {
                    umaData.EnsureBoneData(slotData.umaBoneData, slotData.animatedBones, boneMap);

                    umaData.umaRecipe.AddDNAUpdater(slotData.slotDNA);
                }
            }

            umaData.myRenderer.quality = SkinQuality.Bone4;
            //umaData.myRenderer.useLightProbes = true;
            var materials = combinedMaterialList.ToArray();

            umaData.myRenderer.sharedMaterials = materials;
            //umaData.myRenderer.sharedMesh.RecalculateBounds();
            umaData.myRenderer.sharedMesh.name = "UMAMesh";

            umaData.firstBake = false;

            //FireSlotAtlasNotification(umaData, materials);
        }
Exemple #2
0
 /// <summary>
 /// Initialize UMA mesh cloth data from Unity Cloth
 /// </summary>
 /// <param name="cloth"></param>
 public void RetrieveDataFromUnityCloth(Cloth cloth)
 {
     clothSkinning           = cloth.coefficients;
     clothSkinningSerialized = new Vector2[clothSkinning.Length];
     for (int i = 0; i < clothSkinning.Length; i++)
     {
         SkinnedMeshCombiner.ConvertData(ref clothSkinning[i], ref clothSkinningSerialized[i]);
     }
 }
        /// <summary>
        /// Updates the UMA mesh and skeleton to match current slots.
        /// </summary>
        /// <param name="updatedAtlas">If set to <c>true</c> atlas has changed.</param>
        /// <param name="umaData">UMA data.</param>
        /// <param name="atlasResolution">Atlas resolution.</param>
        public override void UpdateUMAMesh(bool updatedAtlas, UMAData umaData, int atlasResolution)
        {
            this.umaData         = umaData;
            this.atlasResolution = atlasResolution;

            combinedMeshList     = new List <SkinnedMeshCombiner.CombineInstance>(umaData.umaRecipe.slotDataList.Length);
            combinedMaterialList = new List <Material>();

            BuildCombineInstances();

            EnsureUMADataSetup(umaData);
            umaData.skeleton.BeginSkeletonUpdate();

            UMAMeshData umaMesh = new UMAMeshData();

            umaMesh.ClaimSharedBuffers();

            SkinnedMeshCombiner.CombineMeshes(umaMesh, combinedMeshList.ToArray(), umaData.ignoreBlendShapes);

            if (updatedAtlas)
            {
                RecalculateUV(umaMesh);
            }

            umaMesh.ApplyDataToUnityMesh(umaData.myRenderer, umaData.skeleton);
            umaMesh.ReleaseSharedBuffers();

            umaData.umaRecipe.ClearDNAConverters();
            for (int i = 0; i < umaData.umaRecipe.slotDataList.Length; i++)
            {
                SlotData slotData = umaData.umaRecipe.slotDataList[i];
                if (slotData != null)
                {
//                    umaData.EnsureBoneData(slotData.umaBoneData, slotData.animatedBones, boneMap);

                    umaData.umaRecipe.AddDNAUpdater(slotData.asset.slotDNA);
                }
            }

            umaData.myRenderer.quality = SkinQuality.Bone4;
            //umaData.myRenderer.useLightProbes = true;
            var materials = combinedMaterialList.ToArray();

            umaData.myRenderer.sharedMaterials = materials;
            //umaData.myRenderer.sharedMesh.RecalculateBounds();
            umaData.myRenderer.sharedMesh.name = "UMAMesh";

            umaData.firstBake = false;

            //FireSlotAtlasNotification(umaData, materials);
        }
        /// <summary>
        /// Updates the UMA mesh and skeleton to match current slots.
        /// </summary>
        /// <param name="updatedAtlas">If set to <c>true</c> atlas has changed.</param>
        /// <param name="umaData">UMA data.</param>
        /// <param name="atlasResolution">Atlas resolution.</param>
        public override void UpdateUMAMesh(bool updatedAtlas, UMAData umaData, int atlasResolution)
        {
            this.umaData         = umaData;
            this.atlasResolution = atlasResolution;

            combinedMeshList     = new List <SkinnedMeshCombiner.CombineInstance>(umaData.umaRecipe.slotDataList.Length);
            combinedMaterialList = new List <Material>();

            EnsureUMADataSetup(umaData);
            umaData.skeleton.BeginSkeletonUpdate();

            for (currentRendererIndex = 0; currentRendererIndex < umaData.generatedMaterials.rendererCount; currentRendererIndex++)
            {
                //Move umaMesh creation to with in the renderer loops
                //May want to make sure to set all it's buffers to null instead of creating a new UMAMeshData
                UMAMeshData umaMesh = new UMAMeshData();
                umaMesh.ClaimSharedBuffers();

                umaMesh.subMeshCount = 0;
                umaMesh.vertexCount  = 0;

                combinedMeshList.Clear();
                combinedMaterialList.Clear();
                clothProperties = null;

                BuildCombineInstances();

                if (combinedMeshList.Count == 1)
                {
                    // fast track
                    var tempMesh = SkinnedMeshCombiner.ShallowInstanceMesh(combinedMeshList[0].meshData);
                    tempMesh.ApplyDataToUnityMesh(renderers[currentRendererIndex], umaData.skeleton);
                }
                else
                {
                    SkinnedMeshCombiner.CombineMeshes(umaMesh, combinedMeshList.ToArray(), umaData.blendShapeSettings);

                    if (updatedAtlas)
                    {
                        RecalculateUV(umaMesh);
                    }

                    umaMesh.ApplyDataToUnityMesh(renderers[currentRendererIndex], umaData.skeleton);
                }
                var cloth = renderers[currentRendererIndex].GetComponent <Cloth>();
                if (clothProperties != null)
                {
                    if (cloth != null)
                    {
                        clothProperties.ApplyValues(cloth);
                    }
                }
                else
                {
                    Destroy(cloth);
                }

                var materials = combinedMaterialList.ToArray();
                renderers[currentRendererIndex].sharedMaterials = materials;
                umaMesh.ReleaseSharedBuffers();
            }

            umaData.umaRecipe.ClearDNAConverters();
            for (int i = 0; i < umaData.umaRecipe.slotDataList.Length; i++)
            {
                SlotData slotData = umaData.umaRecipe.slotDataList[i];
                if (slotData != null)
                {
                    umaData.umaRecipe.AddDNAUpdater(slotData.asset.slotDNA);
                }
            }

            umaData.firstBake = false;
        }