static void LoadAnimationStates(this AnimationStateComponent component, ModelPack modelPack) { component.cachedBoneKeyFrames.Clear(); for (int i = 0; i < modelPack.bones.Count; i++) { component.cachedBoneKeyFrames.Add((Vector3.Zero, Quaternion.Identity)); } int morphCount = modelPack.morphs.Count; component.Weights.Load(morphCount); component.stringToMorphIndex.Clear(); for (int i = 0; i < morphCount; i++) { component.stringToMorphIndex[modelPack.morphs[i].Name] = i; } }
public static void LoadPmx(this GameObject gameObject, ModelPack modelPack) { gameObject.Name = modelPack.name; gameObject.Description = modelPack.description; var renderer = new MMDRendererComponent(); gameObject.AddComponent(renderer); renderer.skinning = true; renderer.morphs.Clear(); renderer.morphs.AddRange(modelPack.morphs); var animationState = new AnimationStateComponent(); gameObject.AddComponent(animationState); animationState.LoadAnimationStates(modelPack); renderer.Initialize(modelPack); renderer.LoadMesh(modelPack); renderer.SetTransform(gameObject.Transform); }