public static byte[] ToGlb(this FeatureCollection fc, string classifyField, double longitude, double latitude, Color fromColor, Color toColor, int numberOfClasses, int Maximum) { var colors = ColorRange.GetGradients(fromColor, toColor, numberOfClasses).ToList(); var center_coordinate = new GeoCoordinate(latitude, longitude);; var mesh = VPOSNRM.CreateCompatibleMesh("shape"); foreach (var f in fc.Features) { var z = Convert.ToDouble(f.Properties["z"]); var amount = Convert.ToInt32(f.Properties[classifyField]); var point = (GeoJSON.Net.Geometry.Point)f.Geometry; var coords = point.Coordinates; var distance_latitude = new GeoCoordinate(coords.Latitude, longitude).GetDistanceTo(center_coordinate); distance_latitude = coords.Latitude < center_coordinate.Latitude ? distance_latitude * -1 : distance_latitude; var distance_longitude = new GeoCoordinate(latitude, coords.Longitude).GetDistanceTo(center_coordinate); distance_longitude = coords.Longitude < center_coordinate.Longitude ? distance_longitude * -1 : distance_longitude; var color_index = (int)Math.Round((double)(amount * colors.Count / Maximum)); var rgb = colors[color_index]; var material = MaterialCreator.CreateMaterial(rgb.R, rgb.G, rgb.B); var translate = Matrix4x4.CreateTranslation((float)distance_longitude, (float)z * 2, (float)distance_latitude); mesh.AddCube(material, translate); } var scene = new SceneBuilder(); scene.AddMesh(mesh, Matrix4x4.Identity); var glb = scene.ToSchema2().WriteGLB(); var bytes = glb.ToArray(); return(bytes); }
public static byte[] GetGlb(TriangleCollection triangles) { var materialCache = new MaterialsCache(); var default_hex_color = "#bb3333"; var defaultMaterial = materialCache.GetMaterialBuilderByColor(default_hex_color); var mesh = new MeshBuilder <VertexPositionNormal, VertexWithBatchId, VertexEmpty>("mesh"); foreach (var triangle in triangles) { MaterialBuilder material; if (!string.IsNullOrEmpty(triangle.Color)) { material = materialCache.GetMaterialBuilderByColor(triangle.Color); } else { material = defaultMaterial; } DrawTriangle(triangle, material, mesh); } var scene = new SceneBuilder(); scene.AddMesh(mesh, Matrix4x4.Identity); var model = scene.ToSchema2(); var bytes = model.WriteGLB().Array; return(bytes); }
private void RunSimpleAnimation(string name, Vector3 translation, Vector3 localTrans) { float xTrans = 10; float zTrans = 10; // create two materials var material1 = new MaterialBuilder() .WithDoubleSide(true) .WithMetallicRoughnessShader() .WithChannelParam("BaseColor", new Vector4(1, 0, 0, 1)); var material2 = new MaterialBuilder() .WithDoubleSide(true) .WithMetallicRoughnessShader() .WithChannelParam("BaseColor", new Vector4(1, 0, 1, 1)); // create a mesh with two primitives, one for each material var node = new NodeBuilder("Node"); node.LocalTransform = Matrix4x4.CreateTranslation(localTrans); node = node.CreateNode(); node.UseTranslation("track1") .WithPoint(0, translation) .WithPoint(1, translation); node.UseRotation("track1") .WithPoint(0, Quaternion.Identity) .WithPoint(0.5f, Quaternion.CreateFromAxisAngle(Vector3.UnitY, MathF.PI)) .WithPoint(1, Quaternion.CreateFromAxisAngle(Vector3.UnitY, 1.5f * MathF.PI)); var mesh = new MeshBuilder <VERTEX>("mesh"); var prim = mesh.UsePrimitive(material1); prim.AddTriangle(new VERTEX(-10 + xTrans, 0, 0 + zTrans), new VERTEX(10 + xTrans, 0, 0 + zTrans), new VERTEX(0 + xTrans, 0, 10 + zTrans)); prim.AddTriangle(new VERTEX(10 + xTrans, 0, 0 + zTrans), new VERTEX(-10 + xTrans, 0, 0 + zTrans), new VERTEX(0 + xTrans, 0, -10 + zTrans)); prim = mesh.UsePrimitive(material2); prim.AddQuadrangle(new VERTEX(-5 + xTrans, 3, 0 + zTrans), new VERTEX(0 + xTrans, 3, -5 + zTrans), new VERTEX(5 + xTrans, 3, 0 + zTrans), new VERTEX(0 + xTrans, 3, 5 + zTrans)); // create a scene var scene = new SceneBuilder(); scene.AddMesh(mesh, node); // save the model in different formats var model = scene.ToSchema2(); model.SaveGLB($"{name}.glb"); }
public static SceneBuilder ToGltf(IfcStore model) { var context = new Xbim3DModelContext(model); context.CreateContext(); var geoms = context.ShapeGeometries().ToList(); Console.WriteLine("Number of geometries: " + geoms.Count); var mesh = new MeshBuilder <VERTEX>("mesh"); var material1 = new MaterialBuilder() .WithDoubleSide(true) .WithMetallicRoughnessShader() .WithChannelParam("BaseColor", new Vector4(1, 0, 0, 1)); foreach (var geom in geoms) { var data = ((IXbimShapeGeometryData)geom).ShapeData; using var stream = new MemoryStream(data); using var reader = new BinaryReader(stream); var meshBim = reader.ReadShapeTriangulation(); foreach (var face in meshBim.Faces) { var indeces = face.Indices; for (var triangle = 0; triangle < face.TriangleCount; triangle++) { var start = triangle * 3; var p0 = meshBim.Vertices[indeces[start]]; var p1 = meshBim.Vertices[indeces[start + 1]]; var p2 = meshBim.Vertices[indeces[start + 2]]; var prim = mesh.UsePrimitive(material1); prim.AddTriangle( new VERTEX((float)p0.X, (float)p0.Y, (float)p0.Z * 10), new VERTEX((float)p1.X, (float)p1.Y, (float)p1.Z * 10), new VERTEX((float)p2.X, (float)p2.Y, (float)p2.Z * 10)); } } } var scene = new SceneBuilder(); scene.AddMesh(mesh, Matrix4x4.Identity); return(scene); }
private void ExportNodePart(ComponentOccurrence componentOccurrence, SceneBuilder scene, NodeBuilder node) { // ReSharper disable once SuspiciousTypeConversion.Global var partComponentDefinition = (PartComponentDefinition)componentOccurrence.Definition; try { if (visitedDocuments.Add(partComponentDefinition.Document.InternalName())) { progressBar.Message = "Exporting mesh " + visitedDocuments.Count + " of " + progressTotal + "..."; progressBar.UpdateProgress(); } } catch { } if (exportHidden || componentOccurrence.Visible) { scene.AddMesh(ExportMesh(componentOccurrence), node); } }
public void ColorTest() { var p1 = new Point(0, 0, 0); var p2 = new Point(1, 1, 0); var p3 = new Point(1, 0, 0); var triangle1 = new Triangle(p1, p2, p3, 100); p1 = new Point(5, 5, 0); p2 = new Point(6, 6, 0); p3 = new Point(6, 5, 0); var triangle2 = new Triangle(p1, p2, p3, 100); var materialRed = new MaterialBuilder(). WithDoubleSide(true). WithMetallicRoughnessShader(). WithChannelParam("BaseColor", new Vector4(1, 0, 0, 1)); var materialGreen = new MaterialBuilder(). WithDoubleSide(true). WithMetallicRoughnessShader(). WithChannelParam("BaseColor", new Vector4(0, 1, 0, 1)); var materialWhite = new MaterialBuilder(). WithDoubleSide(true). WithMetallicRoughnessShader(). WithChannelParam("BaseColor", new Vector4(1, 1, 1, 1)); var mesh = new MeshBuilder <VertexPositionNormal>("mesh"); DrawTriangle(triangle1, materialWhite, mesh); DrawTriangle(triangle2, materialGreen, mesh); var scene = new SceneBuilder(); scene.AddMesh(mesh, Matrix4x4.Identity); var model = scene.ToSchema2(); }