/// <summary> /// /// </summary> /// <param name="args"></param> public static void Run() { var mesh = HeMesh3d.Factory.CreateFromOBJ(Paths.Resources + _fileIn); double scale = 0.5; double offset = scale * Math.PI * 0.25; // apply texture coordinates from an implicit function foreach (var v in mesh.Vertices) { var p = v.Position * scale; v.Texture = new Vec2d( ImplicitSurfaces.Gyroid(p.X, p.Y, p.Z), ImplicitSurfaces.Gyroid(p.X + offset, p.Y + offset, p.Z + offset) ); } // compute vertex normals & write to file mesh.GetVertexNormals(v => v.Position, (v, n) => v.Normal = n); mesh.WriteToOBJ(Paths.Resources + _fileOut); Console.WriteLine("File written successfully. Press return to exit."); Console.ReadLine(); }
/// <summary> /// /// </summary> public override float Evaluate(Vector3 point) { // impl ref // http://iquilezles.org/www/articles/distfunctions/distfunctions.htm point = _toLocal.MultiplyPoint3x4(point); switch (_type) { case ImplicitSurfaceType.Diamond: return((float)ImplicitSurfaces.Diamond(point)); case ImplicitSurfaceType.Gyroid: return((float)ImplicitSurfaces.Gyroid(point)); case ImplicitSurfaceType.HybridPW: return((float)ImplicitSurfaces.HybridPW(point)); case ImplicitSurfaceType.IWP: return((float)ImplicitSurfaces.IWP(point)); case ImplicitSurfaceType.Neovius: return((float)ImplicitSurfaces.Neovius(point)); } throw new System.NotImplementedException(); }
/// <summary> /// /// </summary> /// <param name="args"></param> public static void Start() { var mesh = HeMesh3d.Factory.CreateFromOBJ(Paths.Resources + _fileIn); var verts = mesh.Vertices; var texCoords = new Vector2d[verts.Count]; double scale = 0.5; double offset = scale * Math.PI * 0.25; // create texture coordinates from implicit function for (int i = 0; i < verts.Count; i++) { var p = verts[i].Position * scale; var u = ImplicitSurfaces.Gyroid(p.X, p.Y, p.Z); var v = ImplicitSurfaces.Gyroid(p.X + offset, p.Y + offset, p.Z + offset); texCoords[i] = new Vector2d(u, v); } // compute vertex normals & write to file mesh.Vertices.Action(v => v.Normal = v.GetNormal(), true); Interop.Meshes.WriteToObj(mesh, Paths.Resources + _fileOut, v => texCoords[v]); Console.WriteLine("File written successfully. Press return to exit."); Console.ReadLine(); }