Skip to content

Commit d1976f8

Browse files
committed
Check if normals and uvs are null
1 parent 35aaa8c commit d1976f8

File tree

2 files changed

+40
-8
lines changed

2 files changed

+40
-8
lines changed

src/main/java/org/sunflow/core/parameter/geometry/GenericMeshParameter.java

+12-8
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,20 @@ public void setup(SunflowAPIInterface api) {
2020
api.parameter("points", "point", "vertex", points);
2121
api.parameter("triangles", triangles);
2222

23-
if (!faceVaryingNormals) {
24-
api.parameter("normals", "vector", "vertex", normals);
25-
} else {
26-
api.parameter("normals", "vector", "facevarying", normals);
23+
if (normals != null) {
24+
if (!faceVaryingNormals) {
25+
api.parameter("normals", "vector", "vertex", normals);
26+
} else {
27+
api.parameter("normals", "vector", "facevarying", normals);
28+
}
2729
}
2830

29-
if (!faceVaryingTextures) {
30-
api.parameter("uvs", "texcoord", "vertex", uvs);
31-
} else {
32-
api.parameter("uvs", "texcoord", "facevarying", uvs);
31+
if (uvs != null) {
32+
if (!faceVaryingTextures) {
33+
api.parameter("uvs", "texcoord", "vertex", uvs);
34+
} else {
35+
api.parameter("uvs", "texcoord", "facevarying", uvs);
36+
}
3337
}
3438

3539
if (faceShaders != null) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package org.sunflow.core.primitive;
2+
3+
import org.junit.Assert;
4+
import org.junit.Before;
5+
import org.junit.Test;
6+
import org.sunflow.math.Point3;
7+
8+
public class TriangleMeshTest {
9+
10+
TriangleMesh mesh;
11+
12+
@Before
13+
public void setUp() {
14+
mesh = new TriangleMesh();
15+
}
16+
17+
@Test
18+
public void testInit() {
19+
mesh.points = new float[]{0, 0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6, 7, 7, 7, 8, 8, 8};
20+
mesh.triangles = new int[]{0, 1, 2, 3, 4, 5, 6, 7, 8};
21+
22+
Assert.assertEquals(3, mesh.getNumPrimitives());
23+
24+
Assert.assertEquals(new Point3(0, 0, 0), mesh.getPoint(0));
25+
Assert.assertEquals(new Point3(1, 1, 1), mesh.getPoint(1));
26+
Assert.assertEquals(new Point3(2, 2, 2), mesh.getPoint(2));
27+
}
28+
}

0 commit comments

Comments
 (0)