Skip to content

Commit

Permalink
[orx-mesh-generators] Fix grid issue when count==1
Browse files Browse the repository at this point in the history
  • Loading branch information
hamoid committed Jan 22, 2025
1 parent ec34015 commit d1d3af7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 15 deletions.
20 changes: 10 additions & 10 deletions orx-mesh-generators/src/commonMain/kotlin/TriangleMeshBuilder.kt
Original file line number Diff line number Diff line change
Expand Up @@ -249,13 +249,13 @@ fun TriangleMeshBuilder.grid(
when (coordinates) {
GridCoordinates.INDEX -> this.builder(u * 1.0, v * 1.0)
GridCoordinates.BIPOLAR -> this.builder(
2 * u / (width - 1.0) - 1,
2 * v / (height - 1.0) - 1
if (width <= 1) 0.0 else 2 * u / (width - 1.0) - 1,
if (height <= 1) 0.0 else 2 * v / (height - 1.0) - 1
)

GridCoordinates.UNIPOLAR -> this.builder(
u / (width - 1.0),
v / (height - 1.0)
if (width <= 1) 0.0 else u / (width - 1.0),
if (height <= 1) 0.0 else v / (height - 1.0)
)
}
}
Expand Down Expand Up @@ -292,15 +292,15 @@ fun TriangleMeshBuilder.grid(
)

GridCoordinates.BIPOLAR -> this.builder(
2 * u / (width - 1.0) - 1,
2 * v / (height - 1.0) - 1,
2 * w / (depth - 1.0) - 1
if (width <= 1) 0.0 else 2 * u / (width - 1.0) - 1,
if (height <= 1) 0.0 else 2 * v / (height - 1.0) - 1,
if (depth <= 1) 0.0 else 2 * w / (depth - 1.0) - 1
)

GridCoordinates.UNIPOLAR -> this.builder(
u / (width - 1.0),
v / (height - 1.0),
w / (depth - 1.0)
if (width <= 1) 0.0 else u / (width - 1.0),
if (height <= 1) 0.0 else v / (height - 1.0),
if (depth <= 1) 0.0 else w / (depth - 1.0)
)
}
}
Expand Down
13 changes: 8 additions & 5 deletions orx-mesh-generators/src/jvmDemo/kotlin/DemoComplex05.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ import org.openrndr.draw.CullTestPass
import org.openrndr.draw.DrawPrimitive
import org.openrndr.draw.shadeStyle
import org.openrndr.extra.camera.Orbital
import org.openrndr.extra.meshgenerators.*
import org.openrndr.extra.meshgenerators.buildTriangleMesh
import org.openrndr.extra.meshgenerators.extrudeShape
import org.openrndr.extra.meshgenerators.grid
import org.openrndr.extra.meshgenerators.twist
import org.openrndr.math.Vector3
import org.openrndr.shape.Circle

Expand All @@ -20,15 +23,15 @@ fun main() {
this.eye = Vector3(0.0, 30.0, 50.0)
}
val m = buildTriangleMesh {
grid(5,5, 5) { u, v, w ->
grid(5, 5, 5) { u, v, w ->
isolated {
translate(u * 20.0, v * 20.0, w * 20.0)
extrudeShape(Circle(0.0, 0.0, 50.0).shape, 4.0, scale = 0.1)
}
}
twist(360.0/200.0, 0.0)
twist(360.0/200.0, 0.0, Vector3.UNIT_X)
twist(360.0/200.0, 0.0, Vector3.UNIT_Z)
twist(360.0 / 200.0, 0.0)
twist(360.0 / 200.0, 0.0, Vector3.UNIT_X)
twist(360.0 / 200.0, 0.0, Vector3.UNIT_Z)
}

extend {
Expand Down

0 comments on commit d1d3af7

Please sign in to comment.