public M2ModelRenderer(M2File model) { mModel = model; mAnimator = ModelFactory.Instance.CreateAnimator(model); mAnimator.SetAnimationByIndex(0); mAnimator.Update(); }
public M2BatchRenderer(M2File model) { mModel = model; mAnimator = ModelFactory.Instance.CreateAnimator(model); mAnimator.SetAnimationByIndex(0); StaticAnimationThread.Instance.AddAnimator(mAnimator); }
private void Dispose(bool disposing) { DestroyModelNameplate(); mModel = null; mRenderer = null; }
public M2PortraitRenderer(M2File model) { Model = model; Textures = model.TextureInfos.ToArray(); mAnimationMatrices = new Matrix[model.GetNumberOfBones()]; Animator = ModelFactory.Instance.CreateAnimator(model); Animator.SetAnimation(AnimationType.Stand); Animator.Update(null); }
public M2AnimationBone(M2File file, ref M2Bone bone, BinaryReader reader) { Bone = bone; mPivot = Matrix.Translation(bone.pivot); mInvPivot = Matrix.Translation(-bone.pivot); mTranslation = new M2Vector3AnimationBlock(file, bone.translation, reader); mRotation = new M2Quaternion16AnimationBlock(file, bone.rotation, reader, Quaternion.Identity); mScaling = new M2Vector3AnimationBlock(file, bone.scaling, reader, Vector3.One); }
private void EventManager_FileExtractComplete(object sender, EventArgs e) { if (!(e is FileExtractCompleteUnsafeArgs)) { return; } FileExtractCompleteUnsafeArgs args = (FileExtractCompleteUnsafeArgs)e; if (runner != null && args.RunnerID == runner.runnerID) { if (args.File.ToLower().EndsWith(".skin")) { extractSkinFile = args.File; } else { extractModelFile = args.File; } if (extractSkinFile != null && extractModelFile != null) { string modelTempPath = Path.Combine(Constants.TEMP_DIRECTORY, extractModelFile); string skinTempPath = Path.Combine(Constants.TEMP_DIRECTORY, extractSkinFile); try { if (!File.Exists(modelTempPath)) { throw new M2Exception(string.Format("Extracted model file {0} does not exist.", modelTempPath)); } if (!File.Exists(skinTempPath)) { throw new M2Exception(string.Format("Extract skin file {0} does not exist.", skinTempPath)); } M2File model = new M2File(modelTempPath, new M2SkinFile(skinTempPath)); model.parse(); Log.Write("ModelViewer: Loaded {0} M2 data.", model.Name); meshes.Add(model.ToMesh()); } catch (M2Exception ex) { Alert.Show(string.Format("Sorry, an error prevented {0} from being opened!", selectedFileName)); Log.Write("Unable to extract M2 file: " + ex.Message); Log.Write(ex.StackTrace); } CloseLoadingWindow(); } } }
public M2Animator(M2File file) { mHasAnimation = false; mAnimations = file.Animations; mAnimationLookup = file.AnimLookup; SetBoneData(file.Bones); SetUvData(file.UvAnimations); SetTexColorData(file.ColorAnimations); SetAlphaData(file.Transparencies); }
public M2SingleRenderer(M2File model) { mModel = model; if (model.NeedsPerInstanceAnimation) { mAnimationMatrices = new Matrix[model.GetNumberOfBones()]; mAnimator = ModelFactory.Instance.CreateAnimator(model); if (mAnimator.SetAnimation(AnimationType.Stand) == false) { mAnimator.SetAnimationByIndex(0); } } }
private void Dispose(bool disposing) { if (mInstanceBuffer != null) { var ib = mInstanceBuffer; WorldFrame.Instance.Dispatcher.BeginInvoke(() => { if (ib != null) { ib.Dispose(); } }); mInstanceBuffer = null; } Model = null; mActiveInstances = null; }
public M2Renderer(M2File model) { Model = model; VisibleInstances = new List <M2RenderInstance>(); if (!model.NeedsPerInstanceAnimation) { mAnimationMatrices = new Matrix[model.GetNumberOfBones()]; Animator = ModelFactory.Instance.CreateAnimator(model); if (Animator.SetAnimation(AnimationType.Stand) == false) { Animator.SetAnimationByIndex(0); } StaticAnimationThread.Instance.AddAnimator(Animator); } mBatchRenderer = new M2BatchRenderer(model); mSingleRenderer = new M2SingleRenderer(model); mPortraitRenderer = new M2PortraitRenderer(model); }
private void Dispose(bool disposing) { if (mAnimBuffer != null) { var ab = mAnimBuffer; WorldFrame.Instance.Dispatcher.BeginInvoke(() => { if (ab != null) { ab.Dispose(); } }); mAnimBuffer = null; } mModel = null; mAnimator = null; mAnimationMatrices = null; }
public M2RenderInstance(int uuid, Vector3 position, Vector3 rotation, Vector3 scale, M2Renderer renderer) { mScale = scale; mPosition = position; mRotation = rotation; NumReferences = 1; Uuid = uuid; mRenderer = renderer; mModel = mRenderer.Model; mBoundingBox = mModel.BoundingBox; var rotationMatrix = Matrix.RotationYawPitchRoll(MathUtil.DegreesToRadians(rotation.Y), MathUtil.DegreesToRadians(rotation.X), MathUtil.DegreesToRadians(rotation.Z)); Matrix.Invert(ref rotationMatrix, out mInverseRotation); mInstanceMatrix = rotationMatrix * Matrix.Scaling(scale) * Matrix.Translation(position); mBoundingBox = BoundingBox.Transform(ref mInstanceMatrix); Matrix.Invert(ref mInstanceMatrix, out mInverseMatrix); InstanceCorners = mModel.BoundingBox.GetCorners(); Vector3.TransformCoordinate(InstanceCorners, ref mInstanceMatrix, InstanceCorners); }
public M2AlphaAnimation(M2File file, ref AnimationBlock transBlock, BinaryReader reader) { mAlpha = new M2InterpolateAlpha16AnimationBlock(file, transBlock, reader, 1.0f); }
public M2BatchRenderer(M2File model) { Model = model; }
private void SetModelCameraParameters(M2File file) { var bboxMin = file.BoundingBox.Minimum.Z; var bboxMax = file.BoundingBox.Maximum.Z; WorldFrame.Instance.Dispatcher.BeginInvoke(() => { mCamera.SetParameters(new Vector3(file.BoundingRadius * 1.5f, 0, bboxMin + (bboxMax - bboxMin) / 2), new Vector3(0, 0, bboxMin + (bboxMax - bboxMin) / 2), Vector3.UnitZ, Vector3.UnitY); comboBox1.Items.Clear(); var values = Enum.GetValues(typeof(AnimationType)); if (file.AnimationLookup.Length > 0) //Animation Lookup { foreach (int anim in values) { if (anim >= file.AnimationLookup.Length) { continue; } if (file.AnimationLookup[anim] < 0) { continue; } comboBox1.Items.Add(new AnimationIndexEntry { AnimationIndex = anim, Name = Enum.GetName(typeof(AnimationType), anim) }); } } else if (file.AnimationIds.Length > 0) //Raw Animation Check { foreach (int anim in values) { if (Array.IndexOf(file.AnimationIds, (ushort)anim) == -1) { continue; } comboBox1.Items.Add(new AnimationIndexEntry { AnimationIndex = anim, Name = Enum.GetName(typeof(AnimationType), anim) }); } } if (comboBox1.Items.Count > 0) //Preset combobox and animator state { comboBox1.SelectedIndex = 0; mRenderer.PortraitRenderer.Animator.SetAnimation((AnimationType)((AnimationIndexEntry)comboBox1.Items[0]).AnimationIndex); } }); if (file.DisplayOptions.TextureVariationFiles.Count > 1) { nudVariation.ReadOnly = false; nudVariation.Maximum = file.DisplayOptions.TextureVariationFiles.Count; nudVariation.Value = file.DisplayOptions.TextureVariation + 1; nudVariation.Increment = 1; } else { nudVariation.Increment = 0; nudVariation.ReadOnly = true; } }
public M2UVAnimation(M2File file, ref M2TexAnim texAnim, BinaryReader reader) { mTranslation = new M2Vector3AnimationBlock(file, texAnim.translation, reader); mRotation = new M2InvQuaternion16AnimationBlock(file, texAnim.rotation, reader); mScaling = new M2Vector3AnimationBlock(file, texAnim.scaling, reader, Vector3.One); }
public M2TexColorAnimation(M2File file, ref M2ColorAnim colorAnim, BinaryReader reader) { mColor = new M2Vector3AnimationBlock(file, colorAnim.color, reader, Vector3.One); mAlpha = new M2NoInterpolateAlpha16AnimationBlock(file, colorAnim.alpha, reader, 1.0f); }