Skip to content

Commit

Permalink
Merge pull request #2458 from SiboVG/issue-2444
Browse files Browse the repository at this point in the history
[#2444] Add Constrained Delaungay Triangulation for OBJ exporting
  • Loading branch information
JoePfeiffer committed Feb 16, 2024
2 parents 3c7f35c + 18b0b34 commit 19cafe9
Show file tree
Hide file tree
Showing 18 changed files with 801 additions and 1 deletion.
1 change: 1 addition & 0 deletions core/.classpath
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,6 @@
<classpathentry kind="lib" path="lib/istack-commons-runtime.jar"/>
<classpathentry kind="lib" path="lib/graal-sdk-22.1.0.1.jar"/>
<classpathentry kind="lib" path="lib/js-scriptengine-22.1.0.1.jar"/>
<classpathentry kind="lib" path="lib/jts-core-1.19.0.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>
9 changes: 9 additions & 0 deletions core/OpenRocket Core.iml
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,15 @@
<SOURCES />
</library>
</orderEntry>
<orderEntry type="module-library">
<library>
<CLASSES>
<root url="jar://$MODULE_DIR$/lib/jts-core-1.19.0.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
<orderEntry type="module-library">
<library>
<CLASSES>
Expand Down
Binary file added core/lib/jts-core-1.19.0.jar
Binary file not shown.
8 changes: 8 additions & 0 deletions core/resources/l10n/messages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -1556,6 +1556,8 @@ OBJOptionChooser.checkbox.removeOffset.ttip = <html>If true, remove the offset o
OBJOptionChooser.btn.showAdvanced = Show Advanced options
OBJOptionChooser.checkbox.triangulate = Triangulate mesh
OBJOptionChooser.checkbox.triangulate.ttip = If true, triangulate the mesh before exporting (convert all quads or high-order polygons to a triangle).
OBJOptionChooser.lbl.triangulationMethod = Triangulation method:
OBJOptionChooser.lbl.triangulationMethod.ttip = Select the desired algorithm to use for the triangulation.
OBJOptionChooser.checkbox.sRGB = Export colors in sRGB
OBJOptionChooser.checkbox.sRGB.ttip = <html>If true, export colors in sRGB instead of a linear color scheme.<br>Is useful for instance when exporting for use in Blender.</html>
OBJOptionChooser.lbl.Scaling = Scaling:
Expand All @@ -1574,6 +1576,12 @@ LevelOfDetail.LOW_QUALITY = Low quality
LevelOfDetail.NORMAL_QUALITY = Normal quality
LevelOfDetail.HIGH_QUALITY = High quality

! TriangulationMethod
TriangulationMethod.SIMPLE = Simple (fast)
TriangulationMethod.SIMPLE.ttip = Simple triangulation method (fast, but may produce poor results)
TriangulationMethod.DELAUNAY = Delaunay (recommended)
TriangulationMethod.DELAUNAY.ttip = Constrained Delaunay triangulation method (recommended, but may be slow for large models)

! ThrustCurveMotorSelectionPanel
TCMotorSelPan.lbl.Selrocketmotor = Select rocket motor:
TCMotorSelPan.checkbox.hideSimilar = Hide very similar thrust curves
Expand Down
29 changes: 29 additions & 0 deletions core/src/net/sf/openrocket/file/wavefrontobj/DefaultObj.java
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,10 @@ public int getNumFaces() {
return faces.size();
}

public List<ObjFace> getFaces() {
return faces;
}

@Override
public ObjFace getFace(int index) {
return faces.get(index);
Expand Down Expand Up @@ -458,6 +462,14 @@ public void addFace(int... v) {
addFace(v, null, null);
}

public void removeFace(int index) {
faces.remove(index);
}

public void removeFace(ObjFace face) {
faces.remove(face);
}

@Override
public void addFaceWithTexCoords(int... v) {
addFace(v, v, null);
Expand Down Expand Up @@ -603,5 +615,22 @@ private static void checkIndices(int[] indices, int max, String name) {
}
}
}

/**
* Creates a clone of this object.
*
* @param cloneFacesAndGroups Whether the faces should be cloned
* @return a new DefaultObj object with the same properties as this object
*/
public DefaultObj clone(boolean cloneFacesAndGroups) {
DefaultObj newObj = new DefaultObj();
newObj.setMtlFileNames(getMtlFileNames());
ObjUtils.copyAllVertices(this, newObj);
if (cloneFacesAndGroups) {
ObjUtils.copyAllFacesAndGroups(this, newObj);
}

return newObj;
}
}

65 changes: 65 additions & 0 deletions core/src/net/sf/openrocket/file/wavefrontobj/DefaultObjEdge.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package net.sf.openrocket.file.wavefrontobj;

public class DefaultObjEdge {
/**
* The vertex index of the start of this edge
*/
private final int startVertexIndex;
/**
* The vertex index of the end of this edge
*/
private final int endVertexIndex;

/**
* The normal index of the start of this edge
*/
private final int startNormalIndex;
/**
* The normal index of the end of this edge
*/
private final int endNormalIndex;

/**
* The texture coordinate index of the start of this edge
*/
private final int startTexCoordIndex;
/**
* The texture coordinate index of the end of this edge
*/
private final int endTexCoordIndex;


public DefaultObjEdge(int startVertexIndex, int endVertexIndex, int startTexCoordIndex, int endTexCoordIndex, int startNormalIndex, int endNormalIndex) {
this.startVertexIndex = startVertexIndex;
this.endVertexIndex = endVertexIndex;
this.startTexCoordIndex = startTexCoordIndex;
this.endTexCoordIndex = endTexCoordIndex;
this.startNormalIndex = startNormalIndex;
this.endNormalIndex = endNormalIndex;
}

public static DefaultObjEdge[] createEdges(DefaultObjFace faces) {
DefaultObjEdge[] edges = new DefaultObjEdge[faces.getNumVertices()-1];
for (int i = 0; i < faces.getNumVertices()-1; i++) {
int startVertexIndex = faces.getVertexIndex(i);
int endVertexIndex = faces.getVertexIndex((i + 1));

int startNormalIndex = -1;
int endNormalIndex = -1;
if (faces.containsNormalIndices()) {
startNormalIndex = faces.getNormalIndex(i);
endNormalIndex = faces.getNormalIndex((i + 1));
}

int startTexCoordIndex = -1;
int endTexCoordIndex = -1;
if (faces.containsTexCoordIndices()) {
startTexCoordIndex = faces.getTexCoordIndex(i);
endTexCoordIndex = faces.getTexCoordIndex((i + 1));
}

edges[i] = new DefaultObjEdge(startVertexIndex, endVertexIndex, startTexCoordIndex, endTexCoordIndex, startNormalIndex, endNormalIndex);
}
return edges;
}
}
20 changes: 20 additions & 0 deletions core/src/net/sf/openrocket/file/wavefrontobj/DefaultObjFace.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@

import de.javagl.obj.ObjFace;

import java.util.Arrays;

/**
* Default implementation of an ObjFace
*/
Expand Down Expand Up @@ -63,6 +65,12 @@ public DefaultObjFace(int[] vertexIndices, int[] texCoordIndices, int[] normalIn
this.normalIndices = normalIndices;
}

public DefaultObjFace(DefaultObjFace face) {
this.vertexIndices = Arrays.copyOf(face.vertexIndices, face.vertexIndices.length);
this.texCoordIndices = face.texCoordIndices != null ? Arrays.copyOf(face.texCoordIndices, face.texCoordIndices.length) : null;
this.normalIndices = face.normalIndices != null ? Arrays.copyOf(face.normalIndices, face.normalIndices.length) : null;
}


@Override
public boolean containsTexCoordIndices() {
Expand All @@ -74,6 +82,18 @@ public boolean containsNormalIndices() {
return normalIndices != null;
}

public int[] getVertexIndices() {
return vertexIndices;
}

public int[] getTexCoordIndices() {
return texCoordIndices;
}

public int[] getNormalIndices() {
return normalIndices;
}

@Override
public int getVertexIndex(int number) {
return this.vertexIndices[number];
Expand Down
26 changes: 26 additions & 0 deletions core/src/net/sf/openrocket/file/wavefrontobj/DefaultObjGroup.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,36 @@ public void addFace(ObjFace face) {
faces.add(face);
}

public void addFaces(List<ObjFace> faces) {
this.faces.addAll(faces);
}

/**
* Remove the given face from this group
*
* @param face The face to remove
*/
public void removeFace(ObjFace face) {
faces.remove(face);
}

/**
* Returns the faces in this group
* @return The faces in this group
*/
public List<ObjFace> getFaces() {
return faces;
}

/**
* Returns whether this group contains the given face
* @param face
* @return
*/
public boolean containsFace(ObjFace face) {
return faces.contains(face);
}

@Override
public int getNumFaces() {
return faces.size();
Expand Down
Loading

0 comments on commit 19cafe9

Please sign in to comment.