private void CreateSearchNodes() { // "flat" structure root = new SymbolNode("Test template", "", "testTemplace.zzz", 0, 0, SymbolNode.LibraryNodeType.Hierarchy); namespaceNode = new NamespaceNode("ClassLibrary1", "", "Class1.cs", 7, 0); classNode = new ModelNode("Class1", "ClassLibrary1.", "Class1.cs", 7, 17); memberNode = new MemberNode("GetBlaBlaBla", "ClassLibrary1.Class1.", "Class1.cs", 9, 22); ModelReferenceList classReferenceNode = new ModelReferenceList( @"C:\Users\sivanov\Documents\Visual Studio 2010\Projects\ClassLibrary1\ClassLibrary1\Class1.cs - (8, 18) : public class Class1(NDjango symbol)", @"C:\Users\sivanov\Documents\Visual Studio 2010\Projects\ClassLibrary1\ClassLibrary1\Class1.cs", "", 8, 18), classReferenceNode1 = new ModelReferenceList( @"C:\Users\sivanov\Documents\Visual Studio 2010\Projects\ClassLibrary1\ClassLibrary1\Class2.cs - (7, 13) : Class1 c1 = new Class1();(NDjango symbol)", @"C:\Users\sivanov\Documents\Visual Studio 2010\Projects\ClassLibrary1\ClassLibrary1\Class2.cs", "", 7, 13); classNode.AddChild(classReferenceNode); classNode.AddChild(classReferenceNode1); MemberReferenceList methodReferenceNode = new MemberReferenceList( @"C:\Users\sivanov\Documents\Visual Studio 2010\Projects\ClassLibrary1\ClassLibrary1\Class1.cs - (10, 23) : public Class1 GetBlaBlaBla()(NDjango symbol)", @"C:\Users\sivanov\Documents\Visual Studio 2010\Projects\ClassLibrary1\ClassLibrary1\Class1.cs", "", 10, 23), methodReferenceNode1 = new MemberReferenceList( @"C:\Users\sivanov\Documents\Visual Studio 2010\Projects\ClassLibrary1\ClassLibrary1\Class1.cs - (0, 0) : public Class1 GetBlaBlaBla()(NDjango symbol)", @"C:\Users\sivanov\Documents\Visual Studio 2010\Projects\ClassLibrary1\ClassLibrary1\Class1.cs", "", 0, 0), methodReferenceNode2 = new MemberReferenceList( @"C:\Users\sivanov\Documents\Visual Studio 2010\Projects\ClassLibrary1\ClassLibrary1\Class1.cs - (0, 0) : public Class1 GetBlaBlaBla()(NDjango symbol)", @"C:\Users\sivanov\Documents\Visual Studio 2010\Projects\ClassLibrary1\ClassLibrary1\Class1.cs", "", 0, 0); memberNode.AddChild(methodReferenceNode); memberNode.AddChild(methodReferenceNode1); memberNode.AddChild(methodReferenceNode2); NamespaceReferenceList nsl1 = new NamespaceReferenceList( @"C:\Users\sivanov\Documents\Visual Studio 2010\Projects\ClassLibrary1\ClassLibrary1\Class1.cs - (2, 2) (NDjango symbol)", @"C:\Users\sivanov\Documents\Visual Studio 2010\Projects\ClassLibrary1\ClassLibrary1\Class1.cs", "", 0, 0), nsl2 = new NamespaceReferenceList( @"C:\Users\sivanov\Documents\Visual Studio 2010\Projects\ClassLibrary1\ClassLibrary1\Class2.cs - (3, 3) (NDjango symbol)", @"C:\Users\sivanov\Documents\Visual Studio 2010\Projects\ClassLibrary1\ClassLibrary1\Class2.cs", "", 0, 0); namespaceNode.AddChild(nsl1); namespaceNode.AddChild(nsl2); root.AddChild(memberNode); root.AddChild(classNode); root.AddChild(namespaceNode); }
private void CreateBuffers(Node assimpnode, ModelNode parent_node, ref Matrix4x4 model_matrix) { // create new mesh ModelNode node = new ModelNode(_openGLFactory); if (parent_node != null) { parent_node.AddChild(node); } else { _model._root_node = node; } // set model matrix Matrix4x4 mm = assimpnode.Transform; node.ModelMatrix = new Matrix4( mm.A1, mm.A2, mm.A3, mm.A4, mm.B1, mm.B2, mm.B3, mm.B4, mm.C1, mm.C2, mm.C3, mm.C4, mm.D1, mm.D2, mm.D3, mm.D4); // combined model matrix Matrix4x4 prev_model = model_matrix; Matrix4x4 new_transform = assimpnode.Transform; model_matrix = new_transform * model_matrix; // ? has this to be reversed link in OpneTK? if (assimpnode.HasMeshes) { foreach (int index in assimpnode.MeshIndices) { Assimp.Mesh assimpmesh = _assimpmodel.Meshes[index]; AABB mesh_box = new AABB(); // extend bounding box by vertices for (int i = 0; i < assimpmesh.VertexCount; i++) { Vector3D tmp = assimpmesh.Vertices[i]; mesh_box = mesh_box | new Vector3(tmp.X, tmp.Y, tmp.Z); tmp = model_matrix * tmp; _model._scene_box = _model._scene_box | new Vector3(tmp.X, tmp.Y, tmp.Z); } // create Mesh uint tuple_index = 0; List <TVertexFormat> formalist = new List <TVertexFormat>(); OpenTK_library.Scene.Mesh mesh = new OpenTK_library.Scene.Mesh(); mesh.Box = mesh_box; node.Add(mesh); // specify vertices mesh.VertexAttribute = (tuple_index, 3); formalist.Add(new TVertexFormat(0, vertex_index, 3, (int)tuple_index, false)); tuple_index += 3; // specify normals if (assimpmesh.HasNormals) { mesh.NormalAttribute = (tuple_index, 3); formalist.Add(new TVertexFormat(0, normal_index, 3, (int)tuple_index, false)); tuple_index += 3; } // specify bi-normals and tangents if (assimpmesh.HasTangentBasis) { mesh.BinormalAttribute = (tuple_index, 3); formalist.Add(new TVertexFormat(0, binormal_index, 3, (int)tuple_index, false)); tuple_index += 3; mesh.TangentAttribute = (tuple_index, 3); formalist.Add(new TVertexFormat(0, tangent_index, 3, (int)tuple_index, false)); tuple_index += 3; } // specify texture channels for (int textur_channel = 0; assimpmesh.HasTextureCoords(textur_channel); ++textur_channel) { mesh.AddTextureAttrib((tuple_index, 3)); int attr_i = textur_channel == 0 ? texture0_index : (textureN_index + textur_channel - 1); formalist.Add(new TVertexFormat(0, attr_i, 3, (int)tuple_index, false)); tuple_index += 3; } // specify color channels for (int color_channel = 0; assimpmesh.HasVertexColors(color_channel); ++color_channel) { mesh.AddColorAttrib((tuple_index, 4)); int attr_i = color_channel == 0 ? color0_index : (colorN_index + color_channel - 1); formalist.Add(new TVertexFormat(0, attr_i, 4, (int)tuple_index, false)); tuple_index += 4; } // TODO $$$ bones if (assimpmesh.HasBones) { // [...] Console.WriteLine("bones not yet implemented"); } // set tuple size mesh.TupleSize = tuple_index; // setup index buffer List <float> attributes = new List <float>(); List <uint> indices = new List <uint>(); uint elem_index = 0; foreach (Face face in assimpmesh.Faces) { if (face.IndexCount < 3) { continue; // lines? } for (uint i = 2; i < (uint)face.IndexCount; i++) { indices.Add(elem_index); indices.Add(elem_index + 1); indices.Add(elem_index + i); } elem_index += (uint)face.IndexCount; for (int i = 0; i < face.IndexCount; i++) { int ei = face.Indices[i]; // add vertex attribute var vertex = assimpmesh.Vertices[ei]; attributes.Add(vertex.X); attributes.Add(vertex.Y); attributes.Add(vertex.Z); // add normals if (assimpmesh.HasNormals) { var normal = assimpmesh.Normals[ei]; attributes.Add(normal.X); attributes.Add(normal.Y); attributes.Add(normal.Z); } // add bi-normals and tangents if (assimpmesh.HasTangentBasis) { var binormal = assimpmesh.BiTangents[ei]; attributes.Add(binormal.X); attributes.Add(binormal.Y); attributes.Add(binormal.Z); var tangent = assimpmesh.Tangents[ei]; attributes.Add(tangent.X); attributes.Add(tangent.Y); attributes.Add(tangent.Z); } // add texture coordinates for (int textur_channel = 0; assimpmesh.HasTextureCoords(textur_channel); ++textur_channel) { var uvw = assimpmesh.TextureCoordinateChannels[textur_channel][ei]; attributes.Add(uvw.X); attributes.Add(uvw.Y); attributes.Add(uvw.Z); } // add color attributes for (int color_channel = 0; assimpmesh.HasVertexColors(color_channel); ++color_channel) { var vertColor = assimpmesh.VertexColorChannels[color_channel][ei]; attributes.Add(vertColor.R); attributes.Add(vertColor.G); attributes.Add(vertColor.B); attributes.Add(vertColor.A); } } } // setup vertex arrays and index array TVertexFormat[] format = formalist.ToArray(); var vao = _openGLFactory.NewVertexArrayObject(); vao.AppendVertexBuffer(0, (int)tuple_index, attributes.ToArray()); vao.Create(format, indices.ToArray()); mesh.FaceSize = 3; mesh.VertexArray = vao; } } for (int i = 0; i < assimpnode.ChildCount; i++) { CreateBuffers(assimpnode.Children[i], node, ref model_matrix); } model_matrix = prev_model; }
public void Initialize() { /// :CodeSample: Model Model.AddNode Model.FindNode ModelNode.AddChild /// ### Assembling a Model /// While normally you'll load Models from file, you can also assemble /// them yourself procedurally! This example shows assembling a simple /// hierarchy of visual and empty nodes. Model model = new Model(); model .AddNode("Root", Matrix.S(0.2f), Mesh.Cube, Material.Default) .AddChild("Sub", Matrix.TR(V.XYZ(0.5f, 0, 0), Quat.FromAngles(0, 0, 45)), Mesh.Cube, Material.Default) .AddChild("Surface", Matrix.TRS(V.XYZ(0.5f, 0, 0), Quat.LookDir(V.XYZ(1, 0, 0)), V.XYZ(1, 1, 1))); ModelNode surfaceNode = model.FindNode("Surface"); surfaceNode.AddChild("UnitX", Matrix.T(Vec3.UnitX)); surfaceNode.AddChild("UnitY", Matrix.T(Vec3.UnitY)); surfaceNode.AddChild("UnitZ", Matrix.T(Vec3.UnitZ)); /// :End: Tests.Test(() => model.FindNode("NotPresent") == null); /// :CodeSample: Model Model.Nodes /// ### Simple iteration /// Walking through the Model's list of nodes is pretty /// straightforward! This will touch every ModelNode in the Model, /// in the order they were defined, regardless of hierarchy position /// or contents. Log.Info("Iterate nodes:"); foreach (ModelNode node in model.Nodes) { Log.Info(" " + node.Name); } /// :End: /// :CodeSample: Model Model.Visuals /// ### Simple iteration of visual nodes /// This will iterate through every ModelNode in the Model with visual /// data attached to it! Log.Info("Iterate visuals:"); foreach (ModelNode node in model.Visuals) { Log.Info(" " + node.Name); } /// :End: /// :CodeSample: Model Model.Visuals Model.Nodes /// ### Tagged Nodes /// You can search through Visuals and Nodes var nodes = model.Visuals .Where(n => n.Name.StartsWith("[Wire]")); foreach (var node in nodes) { node.Material = node.Material.Copy(); node.Material.Wireframe = true; } /// :End: Log.Info("Recursive ModelNode traversal:"); RecursiveTraversal(model.RootNode); Log.Info("Depth first ModelNode traversal:"); DepthFirstTraversal(model); for (int i = 0; i < model.Nodes.Count; i++) { Log.Info($"{model.Nodes[i].Name} using shader {model.Nodes[i].Material?.Shader.Name}"); } _model = model; _surfaceNode = surfaceNode; }