public MeshesDialog(Model model, Bone bone) { InitializeComponent(); this.model = model; this.bone = bone; //Populate meshesComboBox with available meshes foreach (Mesh mesh in model.Meshes) { if (!model.IsMeshAssigned(mesh, model.Children)) { meshesComboBox.Items.Add(mesh); } } if (meshesComboBox.Items.Count == 0) { meshesComboBox.Enabled = false; } //Populate meshesListBox with meshes assigned to bone foreach (Mesh mesh in bone.Meshes) { meshesListBox.Items.Add(mesh); } }
/// <summary> /// Construct a new mesh from an ASE GeomObject /// </summary> /// <param name="obj">ASE GeomObject to read from</param> public Mesh(ASE.GeomObject obj) { children = new List<Node>(); name = obj.name; color = Colors.Random(); polygon = new Polygon(); polygon.Material = null; //Vertices foreach (ASE.Vector3D v in obj.mesh.verticies) polygon.Vertices.Add(new Vertex(v.x, v.y, v.z)); //Normals foreach (ASE.Vector3D v in obj.mesh.vertexNormals) polygon.Normals.Add(new Vertex(v.x, v.y, v.z)); //Texture coordinates foreach (ASE.Vector3D uv in obj.mesh.textureCoordinates) polygon.UVs.Add(new UV(uv.x, uv.y)); //Faces foreach (ASE.Face face in obj.mesh.faces) { Face f = new Face(); foreach (int i in face.vertex) f.Indices.Add(new Index(i, -1, i)); f.Material = new Material(); polygon.Faces.Add(f); } setColor(); bone = null; }
/// <summary> /// Construct a new Mesh /// </summary> public Mesh() { children = new List<Node>(); name = ""; color = Colors.Random(); polygon = new Polygon(); bone = null; setColor(); }
private void addBone(Bone bone, TreeNode parent) { TreeNode node = new TreeNode(bone.Name); node.ImageKey = "bone"; node.SelectedImageKey = "bone"; node.Tag = bone; if (parent == null) this.Nodes.Add(node); else parent.Nodes.Add(node); //Add children foreach (Node child in bone.Children) { if (child is Bone) addBone((Bone)child, node); } }
private void rotate(OpenGL gl, Bone bone) { if (!(bone.Parent is Model)) { if (bone.Parent is Bone) { rotate(gl, (Bone)bone.Parent); } } RotateTransform rotation = new RotateTransform(); rotation.FocalPoint = bone.Position; rotation.Rotation = bone.Rotation; rotation.Rotate(gl); }
private void parentTranslation(OpenGL gl, Bone bone) { if (!(bone.Parent is Model)) { if (bone.Parent is Bone) { Bone parent = bone.Parent as Bone; parentTranslation(gl, parent); gl.Translate(parent.Translation.X, parent.Translation.Y, parent.Translation.Z); } } }
private void getSelectedMeshes(Bone bone) { string selectedMeshes = ""; if (bone.Meshes.Count > 0) { foreach (Mesh mesh in bone.Meshes) { selectedMeshes += mesh.Name + ", "; } selectedMeshes = selectedMeshes.Substring(0, selectedMeshes.Length - 2); } else { selectedMeshes = "(none)"; } meshesLabel.Text = selectedMeshes; }
private void getSelectedBone(Bone childBone) { parentComboBox.Items.Clear(); parentComboBox.Items.Add(Bone.Null); bool sel = false; //Add all bones not already parented to a bone and // the parent of this bone (if any) foreach (Bone modelBone in model.Bones) { if (modelBone != childBone) { parentComboBox.Items.Add(modelBone); if (childBone.Parent == modelBone) { sel = true; parentComboBox.SelectedIndex = parentComboBox.Items.Count - 1; } } } if (!sel) parentComboBox.SelectedIndex = 0; }
private Vertex parentTranslationDiff(Bone bone) { Vertex diff = new Vertex(0, 0, 0); if (!(bone.Parent is Model)) { if (bone.Parent is Bone) { Bone parent = bone.Parent as Bone; diff += parentTranslationDiff(parent); diff += parent.Translation; } } return diff; }
/// <summary> /// Calculates a given Bone's absolute position after being transformed. /// </summary> /// <param name="bone">The Bone to get the position for</param> /// <returns>The given Bone's absolute position after being transformed</returns> private Vertex getTransformedPosition(Bone bone) { Vertex translation = bone.Position; translation += Translation; Bone parent = null; if (!(bone.Parent is Model)) { if (bone.Parent is Bone) { parent = bone.Parent as Bone; } } if (parent != null) { translation += parentTranslationDiff(bone); translation = Helpers.VertexRotateTransform( translation, parent.TransformedPosition, parent.Rotation); } return translation; }