public void Add(TTriMesh use_mesh) { int normal_offset = normal.Length; int pos_offset = pos.Length; //int color_offset = color.Length; pos.Add(use_mesh.pos); normal.Add(use_mesh.normal); //scene.color.Add(use_mesh.color); int last_high = triangle.High; triangle.Add(use_mesh.triangle); for (int k = last_high + 1; k <= triangle.High; k++) { triangle[k] = new TMeshTri( triangle[k].p0 + pos_offset, triangle[k].p1 + pos_offset, triangle[k].p2 + pos_offset, triangle[k].n0 + normal_offset, triangle[k].n1 + normal_offset, triangle[k].n2 + normal_offset, 0, 0, 0);//TODO } }
public TTriMesh GetTransformedMesh() { TTriMesh trans_mesh = new TTriMesh(); if (mesh == null) { return(trans_mesh); } trans_mesh.pos.High = mesh.pos.High; for (int i = 0; i <= mesh.pos.High; i++) { Vector3 t = mesh.pos[i]; t.TransformCoordinate(orient); trans_mesh.pos[i] = t; } trans_mesh.normal.High = mesh.normal.High; for (int i = 0; i <= mesh.normal.High; i++) { Vector3 t = mesh.normal[i]; t.TransformNormal(orient); trans_mesh.normal[i] = t; } trans_mesh.triangle.Add(mesh.triangle); return(trans_mesh); }
private void Draw() { if (detail.Update()) { propertyGrid1.Refresh(); } render.BeginScene(); // DrawBackground(); render.State.CullFace(true); render.Lighting.Enable(true); render.Lighting.LightDir(cam.GetDir()); //render.Lighting.Material(Color.Tomato, Color.Turquoise, 10); TTriMesh scene = detail.GetTransformedMesh();// engine.GetScene(); CustomVertex.PositionNormal[] render_data = scene.GetRenderData(); render.Draw.Triangles(render_data); if (this.toolStripButton2.Checked) { render.Lighting.Material(Color.Black, Color.Black, 0); render.State.DepthBias(true); render.State.FillModeWireFrame(); render.Draw.Triangles(render_data); render.State.FillModeSolid(); render.State.DepthBias(false); } render.Lighting.Enable(false); render.State.CullFace(false); render.ClearDepth(); editor.DrawAxis(this.toolStripComboBox1.SelectedIndex == 1, toolStripButton1.Checked); //TRay cursor_world = render.FromScreenToWorld(Cursor.Position); render.Transform.Ortho(); render.State.DepthTest(false); render.Draw.Text(String.Format("Tri count: {0}", render_data.Length / 3), new System.Drawing.Point(10, 30)); ////Geometry.TAABB test_box = new Geometry.TAABB(new Vector3(0, 0, 0), new Vector3(0.5f, 0.5f, 0.5f)); ////if (test_box.Overlaps(cursor_world)) //// render.Draw.Text("inters", new System.Drawing.Point(10, 30)); //CustomVertex.PositionColored[] points = new CustomVertex.PositionColored[1]; //points[0].Position = cursor_world.pos + cursor_world.dir; //points[0].Color = System.Drawing.Color.FromArgb(1, 0, 0, 0).ToArgb(); render.Transform.Projection(); render.Transform.ViewByCam(cam); //render.State.PointSize(10); //render.Draw.Points(points); render.State.DepthTest(true); render.EndScene(); }
public TTriMesh GetCopy() //создает глубокую копию { TTriMesh result = new TTriMesh(); result.pos.Add(pos); result.normal.Add(normal); result.triangle.Add(triangle); //result.tri_aabb.Add(tri_aabb); //result.aabb=aabb; //result.average_tri_size=average_tri_size; return(result); }
public void RebuildGeometry() { //need_props_refresh = true;//TODO если обновлять окно свойст здесь, то почему-то не происходит перерисовка моделей int last_high = -1, normal_offset = 0, pos_offset = 0, color_offset = 0; if (objects.Count < 1) { return; } TTriMeshWithTree[] meshes = new TTriMeshWithTree[objects.Count]; TTriMesh[] not_cutted_meshes = new TTriMesh[meshes.Length]; float node_size = 0; TVector <int> buffer = new TVector <int>(1000); TAABB scene_box = new TAABB(); for (int i = 0; i < meshes.Length; i++) { not_cutted_meshes[i] = objects[i].GetTransformedMesh(); meshes[i] = new TTriMeshWithTree(not_cutted_meshes[i].GetCopy()); node_size += meshes[i].GetAverageTriSize(); if (i == 0) { scene_box = meshes[i].GetAABB(); } else { scene_box.Extend(meshes[i].GetAABB()); } } node_size /= meshes.Length; scene = new TTriMeshWithTree(node_size * 2, scene_box); TVector <int> query_result = new TVector <int>(1000); TVector <int> query_result1 = new TVector <int>(1000); for (int i = 0; i < meshes.Length; i++) { if (i != 0) { //сечём треугольники объекта треугольниками сцены scene.AABBQuery(query_result, meshes[i].GetAABB()); for (int k = 0; k <= query_result.High; k++) { meshes[i].Cut(buffer, scene.GetMesh(), query_result[k], scene.GetMesh().GetTriAABB(query_result[k])); } //сечём треугольники сцены треугольниками объекта(треугольники объекта не сечённые) for (int k = 0; k <= not_cutted_meshes[i].triangle.High; k++) { scene.Cut(buffer, not_cutted_meshes[i], k, not_cutted_meshes[i].GetTriAABB(k)); } scene.TrianglesInMeshQuery(buffer, query_result, meshes[i], true); meshes[i].TrianglesInMeshQuery(buffer, query_result1, scene, false); scene.DelTriangles(query_result); meshes[i].DelTriangles(query_result1); meshes[i].InverseNormals(); } //добавляем объект в сцену scene.Add(meshes[i]); } }