Esempio n. 1
0
        /// <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);
        }
Esempio n. 2
0
        /// <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;
        }