public void BakeAllClips() { if (this.animation == null || this.animation.GetClipCount() == 0) { Debug.LogWarning("SkinnedMeshInstancer has no animation clips to instance."); return; } this.skinnedMeshRenderer = this.GetComponentInChildren <SkinnedMeshRenderer>(); if (this.skinnedMeshRenderer == null) { Debug.LogError("This GameObject is not a Skinned Mesh."); return; } //Initialize array of baked animation sequences this.SkinnedMeshBakedData = new SkinnedTemplateBakedData(this.name, this.animation.GetClipCount(), this.skinnedMeshRenderer, this.animation); //int clipIndex = 0; //foreach (AnimationState clipState in this.animation) //{ // //Prep animation clip for sampling // var curClip = this.AnimationClipsToBake[clipIndex] = this.animation.GetClip(clipState.name); // this.animation.Play(clipState.name, PlayMode.StopAll); // clipState.time = 0; // clipState.wrapMode = WrapMode.Clamp; // //Calculate number of meshes to bake in this clip sequence based on the clip's sampling framerate // uint numberOfFrames = (uint)Mathf.RoundToInt(curClip.frameRate * curClip.length); // this.BakedMeshAnimations.Add(new Mesh[numberOfFrames]); // var curBakedMeshSequence = this.BakedMeshAnimations[clipIndex]; // for (uint frameIndex = 0; frameIndex < numberOfFrames; frameIndex++) // { // //Bake sequence of meshes // var curMeshFrame = curBakedMeshSequence[frameIndex] = new Mesh(); // curMeshFrame.name = string.Format(@"{0}_Baked_{1}_{2}", this.skinnedMeshRenderer.name, clipIndex, frameIndex); // this.animation.Sample(); // this.skinnedMeshRenderer.BakeMesh(curMeshFrame); // clipState.time += (1.0f / curClip.frameRate); // } // this.animation.Stop(); // clipIndex++; //} }
public void BakeAllClips() { if (this.animation == null || this.animation.GetClipCount() == 0) { Debug.LogWarning("SkinnedMeshInstancer has no animation clips to instance."); return; } this.skinnedMeshRenderer = this.GetComponentInChildren<SkinnedMeshRenderer>(); if (this.skinnedMeshRenderer == null) { Debug.LogError("This GameObject is not a Skinned Mesh."); return; } //Initialize array of baked animation sequences this.SkinnedMeshBakedData = new SkinnedTemplateBakedData(this.name, this.animation.GetClipCount(), this.skinnedMeshRenderer, this.animation); //int clipIndex = 0; //foreach (AnimationState clipState in this.animation) //{ // //Prep animation clip for sampling // var curClip = this.AnimationClipsToBake[clipIndex] = this.animation.GetClip(clipState.name); // this.animation.Play(clipState.name, PlayMode.StopAll); // clipState.time = 0; // clipState.wrapMode = WrapMode.Clamp; // //Calculate number of meshes to bake in this clip sequence based on the clip's sampling framerate // uint numberOfFrames = (uint)Mathf.RoundToInt(curClip.frameRate * curClip.length); // this.BakedMeshAnimations.Add(new Mesh[numberOfFrames]); // var curBakedMeshSequence = this.BakedMeshAnimations[clipIndex]; // for (uint frameIndex = 0; frameIndex < numberOfFrames; frameIndex++) // { // //Bake sequence of meshes // var curMeshFrame = curBakedMeshSequence[frameIndex] = new Mesh(); // curMeshFrame.name = string.Format(@"{0}_Baked_{1}_{2}", this.skinnedMeshRenderer.name, clipIndex, frameIndex); // this.animation.Sample(); // this.skinnedMeshRenderer.BakeMesh(curMeshFrame); // clipState.time += (1.0f / curClip.frameRate); // } // this.animation.Stop(); // clipIndex++; //} }