How to represent 3D shapes with Jcg

(Luca Castelli Aleardi)

       



1. Getting started with Jcg

Files to download

Here are some files to download (some of these models are provided courtesy of INRIA by the
AIM@SHAPE Shape Repository):
  • PlanarMeshes.zip: simple examples of triangle meshes of genus 0 (OFF format)
  • 3DShapes.zip : some more examples (higher genus and boundaries).

Libraries to add (project /LIB):

  • Jcg.jar: library for the manipulation of triangle meshes (updated november 2014)
  • LIB.zip: related libraries required by Jcg (Java3D, Processing, ...).

For the testing and rendering meshes:

Java documentation

Here is the javaDoc of Jcg:


class Polyhedron_3



The library Jcg provides methods for loading and drawing a triangle mesh in a 3D frame. There are two possible ways of rendering a 3D shape: one based on the Java3D library, and one based on Processing3D .Both mesh viewers provide a simple trackball (allowing to rotate the 3D scene with mouse events).

Class TestPolyhedron illustrates how to load a mesh from a file (in OFF format) and how to rendering it, using either Java3D or Processing3D.

Method meshStatistics() allows to load a mesh stored in OFF format and to visualize its size and topology.
	public static void meshStatistics(String filename) {
SharedVertexRepresentation m=new SharedVertexRepresentation(filename); // load the mesh from file
LoadMesh<Point_3> load3D=new LoadMesh<Point_3>();
// build the mesh representation
Polyhedron_3<Point_3> polyhedron3D=load3D.createTriangleMesh(m.points,m.faceDegrees,m.faces,m.sizeHalfedges);
polyhedron3D.isValid(false); // check combinatorial validity
}








1. Loading and rendering 3D triangle meshes with Jcg


1.1 Rendering a 3D shape

Given a triangle mesh (class Polyhedron_3<Point_3>), there are two ways of obtaining a 3D rendering:
  • class MeshViewer provides a rendering tool based on Java3D.
  • class MeshProcessing provides a rendering tool based on Processing3D.



Examples of 3D rendering of a shape using Jcg, with Java3D and Processing