Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

6586559: Support for vertex colors #1557

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
531 changes: 531 additions & 0 deletions apps/toys/FX8-3DFeatures/src/fx83dfeatures/DynamicMeshViewer.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public class TriangleMeshBuilder extends TreeMap<String, Object> implements Buil
private float[] points;
private float[] texCoords;
private float[] normals;
private float[] colors;
private int[] faces;
private int[] faceSmoothingGroups;
private VertexFormat vertexFormat;
Expand All @@ -63,6 +64,9 @@ public TriangleMesh build() {
if (normals != null) {
mesh.getNormals().setAll(normals);
}
if (colors != null) {
mesh.getColors().setAll(colors);
}
if (vertexFormat != null) {
mesh.setVertexFormat(vertexFormat);
}
Expand Down Expand Up @@ -102,13 +106,23 @@ public Object put(String key, Object value) {
for (int i = 0; i < split.length; ++i) {
normals[i] = Float.parseFloat(split[i]);
}
} else if ("colors".equalsIgnoreCase(key)) {
String[] split = ((String) value).split(VALUE_SEPARATOR_REGEX);
colors = new float[split.length];
for (int i = 0; i < split.length; ++i) {
colors[i] = Float.parseFloat(split[i]);
}
} else if ("vertexformat".equalsIgnoreCase(key)) {
if (value instanceof VertexFormat) {
vertexFormat = (VertexFormat) value;
} else if ("point_texcoord".equalsIgnoreCase((String)value)) {
vertexFormat = VertexFormat.POINT_TEXCOORD;
} else if ("point_texcoord_color".equalsIgnoreCase((String)value)) {
vertexFormat = VertexFormat.POINT_TEXCOORD_COLOR;
} else if ("point_normal_texcoord".equalsIgnoreCase((String)value)) {
vertexFormat = VertexFormat.POINT_NORMAL_TEXCOORD;
} else if ("point_normal_texcoord_color".equalsIgnoreCase((String)value)) {
vertexFormat = VertexFormat.POINT_NORMAL_TEXCOORD_COLOR;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,13 @@ public void set(Vec4f v) {
this.w = v.w;
}

public void set(float x, float y, float z, float w) {
this.x = x;
this.y = y;
this.z = z;
this.w = w;
}

@Override
public String toString() {
return "(" + x + ", " + y + ", " + z + ", " + w + ")";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,17 @@
import com.sun.javafx.collections.IntegerArraySyncer;
import com.sun.prism.Mesh;
import com.sun.prism.ResourceFactory;
import javafx.scene.shape.VertexFormat;

/**
* TODO: 3D - Need documentation
*/
public class NGTriangleMesh {
private boolean meshDirty = true;
private Mesh mesh;
private VertexFormat vertexFormat;
private boolean userDefinedNormals = false;
private boolean userDefinedColors = false;

// points is an array of x,y,z interleaved
private float[] points;
Expand All @@ -50,6 +53,10 @@ public class NGTriangleMesh {
private float[] texCoords;
private int[] texCoordsFromAndLengthIndices = new int[2];

// colors is an array of r,g,b,a interleaved
private float[] colors;
private int[] colorsFromAndLengthIndices = new int[2];

// faces is an array of v1,v2,v3 interleaved (where v = {point, texCoord})
private int[] faces;
private int[] facesFromAndLengthIndices = new int[2];
Expand All @@ -75,14 +82,17 @@ Mesh createMesh(ResourceFactory rf) {

boolean validate() {
if (points == null || texCoords == null || faces == null || faceSmoothingGroups == null
|| (userDefinedNormals && (normals == null))) {
|| (userDefinedNormals && (normals == null)) || (userDefinedColors && (colors == null))
|| vertexFormat == null) {
return false;
}
if (meshDirty) {
if (!mesh.buildGeometry(userDefinedNormals,
if (!mesh.buildGeometry(
vertexFormat, userDefinedNormals, userDefinedColors,
points, pointsFromAndLengthIndices,
normals, normalsFromAndLengthIndices,
texCoords, texCoordsFromAndLengthIndices,
colors, colorsFromAndLengthIndices,
faces, facesFromAndLengthIndices,
faceSmoothingGroups, faceSmoothingGroupsFromAndLengthIndices)) {
throw new RuntimeException("NGTriangleMesh: buildGeometry failed");
Expand Down Expand Up @@ -116,6 +126,14 @@ void setTexCoordsByRef(float[] texCoords) {
this.texCoords = texCoords;
}

// Note: This method is intentionally made package scope for security
// reason. It is created for internal use only.
// Do not make it a public method without careful consideration.
void setColorsByRef(float[] colors) {
meshDirty = true;
this.colors = colors;
}

// Note: This method is intentionally made package scope for security
// reason. It is created for internal use only.
// Do not make it a public method without careful consideration.
Expand All @@ -132,6 +150,10 @@ void setFaceSmoothingGroupsByRef(int[] faceSmoothingGroups) {
this.faceSmoothingGroups = faceSmoothingGroups;
}

public void setVertexFormat(VertexFormat vertexFormat) {
this.vertexFormat = vertexFormat;
}

public void setUserDefinedNormals(boolean userDefinedNormals) {
this.userDefinedNormals = userDefinedNormals;
}
Expand All @@ -140,6 +162,14 @@ public boolean isUserDefinedNormals() {
return userDefinedNormals;
}

public void setUserDefinedColors(boolean userDefinedColors) {
this.userDefinedColors = userDefinedColors;
}

public boolean isUserDefinedColors() {
return userDefinedColors;
}

public void syncPoints(FloatArraySyncer array) {
meshDirty = true;
points = array != null ? array.syncTo(points, pointsFromAndLengthIndices) : null;
Expand All @@ -155,6 +185,11 @@ public void syncTexCoords(FloatArraySyncer array) {
texCoords = array != null ? array.syncTo(texCoords, texCoordsFromAndLengthIndices) : null;
}

public void syncColors(FloatArraySyncer array) {
meshDirty = true;
colors = array != null ? array.syncTo(colors, colorsFromAndLengthIndices) : null;
}

public void syncFaces(IntegerArraySyncer array) {
meshDirty = true;
faces = array != null ? array.syncTo(faces, facesFromAndLengthIndices) : null;
Expand All @@ -165,6 +200,10 @@ public void syncFaceSmoothingGroups(IntegerArraySyncer array) {
faceSmoothingGroups = array != null ? array.syncTo(faceSmoothingGroups, faceSmoothingGroupsFromAndLengthIndices) : null;
}

// NOTE: This method is used for unit test purpose only.
VertexFormat test_getVertexFormat() {
return this.vertexFormat;
}
// NOTE: This method is used for unit test purpose only.
int[] test_getFaceSmoothingGroups() {
return this.faceSmoothingGroups;
Expand All @@ -186,6 +225,10 @@ float[] test_getTexCoords() {
return this.texCoords;
}
// NOTE: This method is used for unit test purpose only.
float[] test_getColors() {
return this.colors;
}
// NOTE: This method is used for unit test purpose only.
Mesh test_getMesh() {
return this.mesh;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,22 @@

package com.sun.prism;

import javafx.scene.shape.VertexFormat;

/**
* TODO: 3D - Need documentation
* This class represents mesh geometry data object
*/
public interface Mesh extends GraphicsResource {
// This method will fail if and only if ALL faces are wrong.
// A wrong face is one with zero area or with any index out of range
public boolean buildGeometry(boolean userDefinedNormals,
public boolean buildGeometry(
VertexFormat vertexFormat,
boolean userDefinedNormals, boolean userDefinedColors,
float points[], int[] pointsFromAndLengthIndices,
float normals[], int[] normalsFromAndLengthIndices,
float texCoords[], int[] texCoordsFromAndLengthIndices,
float colors[], int[] colorsFromAndLengthIndices,
int faces[], int[] facesFromAndLengthIndices,
int faceSmoothingGroups[], int[] faceSmoothingGroupsFromAndLengthIndices);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ static ES2Shader getShader(ES2MeshView meshView, ES2Context context) {
attributes.put("pos", 0);
attributes.put("texCoords", 1);
attributes.put("tangent", 2);
attributes.put("color", 3);

Map<String, Integer> samplers = new HashMap<>();
samplers.put("diffuseTexture", 0);
Expand Down
Loading