public void Draw(GraphicsDeviceManager gcm, BasicEffect be, RasterizerState rs) { this.UpdateSkinCondition(); this.ComputeMatricesWithChanges(); for (int mesh = 0; mesh < this.Triangle.Count; mesh++) { int ind = this.Triangle[mesh].Count - 1; for (int triInd = 0; triInd < this.Triangle[mesh].Count; triInd += 3) { for (int k = 0; k < 3; k++) { VertexPositionColorTexture vpt = new VertexPositionColorTexture(); vpt.Position = GetTriangleVertex(mesh, triInd + k); var infsV = GetInfluences(mesh, triInd + k); var infs = GetMatrices(mesh, triInd + k); Vector3 final = Vector3.Zero; for (int l = 0; l < infs.Count; l++) { Matrix mat = this.Skeleton.BonesMatrices[infs[l]]; float inf = infsV[l]; Vector3 v3 = Vector3.Transform(vpt.Position, Matrix.Invert(mat)); v3 = Vector3.Transform(v3, this.Skeleton.BonesReMatrices[infs[l]]); final.X += v3.X * inf; final.Y += v3.Y * inf; final.Z += v3.Z * inf; } vpt.Position = final; vpt.TextureCoordinate = GetTriangleUv(mesh, triInd + k); vpt.Color = GetTriangleColor(mesh, triInd + k); vpt.Position += this.Position; this.RenderBuffer[mesh][ind] = vpt; ind--; } //ApplyTransformations } gcm.GraphicsDevice.DepthStencilState = DepthStencilState.Default; if (be != null) { be.TextureEnabled = true; be.Texture = SrkBinary.GetT2D(this.materialFileNames[this.MaterialIndices[mesh]]); be.CurrentTechnique.Passes[0].Apply(); } if (rs != null) { gcm.GraphicsDevice.RasterizerState = rs; } gcm.GraphicsDevice.DrawUserPrimitives(PrimitiveType.TriangleList, this.RenderBuffer[mesh], 0, this.Triangle[mesh].Count / 3); } this.Skeleton.GetGraphic(); this.Skeleton.Draw(gcm, be, rs); }
public void Draw(GraphicsDeviceManager gcm, BasicEffect be, RasterizerState rs) { for (int mesh = 0; mesh < this.Triangle.Count; mesh++) { int ind = this.Triangle[mesh].Count - 1; //Object3D.orderZindex for (int triInd = 0; triInd < this.Triangle[mesh].Count; triInd += 3) { for (int k = 0; k < 3; k++) { VertexPositionColorTexture vpt = new VertexPositionColorTexture(); vpt.Position = GetTriangleVertex(mesh, triInd + k); vpt.TextureCoordinate = GetTriangleUv(mesh, triInd + k); vpt.Color = Microsoft.Xna.Framework.Color.White; vpt.Position += this.Position; RenderBuffer[mesh][ind] = vpt; ind--; } } if (be != null) { be.TextureEnabled = true; be.Texture = SrkBinary.GetT2D(this.materialFileNames[this.MaterialIndices[mesh]]); be.CurrentTechnique.Passes[0].Apply(); } if (rs != null) { gcm.GraphicsDevice.RasterizerState = rs; } if (RenderBuffer.Length > 0) { gcm.GraphicsDevice.DepthStencilState = DepthStencilState.Default; gcm.GraphicsDevice.DrawUserPrimitives(PrimitiveType.TriangleList, RenderBuffer[mesh], 0, RenderBuffer[mesh].Length / 3); } } //this.Skeleton.GetGraphic(); //this.Skeleton.Draw(gcm, be, rs); }
public void Draw(GraphicsDeviceManager gcm, BasicEffect be, RasterizerState rs) { //this.SkeletonCache.ValidateSelectionCache(gcm); UpdateControls(); Vector3 position = View.mainCamera.GlobalPosition(); double hypo = 1; float diffX = 0; float diffY = 0; float diffZ = 0; VertexPositionColorTexture[] toDraw; gcm.GraphicsDevice.DepthStencilState = DepthStencilState.None; float diffWithZoom = Vector3.Distance(position, View.focusedObject.Position + View.focusedObject.MiddleCoord) / (View.focusedObject.Zoom * 1.5f); if (this.ShowIndices && diffWithZoom < 1) { if (this.bonesTexture.Length > 0 /*&&MainViewer.form.skeletonIndCheckBox.Enabled && MainViewer.form.skeletonIndCheckBox.Checked && * (!MainViewer.form.swapCheckBox.Checked||objet.MeshCount==0)*/) { toDraw = new VertexPositionColorTexture[this.bonesTexture.Length]; Vector3 bonePos = Vector3.Zero; for (int j = 0; j < toDraw.Length; j++) { if (j % 24 == 0) { bonePos = Vector3.Transform(Vector3.Zero, this.BonesReMatrices[j / 24]); diffX = position.X - (bonePos.X + objet.Position.X); diffY = position.Y - (bonePos.Y + objet.Position.Y); diffZ = position.Z - (bonePos.Z + objet.Position.Z); hypo = Math.Pow(diffX * diffX + diffY * diffY + diffZ * diffZ, 0.5f); } toDraw[j] = this.bonesTexture[j]; //if (MainViewer.form.rotateIndCheckBox.Enabled && MainViewer.form.rotateIndCheckBox.Checked) toDraw[j].Position = Vector3.Transform(toDraw[j].Position, Matrix.CreateFromYawPitchRoll(View.mainCamera.Yaw, View.mainCamera.Pitch, 0)); //if (!MainViewer.form.scaleIndCheckBox.Enabled || MainViewer.form.scaleIndCheckBox.Checked) toDraw[j].Position = Vector3.Transform(toDraw[j].Position, Matrix.CreateScale((float)hypo / 80f)); //else //toDraw[j].Position = Vector3.Transform(toDraw[j].Position, Matrix.CreateScale(objet.Zoom / 1000f)); toDraw[j].Position += bonePos; toDraw[j].Position += objet.Position; if (j % 24 == 23 && this.selectedBone == j / 24) { for (int k = 6; k < 24; k++) { toDraw[j - 23 + k].Color.R = 255; toDraw[j - 23 + k].Color.G = 0; toDraw[j - 23 + k].Color.B = 0; } } toDraw[j].Color.A = (byte)(255 - diffWithZoom * 255); } if (be != null) { be.TextureEnabled = true; be.Texture = SrkBinary.GetT2D(View.GetCurrentDirectory() + @"\Content\boneTexture.png"); be.CurrentTechnique.Passes[0].Apply(); } if (rs != null) { gcm.GraphicsDevice.RasterizerState = rs; } gcm.GraphicsDevice.DrawUserPrimitives(PrimitiveType.TriangleList, toDraw, 0, toDraw.Length / 3); } } if (this.bonesTextureCircles.Length > 0 /*&&MainViewer.form.skeletonCheckBox.Checked*/) { toDraw = new VertexPositionColorTexture[this.bonesTextureCircles.Length]; Vector3 bonePos = Vector3.Zero; for (int j = 0; j < toDraw.Length; j++) { if (j % 6 == 0) { bonePos = Vector3.Transform(Vector3.Zero, this.BonesReMatrices[j / 6]); diffX = position.X - (bonePos.X + objet.Position.X); diffY = position.Y - (bonePos.Y + objet.Position.Y); diffZ = position.Z - (bonePos.Z + objet.Position.Z); hypo = Math.Pow(diffX * diffX + diffY * diffY + diffZ * diffZ, 0.5f); } toDraw[j] = this.bonesTextureCircles[j]; toDraw[j].Position = Vector3.Transform(toDraw[j].Position, Matrix.CreateFromYawPitchRoll(View.mainCamera.Yaw, View.mainCamera.Pitch, 0)); //if (!MainViewer.form.scaleIndCheckBox.Enabled||MainViewer.form.scaleIndCheckBox.Checked) toDraw[j].Position = Vector3.Transform(toDraw[j].Position, Matrix.CreateScale(((float)hypo / 60f))); //else //toDraw[j].Position = Vector3.Transform(toDraw[j].Position, Matrix.CreateScale((objet.Zoom / 1000f) / 1)); toDraw[j].Position += bonePos; if (this.HighlightedBone && j / 6 == this.HighlightedBoneParentID) { toDraw[j].TextureCoordinate.X += (192f / 382f); toDraw[j].Color = HighligthedColor; } else if (this.Bones[j / 6].Selected) { if (this.Bones[j / 6].ParentID < 0 || !this.Bones[this.Bones[j / 6].ParentID].Selected) { toDraw[j].TextureCoordinate.X += (192f / 382f); } toDraw[j].Color = SelectedColor; } else { toDraw[j].Color = UnselectedColor; } toDraw[j].Position += objet.Position; } if (be != null) { be.TextureEnabled = true; be.Texture = SrkBinary.GetT2D(View.GetCurrentDirectory() + @"\Content\boneTexture.png"); be.CurrentTechnique.Passes[0].Apply(); } if (rs != null) { gcm.GraphicsDevice.RasterizerState = rs; } gcm.GraphicsDevice.DrawUserPrimitives(PrimitiveType.TriangleList, toDraw, 0, toDraw.Length / 3); VertexPositionColorTexture[] toDrawLines = new VertexPositionColorTexture[this.bonesTextureLinesLength]; if (this.bonesTextureLinesLength > 0) { for (int i = 0; i < toDrawLines.Length; i++) { toDrawLines[i] = this.bonesTextureLines[i]; toDrawLines[i].Position += objet.Position; } gcm.GraphicsDevice.DrawUserPrimitives(PrimitiveType.LineList, toDrawLines, 0, toDrawLines.Length / 2); } } }