* @SuppressWarnings("fallthrough") to prevent warnings
* Fixed rest of the warnings git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@7241 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
This commit is contained in:
parent
7dd3d52e9e
commit
d729da9e78
@ -416,6 +416,13 @@ final class BinaryOutputCapsule implements OutputCapsule {
|
||||
return Arrays.equals(bytes, other);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int hash = 7;
|
||||
hash = 23 * hash + Arrays.hashCode(this.bytes);
|
||||
return hash;
|
||||
}
|
||||
|
||||
public void finish() {
|
||||
// renamed to finish as 'finalize' in java.lang.Object should not be
|
||||
// overridden like this
|
||||
|
@ -170,6 +170,7 @@ public final class Matrix3f implements Savable, Cloneable {
|
||||
* the colum index.
|
||||
* @return the value at (i, j).
|
||||
*/
|
||||
@SuppressWarnings("fallthrough")
|
||||
public float get(int i, int j) {
|
||||
switch (i) {
|
||||
case 0:
|
||||
@ -489,6 +490,7 @@ public final class Matrix3f implements Savable, Cloneable {
|
||||
* the value for (i, j).
|
||||
* @return this
|
||||
*/
|
||||
@SuppressWarnings("fallthrough")
|
||||
public Matrix3f set(int i, int j, float value) {
|
||||
switch (i) {
|
||||
case 0:
|
||||
@ -846,7 +848,6 @@ public final class Matrix3f implements Savable, Cloneable {
|
||||
* @return This matrix, after the multiplication
|
||||
*/
|
||||
public Matrix3f multLocal(Matrix3f mat) {
|
||||
|
||||
return mult(mat, this);
|
||||
}
|
||||
|
||||
@ -1050,8 +1051,9 @@ public final class Matrix3f implements Savable, Cloneable {
|
||||
*
|
||||
* @return the string representation of this object.
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuffer result = new StringBuffer("Matrix3f\n[\n");
|
||||
StringBuilder result = new StringBuilder("Matrix3f\n[\n");
|
||||
result.append(" ");
|
||||
result.append(m00);
|
||||
result.append(" ");
|
||||
@ -1085,6 +1087,7 @@ public final class Matrix3f implements Savable, Cloneable {
|
||||
* @return the hashcode for this instance of Matrix4f.
|
||||
* @see java.lang.Object#hashCode()
|
||||
*/
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int hash = 37;
|
||||
hash = 37 * hash + Float.floatToIntBits(m00);
|
||||
@ -1109,6 +1112,7 @@ public final class Matrix3f implements Savable, Cloneable {
|
||||
* the object to compare for equality
|
||||
* @return true if they are equal
|
||||
*/
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (!(o instanceof Matrix3f) || o == null) {
|
||||
return false;
|
||||
@ -1270,7 +1274,7 @@ public final class Matrix3f implements Savable, Cloneable {
|
||||
m22 *= scale.z;
|
||||
}
|
||||
|
||||
static final boolean equalIdentity(Matrix3f mat) {
|
||||
static boolean equalIdentity(Matrix3f mat) {
|
||||
if (Math.abs(mat.m00 - 1) > 1e-4) return false;
|
||||
if (Math.abs(mat.m11 - 1) > 1e-4) return false;
|
||||
if (Math.abs(mat.m22 - 1) > 1e-4) return false;
|
||||
|
@ -280,6 +280,7 @@ public final class Matrix4f implements Savable, Cloneable {
|
||||
* the colum index.
|
||||
* @return the value at (i, j).
|
||||
*/
|
||||
@SuppressWarnings("fallthrough")
|
||||
public float get(int i, int j) {
|
||||
switch (i) {
|
||||
case 0:
|
||||
@ -450,6 +451,7 @@ public final class Matrix4f implements Savable, Cloneable {
|
||||
* @param value
|
||||
* the value for (i, j).
|
||||
*/
|
||||
@SuppressWarnings("fallthrough")
|
||||
public void set(int i, int j, float value) {
|
||||
switch (i) {
|
||||
case 0:
|
||||
|
@ -20,264 +20,265 @@ import com.jme3.util.BufferUtils;
|
||||
* @author Marcin Roguski (Kealthas)
|
||||
*/
|
||||
public class Surface extends Mesh {
|
||||
private SplineType type; //the type of the surface
|
||||
private List<List<Vector4f>> controlPoints; //space control points and their weights
|
||||
private List<Float>[] knots; //knots of the surface
|
||||
private int basisUFunctionDegree; //the degree of basis U function
|
||||
private int basisVFunctionDegree; //the degree of basis V function
|
||||
private int uSegments; //the amount of U segments
|
||||
private int vSegments; //the amount of V segments
|
||||
|
||||
/**
|
||||
* Constructor. Constructs required surface.
|
||||
* @param controlPoints space control points
|
||||
* @param nurbKnots knots of the surface
|
||||
* @param uSegments the amount of U segments
|
||||
* @param vSegments the amount of V segments
|
||||
* @param basisUFunctionDegree the degree of basis U function
|
||||
* @param basisVFunctionDegree the degree of basis V function
|
||||
*/
|
||||
private Surface(List<List<Vector4f>> controlPoints, List<Float>[] nurbKnots,
|
||||
int uSegments, int vSegments, int basisUFunctionDegree, int basisVFunctionDegree) {
|
||||
this.validateInputData(controlPoints, nurbKnots, uSegments, vSegments);
|
||||
this.type = SplineType.Nurb;
|
||||
this.uSegments = uSegments;
|
||||
this.vSegments = vSegments;
|
||||
this.controlPoints = controlPoints;
|
||||
this.knots = nurbKnots;
|
||||
this.basisUFunctionDegree = basisUFunctionDegree;
|
||||
CurveAndSurfaceMath.prepareNurbsKnots(nurbKnots[0], basisUFunctionDegree);
|
||||
if(nurbKnots[1]!=null) {
|
||||
this.basisVFunctionDegree = basisVFunctionDegree;
|
||||
CurveAndSurfaceMath.prepareNurbsKnots(nurbKnots[1], basisVFunctionDegree);
|
||||
}
|
||||
|
||||
this.buildSurface();
|
||||
}
|
||||
private SplineType type; //the type of the surface
|
||||
private List<List<Vector4f>> controlPoints; //space control points and their weights
|
||||
private List<Float>[] knots; //knots of the surface
|
||||
private int basisUFunctionDegree; //the degree of basis U function
|
||||
private int basisVFunctionDegree; //the degree of basis V function
|
||||
private int uSegments; //the amount of U segments
|
||||
private int vSegments; //the amount of V segments
|
||||
|
||||
/**
|
||||
* This method creates a NURBS surface.
|
||||
* @param controlPoints space control points
|
||||
* @param nurbKnots knots of the surface
|
||||
* @param uSegments the amount of U segments
|
||||
* @param vSegments the amount of V segments
|
||||
* @param basisUFunctionDegree the degree of basis U function
|
||||
* @param basisVFunctionDegree the degree of basis V function
|
||||
* @return an instance of NURBS surface
|
||||
*/
|
||||
public static final Surface createNurbsSurface(List<List<Vector4f>> controlPoints, List<Float>[] nurbKnots,
|
||||
int uSegments, int vSegments, int basisUFunctionDegree, int basisVFunctionDegree) {
|
||||
Surface result = new Surface(controlPoints, nurbKnots, uSegments, vSegments, basisUFunctionDegree, basisVFunctionDegree);
|
||||
result.type = SplineType.Nurb;
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method creates the surface.
|
||||
*/
|
||||
private void buildSurface() {
|
||||
boolean smooth = true;//TODO: take smoothing into consideration
|
||||
float minUKnot = this.getMinUNurbKnot();
|
||||
float maxUKnot = this.getMaxUNurbKnot();
|
||||
float deltaU = (maxUKnot - minUKnot)/uSegments;
|
||||
|
||||
float minVKnot = this.getMinVNurbKnot();
|
||||
float maxVKnot = this.getMaxVNurbKnot();
|
||||
float deltaV = (maxVKnot - minVKnot)/vSegments;
|
||||
|
||||
Vector3f[] vertices = new Vector3f[(uSegments + 1) * (vSegments + 1)];
|
||||
|
||||
float u = minUKnot, v = minVKnot;
|
||||
int arrayIndex = 0;
|
||||
|
||||
for(int i=0;i<=vSegments; ++i) {
|
||||
for(int j=0;j<=uSegments; ++j) {
|
||||
Vector3f interpolationResult = new Vector3f();
|
||||
CurveAndSurfaceMath.interpolate(u, v, controlPoints, knots, basisUFunctionDegree, basisVFunctionDegree, interpolationResult);
|
||||
vertices[arrayIndex++] = interpolationResult;
|
||||
u += deltaU;
|
||||
}
|
||||
u = minUKnot;
|
||||
v += deltaV;
|
||||
}
|
||||
|
||||
//adding indexes
|
||||
int uVerticesAmount = uSegments + 1;
|
||||
int[] indices = new int[uSegments * vSegments * 6];
|
||||
arrayIndex = 0;
|
||||
for(int i=0;i<vSegments; ++i) {
|
||||
for(int j=0;j<uSegments; ++j) {
|
||||
indices[arrayIndex++] = j + i*uVerticesAmount;
|
||||
indices[arrayIndex++] = j + i*uVerticesAmount + 1;
|
||||
indices[arrayIndex++] = j + i*uVerticesAmount + uVerticesAmount;
|
||||
indices[arrayIndex++] = j + i*uVerticesAmount + 1;
|
||||
indices[arrayIndex++] = j + i*uVerticesAmount + uVerticesAmount + 1;
|
||||
indices[arrayIndex++] = j + i*uVerticesAmount + uVerticesAmount;
|
||||
}
|
||||
}
|
||||
|
||||
//normalMap merges normals of faces that will be rendered smooth
|
||||
Map<Vector3f, Vector3f> normalMap = new HashMap<Vector3f, Vector3f>(vertices.length);
|
||||
for(int i=0;i<indices.length;i+=3) {
|
||||
Vector3f n = FastMath.computeNormal(vertices[indices[i]], vertices[indices[i + 1]], vertices[indices[i + 2]]);
|
||||
this.addNormal(n, normalMap, smooth, vertices[indices[i]], vertices[indices[i + 1]], vertices[indices[i + 2]]);
|
||||
}
|
||||
//preparing normal list (the order of normals must match the order of vertices)
|
||||
float[] normals = new float[vertices.length * 3];
|
||||
arrayIndex = 0;
|
||||
for(int i=0;i<vertices.length;++i) {
|
||||
Vector3f n = normalMap.get(vertices[i]);
|
||||
normals[arrayIndex++] = n.x;
|
||||
normals[arrayIndex++] = n.y;
|
||||
normals[arrayIndex++] = n.z;
|
||||
}
|
||||
|
||||
this.setBuffer(VertexBuffer.Type.Position, 3, BufferUtils.createFloatBuffer(vertices));
|
||||
this.setBuffer(VertexBuffer.Type.Index, 3, indices);
|
||||
this.setBuffer(VertexBuffer.Type.Normal, 3, normals);
|
||||
this.updateBound();
|
||||
this.updateCounts();
|
||||
}
|
||||
|
||||
public List<List<Vector4f>> getControlPoints() {
|
||||
return controlPoints;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method returns the amount of U control points.
|
||||
* @return the amount of U control points
|
||||
*/
|
||||
public int getUControlPointsAmount() {
|
||||
return controlPoints.size();
|
||||
}
|
||||
|
||||
/**
|
||||
* This method returns the amount of V control points.
|
||||
* @return the amount of V control points
|
||||
*/
|
||||
public int getVControlPointsAmount() {
|
||||
return controlPoints.get(0)==null ? 0 : controlPoints.get(0).size();
|
||||
}
|
||||
|
||||
/**
|
||||
* This method returns the degree of basis U function.
|
||||
* @return the degree of basis U function
|
||||
*/
|
||||
public int getBasisUFunctionDegree() {
|
||||
return basisUFunctionDegree;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method returns the degree of basis V function.
|
||||
* @return the degree of basis V function
|
||||
*/
|
||||
public int getBasisVFunctionDegree() {
|
||||
return basisVFunctionDegree;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method returns the knots for specified dimension (U knots - value: '0',
|
||||
* V knots - value: '1').
|
||||
* @param dim an integer specifying if the U or V knots are required
|
||||
* @return an array of knots
|
||||
*/
|
||||
public List<Float> getKnots(int dim) {
|
||||
return knots[dim];
|
||||
}
|
||||
|
||||
/**
|
||||
* This method returns the type of the surface.
|
||||
* @return the type of the surface
|
||||
*/
|
||||
public SplineType getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method returns the minimum nurb curve U knot value.
|
||||
* @return the minimum nurb curve knot value
|
||||
*/
|
||||
* Constructor. Constructs required surface.
|
||||
* @param controlPoints space control points
|
||||
* @param nurbKnots knots of the surface
|
||||
* @param uSegments the amount of U segments
|
||||
* @param vSegments the amount of V segments
|
||||
* @param basisUFunctionDegree the degree of basis U function
|
||||
* @param basisVFunctionDegree the degree of basis V function
|
||||
*/
|
||||
private Surface(List<List<Vector4f>> controlPoints, List<Float>[] nurbKnots,
|
||||
int uSegments, int vSegments, int basisUFunctionDegree, int basisVFunctionDegree) {
|
||||
this.validateInputData(controlPoints, nurbKnots, uSegments, vSegments);
|
||||
this.type = SplineType.Nurb;
|
||||
this.uSegments = uSegments;
|
||||
this.vSegments = vSegments;
|
||||
this.controlPoints = controlPoints;
|
||||
this.knots = nurbKnots;
|
||||
this.basisUFunctionDegree = basisUFunctionDegree;
|
||||
CurveAndSurfaceMath.prepareNurbsKnots(nurbKnots[0], basisUFunctionDegree);
|
||||
if (nurbKnots[1] != null) {
|
||||
this.basisVFunctionDegree = basisVFunctionDegree;
|
||||
CurveAndSurfaceMath.prepareNurbsKnots(nurbKnots[1], basisVFunctionDegree);
|
||||
}
|
||||
|
||||
this.buildSurface();
|
||||
}
|
||||
|
||||
/**
|
||||
* This method creates a NURBS surface.
|
||||
* @param controlPoints space control points
|
||||
* @param nurbKnots knots of the surface
|
||||
* @param uSegments the amount of U segments
|
||||
* @param vSegments the amount of V segments
|
||||
* @param basisUFunctionDegree the degree of basis U function
|
||||
* @param basisVFunctionDegree the degree of basis V function
|
||||
* @return an instance of NURBS surface
|
||||
*/
|
||||
public static final Surface createNurbsSurface(List<List<Vector4f>> controlPoints, List<Float>[] nurbKnots,
|
||||
int uSegments, int vSegments, int basisUFunctionDegree, int basisVFunctionDegree) {
|
||||
Surface result = new Surface(controlPoints, nurbKnots, uSegments, vSegments, basisUFunctionDegree, basisVFunctionDegree);
|
||||
result.type = SplineType.Nurb;
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method creates the surface.
|
||||
*/
|
||||
private void buildSurface() {
|
||||
boolean smooth = true;//TODO: take smoothing into consideration
|
||||
float minUKnot = this.getMinUNurbKnot();
|
||||
float maxUKnot = this.getMaxUNurbKnot();
|
||||
float deltaU = (maxUKnot - minUKnot) / uSegments;
|
||||
|
||||
float minVKnot = this.getMinVNurbKnot();
|
||||
float maxVKnot = this.getMaxVNurbKnot();
|
||||
float deltaV = (maxVKnot - minVKnot) / vSegments;
|
||||
|
||||
Vector3f[] vertices = new Vector3f[(uSegments + 1) * (vSegments + 1)];
|
||||
|
||||
float u = minUKnot, v = minVKnot;
|
||||
int arrayIndex = 0;
|
||||
|
||||
for (int i = 0; i <= vSegments; ++i) {
|
||||
for (int j = 0; j <= uSegments; ++j) {
|
||||
Vector3f interpolationResult = new Vector3f();
|
||||
CurveAndSurfaceMath.interpolate(u, v, controlPoints, knots, basisUFunctionDegree, basisVFunctionDegree, interpolationResult);
|
||||
vertices[arrayIndex++] = interpolationResult;
|
||||
u += deltaU;
|
||||
}
|
||||
u = minUKnot;
|
||||
v += deltaV;
|
||||
}
|
||||
|
||||
//adding indexes
|
||||
int uVerticesAmount = uSegments + 1;
|
||||
int[] indices = new int[uSegments * vSegments * 6];
|
||||
arrayIndex = 0;
|
||||
for (int i = 0; i < vSegments; ++i) {
|
||||
for (int j = 0; j < uSegments; ++j) {
|
||||
indices[arrayIndex++] = j + i * uVerticesAmount;
|
||||
indices[arrayIndex++] = j + i * uVerticesAmount + 1;
|
||||
indices[arrayIndex++] = j + i * uVerticesAmount + uVerticesAmount;
|
||||
indices[arrayIndex++] = j + i * uVerticesAmount + 1;
|
||||
indices[arrayIndex++] = j + i * uVerticesAmount + uVerticesAmount + 1;
|
||||
indices[arrayIndex++] = j + i * uVerticesAmount + uVerticesAmount;
|
||||
}
|
||||
}
|
||||
|
||||
//normalMap merges normals of faces that will be rendered smooth
|
||||
Map<Vector3f, Vector3f> normalMap = new HashMap<Vector3f, Vector3f>(vertices.length);
|
||||
for (int i = 0; i < indices.length; i += 3) {
|
||||
Vector3f n = FastMath.computeNormal(vertices[indices[i]], vertices[indices[i + 1]], vertices[indices[i + 2]]);
|
||||
this.addNormal(n, normalMap, smooth, vertices[indices[i]], vertices[indices[i + 1]], vertices[indices[i + 2]]);
|
||||
}
|
||||
//preparing normal list (the order of normals must match the order of vertices)
|
||||
float[] normals = new float[vertices.length * 3];
|
||||
arrayIndex = 0;
|
||||
for (int i = 0; i < vertices.length; ++i) {
|
||||
Vector3f n = normalMap.get(vertices[i]);
|
||||
normals[arrayIndex++] = n.x;
|
||||
normals[arrayIndex++] = n.y;
|
||||
normals[arrayIndex++] = n.z;
|
||||
}
|
||||
|
||||
this.setBuffer(VertexBuffer.Type.Position, 3, BufferUtils.createFloatBuffer(vertices));
|
||||
this.setBuffer(VertexBuffer.Type.Index, 3, indices);
|
||||
this.setBuffer(VertexBuffer.Type.Normal, 3, normals);
|
||||
this.updateBound();
|
||||
this.updateCounts();
|
||||
}
|
||||
|
||||
public List<List<Vector4f>> getControlPoints() {
|
||||
return controlPoints;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method returns the amount of U control points.
|
||||
* @return the amount of U control points
|
||||
*/
|
||||
public int getUControlPointsAmount() {
|
||||
return controlPoints.size();
|
||||
}
|
||||
|
||||
/**
|
||||
* This method returns the amount of V control points.
|
||||
* @return the amount of V control points
|
||||
*/
|
||||
public int getVControlPointsAmount() {
|
||||
return controlPoints.get(0) == null ? 0 : controlPoints.get(0).size();
|
||||
}
|
||||
|
||||
/**
|
||||
* This method returns the degree of basis U function.
|
||||
* @return the degree of basis U function
|
||||
*/
|
||||
public int getBasisUFunctionDegree() {
|
||||
return basisUFunctionDegree;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method returns the degree of basis V function.
|
||||
* @return the degree of basis V function
|
||||
*/
|
||||
public int getBasisVFunctionDegree() {
|
||||
return basisVFunctionDegree;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method returns the knots for specified dimension (U knots - value: '0',
|
||||
* V knots - value: '1').
|
||||
* @param dim an integer specifying if the U or V knots are required
|
||||
* @return an array of knots
|
||||
*/
|
||||
public List<Float> getKnots(int dim) {
|
||||
return knots[dim];
|
||||
}
|
||||
|
||||
/**
|
||||
* This method returns the type of the surface.
|
||||
* @return the type of the surface
|
||||
*/
|
||||
public SplineType getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method returns the minimum nurb curve U knot value.
|
||||
* @return the minimum nurb curve knot value
|
||||
*/
|
||||
private float getMinUNurbKnot() {
|
||||
return knots[0].get(basisUFunctionDegree - 1);
|
||||
return knots[0].get(basisUFunctionDegree - 1);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This method returns the maximum nurb curve U knot value.
|
||||
* @return the maximum nurb curve knot value
|
||||
*/
|
||||
* This method returns the maximum nurb curve U knot value.
|
||||
* @return the maximum nurb curve knot value
|
||||
*/
|
||||
private float getMaxUNurbKnot() {
|
||||
return knots[0].get(knots[0].size() - basisUFunctionDegree);
|
||||
return knots[0].get(knots[0].size() - basisUFunctionDegree);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This method returns the minimum nurb curve U knot value.
|
||||
* @return the minimum nurb curve knot value
|
||||
*/
|
||||
* This method returns the minimum nurb curve U knot value.
|
||||
* @return the minimum nurb curve knot value
|
||||
*/
|
||||
private float getMinVNurbKnot() {
|
||||
return knots[1].get(basisVFunctionDegree - 1);
|
||||
return knots[1].get(basisVFunctionDegree - 1);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This method returns the maximum nurb curve U knot value.
|
||||
* @return the maximum nurb curve knot value
|
||||
*/
|
||||
* This method returns the maximum nurb curve U knot value.
|
||||
* @return the maximum nurb curve knot value
|
||||
*/
|
||||
private float getMaxVNurbKnot() {
|
||||
return knots[1].get(knots[1].size() - basisVFunctionDegree);
|
||||
return knots[1].get(knots[1].size() - basisVFunctionDegree);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This method adds a normal to a normals' map. This map is used to merge normals of a vertor that should be rendered smooth.
|
||||
* @param normalToAdd
|
||||
* a normal to be added
|
||||
* @param normalMap
|
||||
* merges normals of faces that will be rendered smooth; the key is the vertex and the value - its normal vector
|
||||
* @param smooth
|
||||
* the variable that indicates wheather to merge normals (creating the smooth mesh) or not
|
||||
* @param vertices
|
||||
* a list of vertices read from the blender file
|
||||
*/
|
||||
private void addNormal(Vector3f normalToAdd, Map<Vector3f, Vector3f> normalMap, boolean smooth, Vector3f... vertices) {
|
||||
for(Vector3f v : vertices) {
|
||||
Vector3f n = normalMap.get(v);
|
||||
if(!smooth || n == null) {
|
||||
normalMap.put(v, normalToAdd.clone());
|
||||
} else {
|
||||
n.addLocal(normalToAdd).normalizeLocal();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This method validates the input data. It throws {@link IllegalArgumentException} if
|
||||
* the data is invalid.
|
||||
* @param controlPoints space control points
|
||||
* @param nurbKnots knots of the surface
|
||||
* @param uSegments the amount of U segments
|
||||
* @param vSegments the amount of V segments
|
||||
*/
|
||||
private void validateInputData(List<List<Vector4f>> controlPoints, List<Float>[] nurbKnots,
|
||||
int uSegments, int vSegments) {
|
||||
int uPointsAmount = controlPoints.get(0).size();
|
||||
for(int i=1;i<controlPoints.size();++i) {
|
||||
if(controlPoints.get(i).size()!=uPointsAmount) {
|
||||
throw new IllegalArgumentException("The amount of 'U' control points is invalid!");
|
||||
}
|
||||
}
|
||||
if(uSegments<=0) {
|
||||
throw new IllegalArgumentException("U segments amount should be positive!");
|
||||
}
|
||||
if(vSegments<0) {
|
||||
throw new IllegalArgumentException("V segments amount cannot be negative!");
|
||||
}
|
||||
if (nurbKnots.length != 2) {
|
||||
throw new IllegalArgumentException("Nurb surface should have two rows of knots!");
|
||||
}
|
||||
for (int i = 0; i < nurbKnots.length; ++i) {
|
||||
for (int j = 0; j < nurbKnots[i].size() - 1; ++j) {
|
||||
if (nurbKnots[i].get(j) > nurbKnots[i].get(j+1)) {
|
||||
throw new IllegalArgumentException("The knots' values cannot decrease!");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
* This method adds a normal to a normals' map. This map is used to merge normals of a vertor that should be rendered smooth.
|
||||
* @param normalToAdd
|
||||
* a normal to be added
|
||||
* @param normalMap
|
||||
* merges normals of faces that will be rendered smooth; the key is the vertex and the value - its normal vector
|
||||
* @param smooth
|
||||
* the variable that indicates wheather to merge normals (creating the smooth mesh) or not
|
||||
* @param vertices
|
||||
* a list of vertices read from the blender file
|
||||
*/
|
||||
private void addNormal(Vector3f normalToAdd, Map<Vector3f, Vector3f> normalMap, boolean smooth, Vector3f... vertices) {
|
||||
for (Vector3f v : vertices) {
|
||||
Vector3f n = normalMap.get(v);
|
||||
if (!smooth || n == null) {
|
||||
normalMap.put(v, normalToAdd.clone());
|
||||
} else {
|
||||
n.addLocal(normalToAdd).normalizeLocal();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This method validates the input data. It throws {@link IllegalArgumentException} if
|
||||
* the data is invalid.
|
||||
* @param controlPoints space control points
|
||||
* @param nurbKnots knots of the surface
|
||||
* @param uSegments the amount of U segments
|
||||
* @param vSegments the amount of V segments
|
||||
*/
|
||||
private void validateInputData(List<List<Vector4f>> controlPoints, List<Float>[] nurbKnots,
|
||||
int uSegments, int vSegments) {
|
||||
int uPointsAmount = controlPoints.get(0).size();
|
||||
for (int i = 1; i < controlPoints.size(); ++i) {
|
||||
if (controlPoints.get(i).size() != uPointsAmount) {
|
||||
throw new IllegalArgumentException("The amount of 'U' control points is invalid!");
|
||||
}
|
||||
}
|
||||
if (uSegments <= 0) {
|
||||
throw new IllegalArgumentException("U segments amount should be positive!");
|
||||
}
|
||||
if (vSegments < 0) {
|
||||
throw new IllegalArgumentException("V segments amount cannot be negative!");
|
||||
}
|
||||
if (nurbKnots.length != 2) {
|
||||
throw new IllegalArgumentException("Nurb surface should have two rows of knots!");
|
||||
}
|
||||
for (int i = 0; i < nurbKnots.length; ++i) {
|
||||
for (int j = 0; j < nurbKnots[i].size() - 1; ++j) {
|
||||
if (nurbKnots[i].get(j) > nurbKnots[i].get(j + 1)) {
|
||||
throw new IllegalArgumentException("The knots' values cannot decrease!");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -153,13 +153,9 @@ public class Torus extends Mesh {
|
||||
float sinPhi = FastMath.sin(phi);
|
||||
tempNormal.set(radialAxis).multLocal(cosPhi);
|
||||
tempNormal.z += sinPhi;
|
||||
if (true)
|
||||
fnb.put(tempNormal.x).put(tempNormal.y).put(
|
||||
tempNormal.z);
|
||||
else
|
||||
fnb.put(-tempNormal.x).put(-tempNormal.y)
|
||||
.put(-tempNormal.z);
|
||||
|
||||
fnb.put(tempNormal.x).put(tempNormal.y).put(
|
||||
tempNormal.z);
|
||||
|
||||
tempNormal.multLocal(innerRadius).addLocal(torusMiddle);
|
||||
fpb.put(tempNormal.x).put(tempNormal.y).put(
|
||||
tempNormal.z);
|
||||
|
@ -286,6 +286,7 @@ public class PssmShadowRenderer implements SceneProcessor {
|
||||
this.direction.set(direction).normalizeLocal();
|
||||
}
|
||||
|
||||
@SuppressWarnings("fallthrough")
|
||||
public void postQueue(RenderQueue rq) {
|
||||
GeometryList occluders = rq.getShadowQueueContent(ShadowMode.Cast);
|
||||
if (occluders.size() == 0)
|
||||
@ -317,6 +318,8 @@ public class PssmShadowRenderer implements SceneProcessor {
|
||||
shadowCam.updateViewProjection();
|
||||
|
||||
PssmShadowUtil.updateFrustumSplits(splitsArray, viewCam.getFrustumNear(), zFar, lambda);
|
||||
|
||||
|
||||
switch (splitsArray.length){
|
||||
case 5:
|
||||
splits.a = splitsArray[4];
|
||||
|
@ -82,6 +82,7 @@ import java.util.logging.Logger;
|
||||
//import org.lwjgl.opengl.ARBVertexArrayObject;
|
||||
//import org.lwjgl.opengl.ARBHalfFloatVertex;
|
||||
//import org.lwjgl.opengl.ARBVertexArrayObject;
|
||||
//import jme3tools.converters.MipMapGenerator;
|
||||
import org.lwjgl.opengl.ARBDrawBuffers;
|
||||
//import org.lwjgl.opengl.ARBDrawInstanced;
|
||||
import org.lwjgl.opengl.ARBDrawInstanced;
|
||||
@ -168,6 +169,7 @@ public class LwjglRenderer implements Renderer {
|
||||
return caps;
|
||||
}
|
||||
|
||||
@SuppressWarnings("fallthrough")
|
||||
public void initialize() {
|
||||
ContextCapabilities ctxCaps = GLContext.getCapabilities();
|
||||
if (ctxCaps.OpenGL20) {
|
||||
@ -1514,6 +1516,7 @@ public class LwjglRenderer implements Renderer {
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("fallthrough")
|
||||
private void setupTextureParams(Texture tex) {
|
||||
Image image = tex.getImage();
|
||||
int target = convertTextureType(tex.getType(), image != null ? image.getMultiSamples() : 1);
|
||||
@ -1618,6 +1621,8 @@ public class LwjglRenderer implements Renderer {
|
||||
|| img.getWidth() != img.getHeight()){
|
||||
logger.log(Level.WARNING, "Encountered NPOT texture {0}, "
|
||||
+ "it might not display correctly.", img);
|
||||
|
||||
//MipMapGenerator.resizeToPowerOf2(img);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user