private static Model3DGroup CreateAxisAndArrowHead(RotateTransform3D rotateTransform, TranslateTransform3D translateTransform, Material material) { Model3DGroup model3Dgroup = new Model3DGroup(); Model3DCollection model3Dcollection = new Model3DCollection(); model3Dgroup.Children = model3Dcollection; Model3DGroup cylinder = Cylinder.CreateCylinder(0.02, 0.5, 12, material, material, (Material)null); if (rotateTransform != null) { cylinder.Transform = (Transform3D)rotateTransform; } model3Dgroup.Children.Add((Model3D)cylinder); Model3DGroup cone = Cone.CreateCone(0.04, 0.1, 12, material, material); if (rotateTransform != null) { cone.Transform = (Transform3D) new Transform3DGroup() { Children = { (Transform3D)rotateTransform, (Transform3D)translateTransform } } } ; else { cone.Transform = (Transform3D)translateTransform; } model3Dgroup.Children.Add((Model3D)cone); model3Dgroup.Freeze(); return(model3Dgroup); }
public void WordTo2DTree(string word, Vector3 pos, Quaternion rotation, float offset) { //Debug.Log(word); Vector3 pivot = pos; Stack <Vector3> vectors_stack = new Stack <Vector3>(); Stack <float> angles_stack = new Stack <float>(); float angle = 0; int i = 0; foreach (char c in word) { //Debug.Log("i : " + i + ", pivot : " + pivot); if (c == 'F') { Cylinder cylinder = new Cylinder(pivot, base_radius, trunck_height, deltaAngle); cylinder.CreateCylinder(); DrawMesh(i + "_mesh", cylinder.vertices, cylinder.uvs, cylinder.triangles, rotation * Quaternion.Euler(0, 0, angle), pivot); pivot += rotation * Quaternion.Euler(0, 0, angle) * new Vector3(0, trunck_height, 0); ++i; } else if (c == 'A') { //Debug.Log("OOOOOK"); Instantiate(leaf, pivot, Quaternion.Euler(0, 0, angle)); pivot += rotation * Quaternion.Euler(0, 0, angle) * new Vector3(pivot.x, trunck_height, pivot.z); ++i; } else if (c == 'B') { //Debug.Log("OK"); Cylinder cylinder = new Cylinder(pivot, base_radius, trunck_height * 1.5f, deltaAngle); cylinder.CreateCylinder(); DrawMesh(i + "_mesh", cylinder.vertices, cylinder.uvs, cylinder.triangles, rotation * Quaternion.Euler(0, 0, angle), pivot); pivot += rotation * Quaternion.Euler(0, 0, angle) * new Vector3(0, trunck_height * 1.5f, 0); ++i; } else if (c == '[') { vectors_stack.Push(pivot); angles_stack.Push(angle); } else if (c == ']') { pivot = vectors_stack.Pop(); angle = angles_stack.Pop(); } else if (c == '+') { angle += base_angle; } else if (c == '-') { angle += -base_angle; } } }
public void WordTo3DTree(string word, Vector3 pos) { //Debug.Log(word); Vector3 pivot = pos; Stack <Vector3> vectors_stack = new Stack <Vector3>(); Stack <Vector3> angles_stack = new Stack <Vector3>(); float u_angle = 0; float h_angle = 0; float l_angle = 0; int i = 0; foreach (char c in word) { //Debug.Log("i : " + i + ", pivot : " + pivot); if (c == 'F') { Cylinder cylinder = new Cylinder(pivot, base_radius, trunck_height, deltaAngle); cylinder.CreateCylinder(); DrawMesh(i + "_mesh", cylinder.vertices, cylinder.uvs, cylinder.triangles, Quaternion.Euler(l_angle, u_angle, h_angle), pivot); pivot += Quaternion.Euler(l_angle, u_angle, h_angle) * new Vector3(pivot.x, trunck_height, pivot.z); ++i; } else if (c == 'B') { //Debug.Log("OK"); Cylinder cylinder = new Cylinder(pivot, base_radius, trunck_height * 1.5f, deltaAngle); cylinder.CreateCylinder(); DrawMesh(i + "_mesh", cylinder.vertices, cylinder.uvs, cylinder.triangles, Quaternion.Euler(l_angle, u_angle, h_angle), pivot); pivot += Quaternion.Euler(l_angle, u_angle, h_angle) * new Vector3(pivot.x, trunck_height, pivot.z); ++i; } else if (c == 'A') { Instantiate(leaf, pivot, Quaternion.Euler(l_angle, u_angle, h_angle)); pivot += Quaternion.Euler(l_angle, u_angle, h_angle) * new Vector3(pivot.x, trunck_height, pivot.z); ++i; } else if (c == 'S') { //Debug.Log("OK"); Cylinder cylinder = new Cylinder(pivot, base_radius, trunck_height * 0.5f, deltaAngle); cylinder.CreateCylinder(); DrawMesh(i + "_mesh", cylinder.vertices, cylinder.uvs, cylinder.triangles, Quaternion.Euler(l_angle, u_angle, h_angle), pivot); pivot += Quaternion.Euler(l_angle, u_angle, h_angle) * new Vector3(pivot.x, trunck_height, pivot.z); ++i; } else if (c == '[') { vectors_stack.Push(pivot); angles_stack.Push(new Vector3(l_angle, u_angle, h_angle)); } else if (c == ']') { pivot = vectors_stack.Pop(); Vector3 angles = angles_stack.Pop(); l_angle = angles.x; u_angle = angles.y; h_angle = angles.z; } else if (c == '+') { u_angle += base_angle; } else if (c == '-') { u_angle += -base_angle; } else if (c == '&') { l_angle += base_angle; } else if (c == '^') { l_angle -= base_angle; } else if (c == '\\') { h_angle += base_angle; } else if (c == '/') { h_angle -= base_angle; } else if (c == '|') { u_angle += 180; } } }
public GameObject WordTo2DTree(string word, Vector3 pos, Tree tree, string name, Quaternion q) { float yMin, yMax, xMin, xMax; //y for height, x for width //Debug.Log(word); Vector3 pivot = pos; Vector3 old_pivot = Vector3.zero; yMin = yMax = pos.y; xMin = xMax = pos.x; bool isBranch = false; Stack <Vector3> vectors_stack = new Stack <Vector3>(); Stack <float> angles_stack = new Stack <float>(); float angle = 0; int i = 0; GameObject treeGo = new GameObject(name); foreach (char c in word) { float tmp_trunc_len = 0; //Debug.Log("i : " + i + ", pivot : " + pivot); if (c == 'F') { isBranch = true; Cylinder cylinder = new Cylinder(pivot, tree.trunc_radius, tree.trunc_height, tree.delta_angle); cylinder.CreateCylinder(); DrawMesh(i + "_mesh", treeGo, cylinder.vertices, cylinder.uvs, cylinder.triangles, q * Quaternion.Euler(0, 0, angle), pivot); old_pivot = pivot; pivot += q * Quaternion.Euler(0, 0, angle) * new Vector3(0, tree.trunc_height, 0); tmp_trunc_len = tree.trunc_height; //Debug.Log("tmp_len : " + tmp_trunc_len); ++i; } else if (c == 'A') { GameObject _leaf = Instantiate(leaf, pivot, Quaternion.Euler(0, 0, angle)); _leaf.transform.SetParent(treeGo.transform); pivot += q * Quaternion.Euler(0, 0, angle) * new Vector3(pivot.x, tree.trunc_height, pivot.z); ++i; } else if (c == 'B') { //Debug.Log("OK"); isBranch = true; Cylinder cylinder = new Cylinder(pivot, tree.trunc_radius, tree.trunc_height * 1.5f, tree.delta_angle); cylinder.CreateCylinder(); DrawMesh(i + "_mesh", treeGo, cylinder.vertices, cylinder.uvs, cylinder.triangles, q * Quaternion.Euler(0, 0, angle), pivot); old_pivot = pivot; pivot += q * Quaternion.Euler(0, 0, angle) * new Vector3(0, tree.trunc_height * 1.5f, 0); tmp_trunc_len = tree.trunc_height * 1.5f; ++i; } else if (c == '[') { vectors_stack.Push(pivot); angles_stack.Push(angle); } else if (c == ']') { pivot = vectors_stack.Pop(); angle = angles_stack.Pop(); } else if (c == '+') { angle += tree.delta_angle; } else if (c == '-') { angle += -tree.delta_angle; } if (isBranch) { float tmp_y = (Mathf.Cos(angle * Mathf.PI / 180) * tmp_trunc_len) + old_pivot.y; float tmp_x = (Mathf.Sin(angle * Mathf.PI / 180) * tmp_trunc_len) + old_pivot.x; old_pivot = pivot; if (tmp_y < yMin) { yMin = tmp_y; } if (tmp_y > yMax) { yMax = tmp_y; } if (tmp_x < xMin) { xMin = tmp_x; } if (tmp_x > xMax) { xMax = tmp_x; } } isBranch = false; } tree.height = Mathf.Abs(yMax - yMin); tree.radius = Mathf.Abs(xMax - xMin); //Debug.Log("Tree height : " + tree.height); //Debug.Log("Tree width : " + tree.radius); return(treeGo); }