Skip to content

A mesh generation library using Wavefront OBJ format for Java.

Notifications You must be signed in to change notification settings

erenyenigul/wavefront.java

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

wavefront.java

This library provides a set of classes and methods for creating and exporting 3D models in the Wavefront OBJ file format. The library supports creating and manipulating vertices, faces and meshes in a simple and intuitive way.

Features 🛠

  • Create and manipulate 3D models with vertices, faces, and texture coordinates
  • Export models to the Wavefront OBJ file format
  • Define meshes (combination of faces), extrude and loft faces,
  • Easy to use and integrate into existing Java projects

Here's the list of classes:

Point

Point is a immutable class which can be used to define Vectors, Faces and many more. To define a Point,

Point p = new Point(double X, double Y, double Z);

If you need origin, you can directly call the static variable ORIGIN,

Point origin = new Point(0,0,0);
//But instead,
Point origin = Point.ORIGIN;

Methods

getX(),getY(),getZ()

returns double
double xCoordMyPoint = myPoint.getX(); 

distanceToPoint(Point p)

returns double
double distance = myPoint.distanceToPoint(otherPoint);

shift(Vector v)

returns Point
Point shiftedPoint = myPoint.shift(myVector);

Do not forget that Point is an immutable class. Methods like this does not affect the point itself, but outputs new instances!


Vector

Vectors allow you to do many different operations. Vector is an immutable class. To define a Vector, you can use any of the ways below:

Vector v = new Vector(Point head);
//or
Vector v = new Vector(Point tail, Point head);
//or 
Vector v = new Vector(double headX, double headY, double headZ);

Vector s in JavaMesh do not have the instance tail. Constructor with tail (which is the second example above), forms a new head, and creates a vector which is a shifted-to-origin version of the vector with user-given tail and head

Methods

getHead()

returns Point

length()

returns double

getUnitVector()

returns Vector

Returns a unit vector which has the same direction as the vector itself.


cross(Vector v)

returns Vector

Get the cross product of the vector with v .


dot(Vector v)

returns double

Get the dot product of the vector with v .


degreeBetween(Vector v)

returns double

Return value is radians.


add(Vector v), substract(Vector v)

returns Vector

scale(double scaleFactor)

returns Vector

Returns a new vector which is a scaled version of the original.


rotate(double angle, Vector axisOfRotation)

returns Vector

Angle must be in radians.


isZeroVector()

returns boolean

Face

Mesh

Mesh is a collection of Faces.

Use .saveAsObj() to save it as .obj file.

Creation Operations

static extrude(Face f, Vector directionVector)

returns Mesh

static loft(Surface s1, Surface s2, int segmentNum, double scaleFactor)

returns Mesh

Releases

No releases published

Packages

No packages published

Languages