/// <summary> /// Creates a fusee-compatible mesh from a Jometri geometry /// </summary> /// <param name="geometry">The triangulated Jometri geometry, saved in a doubly connected edge list</param> public JometriMesh(Jometri.Geometry geometry) { ConvertToMesh(geometry, out var vertices, out var triangles, out var normals); Vertices = vertices; Triangles = triangles; Normals = normals.ToArray(); }
//Geometry has to be triangulated! Translates a Jometri.Geometry into a Fusee.Mesh. private static void ConvertToMesh(Jometri.Geometry geometry, out float3[] vertices, out ushort[] triangles, out List <float3> normals) { var faces = geometry.GetAllFaces().ToList(); if (faces[0].Handle == 1) { faces.RemoveAt(0); } var triangleCount = faces.Count; var vertCount = triangleCount * 3; var verts = new List <float3>(); vertices = new float3[vertCount]; triangles = new ushort[vertCount]; normals = new List <float3>(); foreach (var face in faces) { if (face.Handle == 1) { continue; } var faceVerts = geometry.GetFaceVertices(face.Handle).ToList(); if (faceVerts.Count > 3) { throw new ArgumentException("Invalid triangle - face has more than 3 Vertices"); } foreach (var vertex in faceVerts) { verts.Add(vertex.VertData.Pos); if (face.FaceData.FaceNormal == float3.Zero) { geometry.SetFaceNormal(geometry.GetFaceOuterVertices(face.Handle).ToList(), face); } normals.Add(face.FaceData.FaceNormal); } } for (var i = 0; i < vertices.Length; i++) { vertices[i] = verts[i]; triangles[i] = (ushort)i; } }
// Init is called on startup. public override void Init() { var fontLato = AssetStorage.Get <Font>("Lato-Black.ttf"); var vladimir = AssetStorage.Get <Font>("VLADIMIR.TTF"); var gnuSerif = AssetStorage.Get <Font>("GNU-FreeSerif.ttf"); _text = "FUSEE ThreeDFont Example"; _threeDFontHelper = new ThreeDFontHelper(_text, fontLato); var outlinesLato = _threeDFontHelper.GetTextOutlinesWAngle(20); var geomLato = new Jometri.Geometry(outlinesLato); geomLato.Extrude2DPolygon(2000, false); geomLato.Triangulate(); _textMeshLato = new JometriMesh(geomLato); _threeDFontHelper = new ThreeDFontHelper(_text, vladimir); var outlinesVlad = _threeDFontHelper.GetTextOutlinesWAngle(7); var geomVlad = new Jometri.Geometry(outlinesVlad); geomVlad.Extrude2DPolygon(200, false); geomVlad.Triangulate(); _textMeshVlad = new JometriMesh(geomVlad); _threeDFontHelper = new ThreeDFontHelper(_text, gnuSerif); var outlinesGnu = _threeDFontHelper.GetTextOutlinesWAngle(40); var geomGnu = new Jometri.Geometry(outlinesGnu); //geomVlad.Extrude2DPolygon(200, false); geomGnu.Triangulate(); _textMeshGnu = new JometriMesh(geomGnu); ////////////////// Fill SceneNode //////////////////////////////// var parentNode = new SceneNode { Components = new List <SceneComponent>(), Children = new ChildList() }; var parentTrans = new Transform { Rotation = float3.Zero, Scale = new float3(0.01f, 0.01f, 0.01f), Translation = new float3(0, 0, 10) }; parentNode.Components.Add(parentTrans); //Vladimir var sceneNodeCVlad = new SceneNode { Components = new List <SceneComponent>() }; var meshCVlad = new Mesh { Vertices = _textMeshVlad.Vertices, Triangles = _textMeshVlad.Triangles, Normals = _textMeshVlad.Normals, }; var tranCVlad = new Transform { Rotation = float3.Zero, Scale = float3.One, Translation = new float3(0, 2000, 0) }; sceneNodeCVlad.Components.Add(tranCVlad); sceneNodeCVlad.Components.Add(meshCVlad); //Lato var sceneNodeCLato = new SceneNode { Components = new List <SceneComponent>() }; var meshCLato = new Mesh { Vertices = _textMeshLato.Vertices, Triangles = _textMeshLato.Triangles, Normals = _textMeshLato.Normals, }; var tranCLato = new Transform { Rotation = float3.Zero, Scale = float3.One, Translation = new float3(0, 0, 0) }; sceneNodeCLato.Components.Add(tranCLato); sceneNodeCLato.Components.Add(meshCLato); //GNU var sceneNodeCGnu = new SceneNode { Components = new List <SceneComponent>() }; var meshCGnu = new Mesh { Vertices = _textMeshGnu.Vertices, Triangles = _textMeshGnu.Triangles, Normals = _textMeshGnu.Normals, }; var tranCGnu = new Transform { Rotation = float3.Zero, Scale = float3.One, Translation = new float3(0, -2000, 0) }; sceneNodeCGnu.Components.Add(tranCGnu); sceneNodeCGnu.Components.Add(meshCGnu); parentNode.Children.Add(sceneNodeCVlad); parentNode.Children.Add(sceneNodeCLato); parentNode.Children.Add(sceneNodeCGnu); var sc = new SceneContainer { Children = new List <SceneNode> { parentNode } }; _renderer = new SceneRendererForward(sc); var shaderFx = new ShaderEffect(new[] { new EffectPassDeclaration { PS = AssetStorage.Get <string>("FragShader.frag"), VS = AssetStorage.Get <string>("VertShader.vert"), StateSet = new RenderStateSet { ZEnable = true } } }, new List <EffectParameterDeclaration> { new EffectParameterDeclaration { Name = "xform", Value = float4x4.Identity } }); RC.SetShaderEffect(shaderFx); // Set the clear color for the backbuffer RC.ClearColor = new float4(0, 0.61f, 0.88f, 1); }