corrections to com.jme3.scene.* comments as discussed at http://hub.jmonkeyengine.org/forum/topic/typos-in-com-jme3-scene/
parent
5372cb505d
commit
4a69eee64f
@ -1,314 +1,316 @@ |
|||||||
/* |
/* |
||||||
* Copyright (c) 2009-2012 jMonkeyEngine |
* Copyright (c) 2009-2012 jMonkeyEngine |
||||||
* All rights reserved. |
* All rights reserved. |
||||||
* |
* |
||||||
* Redistribution and use in source and binary forms, with or without |
* Redistribution and use in source and binary forms, with or without |
||||||
* modification, are permitted provided that the following conditions are |
* modification, are permitted provided that the following conditions are |
||||||
* met: |
* met: |
||||||
* |
* |
||||||
* * Redistributions of source code must retain the above copyright |
* * Redistributions of source code must retain the above copyright |
||||||
* notice, this list of conditions and the following disclaimer. |
* notice, this list of conditions and the following disclaimer. |
||||||
* |
* |
||||||
* * Redistributions in binary form must reproduce the above copyright |
* * Redistributions in binary form must reproduce the above copyright |
||||||
* notice, this list of conditions and the following disclaimer in the |
* notice, this list of conditions and the following disclaimer in the |
||||||
* documentation and/or other materials provided with the distribution. |
* documentation and/or other materials provided with the distribution. |
||||||
* |
* |
||||||
* * Neither the name of 'jMonkeyEngine' nor the names of its contributors |
* * Neither the name of 'jMonkeyEngine' nor the names of its contributors |
||||||
* may be used to endorse or promote products derived from this software |
* may be used to endorse or promote products derived from this software |
||||||
* without specific prior written permission. |
* without specific prior written permission. |
||||||
* |
* |
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
||||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED |
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED |
||||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
||||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR |
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR |
||||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
||||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
||||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
||||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
||||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
||||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
||||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||||||
*/ |
*/ |
||||||
package com.jme3.scene.shape; |
package com.jme3.scene.shape; |
||||||
|
|
||||||
import com.jme3.math.CurveAndSurfaceMath; |
import com.jme3.math.CurveAndSurfaceMath; |
||||||
import com.jme3.math.FastMath; |
import com.jme3.math.FastMath; |
||||||
import com.jme3.math.Spline.SplineType; |
import com.jme3.math.Spline.SplineType; |
||||||
import com.jme3.math.Vector3f; |
import com.jme3.math.Vector3f; |
||||||
import com.jme3.math.Vector4f; |
import com.jme3.math.Vector4f; |
||||||
import com.jme3.scene.Mesh; |
import com.jme3.scene.Mesh; |
||||||
import com.jme3.scene.VertexBuffer; |
import com.jme3.scene.VertexBuffer; |
||||||
import com.jme3.util.BufferUtils; |
import com.jme3.util.BufferUtils; |
||||||
import java.util.HashMap; |
import java.util.HashMap; |
||||||
import java.util.List; |
import java.util.List; |
||||||
import java.util.Map; |
import java.util.Map; |
||||||
|
|
||||||
/** |
/** |
||||||
* This class represents a surface described by knots, weights and control points. |
* This class represents a surface described by knots, weights and control points. |
||||||
* Currently the following types are supported: |
* Currently the following types are supported: |
||||||
* a) NURBS |
* a) NURBS |
||||||
* @author Marcin Roguski (Kealthas) |
* @author Marcin Roguski (Kealthas) |
||||||
*/ |
*/ |
||||||
public class Surface extends Mesh { |
public class Surface extends Mesh { |
||||||
|
|
||||||
private SplineType type; //the type of the surface
|
private SplineType type; //the type of the surface
|
||||||
private List<List<Vector4f>> controlPoints; //space control points and their weights
|
private List<List<Vector4f>> controlPoints; //space control points and their weights
|
||||||
private List<Float>[] knots; //knots of the surface
|
private List<Float>[] knots; //knots of the surface
|
||||||
private int basisUFunctionDegree; //the degree of basis U function
|
private int basisUFunctionDegree; //the degree of basis U function
|
||||||
private int basisVFunctionDegree; //the degree of basis V function
|
private int basisVFunctionDegree; //the degree of basis V function
|
||||||
private int uSegments; //the amount of U segments
|
private int uSegments; //the amount of U segments
|
||||||
private int vSegments; //the amount of V segments
|
private int vSegments; //the amount of V segments
|
||||||
|
|
||||||
/** |
/** |
||||||
* Constructor. Constructs required surface. |
* Constructor. Constructs required surface. |
||||||
* @param controlPoints space control points |
* @param controlPoints space control points |
||||||
* @param nurbKnots knots of the surface |
* @param nurbKnots knots of the surface |
||||||
* @param uSegments the amount of U segments |
* @param uSegments the amount of U segments |
||||||
* @param vSegments the amount of V segments |
* @param vSegments the amount of V segments |
||||||
* @param basisUFunctionDegree the degree of basis U function |
* @param basisUFunctionDegree the degree of basis U function |
||||||
* @param basisVFunctionDegree the degree of basis V function |
* @param basisVFunctionDegree the degree of basis V function |
||||||
*/ |
*/ |
||||||
private Surface(List<List<Vector4f>> controlPoints, List<Float>[] nurbKnots, |
private Surface(List<List<Vector4f>> controlPoints, List<Float>[] nurbKnots, |
||||||
int uSegments, int vSegments, int basisUFunctionDegree, int basisVFunctionDegree) { |
int uSegments, int vSegments, int basisUFunctionDegree, int basisVFunctionDegree) { |
||||||
this.validateInputData(controlPoints, nurbKnots, uSegments, vSegments); |
this.validateInputData(controlPoints, nurbKnots, uSegments, vSegments); |
||||||
this.type = SplineType.Nurb; |
this.type = SplineType.Nurb; |
||||||
this.uSegments = uSegments; |
this.uSegments = uSegments; |
||||||
this.vSegments = vSegments; |
this.vSegments = vSegments; |
||||||
this.controlPoints = controlPoints; |
this.controlPoints = controlPoints; |
||||||
this.knots = nurbKnots; |
this.knots = nurbKnots; |
||||||
this.basisUFunctionDegree = basisUFunctionDegree; |
this.basisUFunctionDegree = basisUFunctionDegree; |
||||||
CurveAndSurfaceMath.prepareNurbsKnots(nurbKnots[0], basisUFunctionDegree); |
CurveAndSurfaceMath.prepareNurbsKnots(nurbKnots[0], basisUFunctionDegree); |
||||||
if (nurbKnots[1] != null) { |
if (nurbKnots[1] != null) { |
||||||
this.basisVFunctionDegree = basisVFunctionDegree; |
this.basisVFunctionDegree = basisVFunctionDegree; |
||||||
CurveAndSurfaceMath.prepareNurbsKnots(nurbKnots[1], basisVFunctionDegree); |
CurveAndSurfaceMath.prepareNurbsKnots(nurbKnots[1], basisVFunctionDegree); |
||||||
} |
} |
||||||
|
|
||||||
this.buildSurface(); |
this.buildSurface(); |
||||||
} |
} |
||||||
|
|
||||||
/** |
/** |
||||||
* This method creates a NURBS surface. |
* This method creates a NURBS surface. |
||||||
* @param controlPoints space control points |
* @param controlPoints space control points |
||||||
* @param nurbKnots knots of the surface |
* @param nurbKnots knots of the surface |
||||||
* @param uSegments the amount of U segments |
* @param uSegments the amount of U segments |
||||||
* @param vSegments the amount of V segments |
* @param vSegments the amount of V segments |
||||||
* @param basisUFunctionDegree the degree of basis U function |
* @param basisUFunctionDegree the degree of basis U function |
||||||
* @param basisVFunctionDegree the degree of basis V function |
* @param basisVFunctionDegree the degree of basis V function |
||||||
* @return an instance of NURBS surface |
* @return an instance of NURBS surface |
||||||
*/ |
*/ |
||||||
public static final Surface createNurbsSurface(List<List<Vector4f>> controlPoints, List<Float>[] nurbKnots, |
public static final Surface createNurbsSurface(List<List<Vector4f>> controlPoints, List<Float>[] nurbKnots, |
||||||
int uSegments, int vSegments, int basisUFunctionDegree, int basisVFunctionDegree) { |
int uSegments, int vSegments, int basisUFunctionDegree, int basisVFunctionDegree) { |
||||||
Surface result = new Surface(controlPoints, nurbKnots, uSegments, vSegments, basisUFunctionDegree, basisVFunctionDegree); |
Surface result = new Surface(controlPoints, nurbKnots, uSegments, vSegments, basisUFunctionDegree, basisVFunctionDegree); |
||||||
result.type = SplineType.Nurb; |
result.type = SplineType.Nurb; |
||||||
return result; |
return result; |
||||||
} |
} |
||||||
|
|
||||||
/** |
/** |
||||||
* This method creates the surface. |
* This method creates the surface. |
||||||
*/ |
*/ |
||||||
private void buildSurface() { |
private void buildSurface() { |
||||||
boolean smooth = true;//TODO: take smoothing into consideration
|
boolean smooth = true;//TODO: take smoothing into consideration
|
||||||
float minUKnot = this.getMinUNurbKnot(); |
float minUKnot = this.getMinUNurbKnot(); |
||||||
float maxUKnot = this.getMaxUNurbKnot(); |
float maxUKnot = this.getMaxUNurbKnot(); |
||||||
float deltaU = (maxUKnot - minUKnot) / uSegments; |
float deltaU = (maxUKnot - minUKnot) / uSegments; |
||||||
|
|
||||||
float minVKnot = this.getMinVNurbKnot(); |
float minVKnot = this.getMinVNurbKnot(); |
||||||
float maxVKnot = this.getMaxVNurbKnot(); |
float maxVKnot = this.getMaxVNurbKnot(); |
||||||
float deltaV = (maxVKnot - minVKnot) / vSegments; |
float deltaV = (maxVKnot - minVKnot) / vSegments; |
||||||
|
|
||||||
Vector3f[] vertices = new Vector3f[(uSegments + 1) * (vSegments + 1)]; |
Vector3f[] vertices = new Vector3f[(uSegments + 1) * (vSegments + 1)]; |
||||||
|
|
||||||
float u = minUKnot, v = minVKnot; |
float u = minUKnot, v = minVKnot; |
||||||
int arrayIndex = 0; |
int arrayIndex = 0; |
||||||
|
|
||||||
for (int i = 0; i <= vSegments; ++i) { |
for (int i = 0; i <= vSegments; ++i) { |
||||||
for (int j = 0; j <= uSegments; ++j) { |
for (int j = 0; j <= uSegments; ++j) { |
||||||
Vector3f interpolationResult = new Vector3f(); |
Vector3f interpolationResult = new Vector3f(); |
||||||
CurveAndSurfaceMath.interpolate(u, v, controlPoints, knots, basisUFunctionDegree, basisVFunctionDegree, interpolationResult); |
CurveAndSurfaceMath.interpolate(u, v, controlPoints, knots, basisUFunctionDegree, basisVFunctionDegree, interpolationResult); |
||||||
vertices[arrayIndex++] = interpolationResult; |
vertices[arrayIndex++] = interpolationResult; |
||||||
u += deltaU; |
u += deltaU; |
||||||
} |
} |
||||||
u = minUKnot; |
u = minUKnot; |
||||||
v += deltaV; |
v += deltaV; |
||||||
} |
} |
||||||
|
|
||||||
//adding indexes
|
//adding indexes
|
||||||
int uVerticesAmount = uSegments + 1; |
int uVerticesAmount = uSegments + 1; |
||||||
int[] indices = new int[uSegments * vSegments * 6]; |
int[] indices = new int[uSegments * vSegments * 6]; |
||||||
arrayIndex = 0; |
arrayIndex = 0; |
||||||
for (int i = 0; i < vSegments; ++i) { |
for (int i = 0; i < vSegments; ++i) { |
||||||
for (int j = 0; j < uSegments; ++j) { |
for (int j = 0; j < uSegments; ++j) { |
||||||
indices[arrayIndex++] = j + i * uVerticesAmount; |
indices[arrayIndex++] = j + i * uVerticesAmount; |
||||||
indices[arrayIndex++] = j + i * uVerticesAmount + 1; |
indices[arrayIndex++] = j + i * uVerticesAmount + 1; |
||||||
indices[arrayIndex++] = j + i * uVerticesAmount + uVerticesAmount; |
indices[arrayIndex++] = j + i * uVerticesAmount + uVerticesAmount; |
||||||
indices[arrayIndex++] = j + i * uVerticesAmount + 1; |
indices[arrayIndex++] = j + i * uVerticesAmount + 1; |
||||||
indices[arrayIndex++] = j + i * uVerticesAmount + uVerticesAmount + 1; |
indices[arrayIndex++] = j + i * uVerticesAmount + uVerticesAmount + 1; |
||||||
indices[arrayIndex++] = j + i * uVerticesAmount + uVerticesAmount; |
indices[arrayIndex++] = j + i * uVerticesAmount + uVerticesAmount; |
||||||
} |
} |
||||||
} |
} |
||||||
|
|
||||||
//normalMap merges normals of faces that will be rendered smooth
|
//normalMap merges normals of faces that will be rendered smooth
|
||||||
Map<Vector3f, Vector3f> normalMap = new HashMap<Vector3f, Vector3f>(vertices.length); |
Map<Vector3f, Vector3f> normalMap = new HashMap<Vector3f, Vector3f>(vertices.length); |
||||||
for (int i = 0; i < indices.length; i += 3) { |
for (int i = 0; i < indices.length; i += 3) { |
||||||
Vector3f n = FastMath.computeNormal(vertices[indices[i]], vertices[indices[i + 1]], vertices[indices[i + 2]]); |
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]]); |
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)
|
//preparing normal list (the order of normals must match the order of vertices)
|
||||||
float[] normals = new float[vertices.length * 3]; |
float[] normals = new float[vertices.length * 3]; |
||||||
arrayIndex = 0; |
arrayIndex = 0; |
||||||
for (int i = 0; i < vertices.length; ++i) { |
for (int i = 0; i < vertices.length; ++i) { |
||||||
Vector3f n = normalMap.get(vertices[i]); |
Vector3f n = normalMap.get(vertices[i]); |
||||||
normals[arrayIndex++] = n.x; |
normals[arrayIndex++] = n.x; |
||||||
normals[arrayIndex++] = n.y; |
normals[arrayIndex++] = n.y; |
||||||
normals[arrayIndex++] = n.z; |
normals[arrayIndex++] = n.z; |
||||||
} |
} |
||||||
|
|
||||||
this.setBuffer(VertexBuffer.Type.Position, 3, BufferUtils.createFloatBuffer(vertices)); |
this.setBuffer(VertexBuffer.Type.Position, 3, BufferUtils.createFloatBuffer(vertices)); |
||||||
this.setBuffer(VertexBuffer.Type.Index, 3, indices); |
this.setBuffer(VertexBuffer.Type.Index, 3, indices); |
||||||
this.setBuffer(VertexBuffer.Type.Normal, 3, normals); |
this.setBuffer(VertexBuffer.Type.Normal, 3, normals); |
||||||
this.updateBound(); |
this.updateBound(); |
||||||
this.updateCounts(); |
this.updateCounts(); |
||||||
} |
} |
||||||
|
|
||||||
public List<List<Vector4f>> getControlPoints() { |
public List<List<Vector4f>> getControlPoints() { |
||||||
return controlPoints; |
return controlPoints; |
||||||
} |
} |
||||||
|
|
||||||
/** |
/** |
||||||
* This method returns the amount of U control points. |
* This method returns the amount of U control points. |
||||||
* @return the amount of U control points |
* @return the amount of U control points |
||||||
*/ |
*/ |
||||||
public int getUControlPointsAmount() { |
public int getUControlPointsAmount() { |
||||||
return controlPoints.size(); |
return controlPoints.size(); |
||||||
} |
} |
||||||
|
|
||||||
/** |
/** |
||||||
* This method returns the amount of V control points. |
* This method returns the amount of V control points. |
||||||
* @return the amount of V control points |
* @return the amount of V control points |
||||||
*/ |
*/ |
||||||
public int getVControlPointsAmount() { |
public int getVControlPointsAmount() { |
||||||
return controlPoints.get(0) == null ? 0 : controlPoints.get(0).size(); |
return controlPoints.get(0) == null ? 0 : controlPoints.get(0).size(); |
||||||
} |
} |
||||||
|
|
||||||
/** |
/** |
||||||
* This method returns the degree of basis U function. |
* This method returns the degree of basis U function. |
||||||
* @return the degree of basis U function |
* @return the degree of basis U function |
||||||
*/ |
*/ |
||||||
public int getBasisUFunctionDegree() { |
public int getBasisUFunctionDegree() { |
||||||
return basisUFunctionDegree; |
return basisUFunctionDegree; |
||||||
} |
} |
||||||
|
|
||||||
/** |
/** |
||||||
* This method returns the degree of basis V function. |
* This method returns the degree of basis V function. |
||||||
* @return the degree of basis V function |
* @return the degree of basis V function |
||||||
*/ |
*/ |
||||||
public int getBasisVFunctionDegree() { |
public int getBasisVFunctionDegree() { |
||||||
return basisVFunctionDegree; |
return basisVFunctionDegree; |
||||||
} |
} |
||||||
|
|
||||||
/** |
/** |
||||||
* This method returns the knots for specified dimension (U knots - value: '0', |
* This method returns the knots for specified dimension (U knots - value: '0', |
||||||
* V knots - value: '1'). |
* V knots - value: '1'). |
||||||
* @param dim an integer specifying if the U or V knots are required |
* @param dim an integer specifying if the U or V knots are required |
||||||
* @return an array of knots |
* @return an array of knots |
||||||
*/ |
*/ |
||||||
public List<Float> getKnots(int dim) { |
public List<Float> getKnots(int dim) { |
||||||
return knots[dim]; |
return knots[dim]; |
||||||
} |
} |
||||||
|
|
||||||
/** |
/** |
||||||
* This method returns the type of the surface. |
* This method returns the type of the surface. |
||||||
* @return the type of the surface |
* @return the type of the surface |
||||||
*/ |
*/ |
||||||
public SplineType getType() { |
public SplineType getType() { |
||||||
return type; |
return type; |
||||||
} |
} |
||||||
|
|
||||||
/** |
/** |
||||||
* This method returns the minimum nurb curve U knot value. |
* This method returns the minimum nurb curve U knot value. |
||||||
* @return the minimum nurb curve knot value |
* @return the minimum nurb curve knot value |
||||||
*/ |
*/ |
||||||
private float getMinUNurbKnot() { |
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. |
* This method returns the maximum nurb curve U knot value. |
||||||
* @return the maximum nurb curve knot value |
* @return the maximum nurb curve knot value |
||||||
*/ |
*/ |
||||||
private float getMaxUNurbKnot() { |
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. |
* This method returns the minimum nurb curve U knot value. |
||||||
* @return the minimum nurb curve knot value |
* @return the minimum nurb curve knot value |
||||||
*/ |
*/ |
||||||
private float getMinVNurbKnot() { |
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. |
* This method returns the maximum nurb curve U knot value. |
||||||
* @return the maximum nurb curve knot value |
* @return the maximum nurb curve knot value |
||||||
*/ |
*/ |
||||||
private float getMaxVNurbKnot() { |
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. |
* This method adds a normal to a normal's map. This map is used to merge |
||||||
* @param normalToAdd |
* normals of a vector that should be rendered smooth. |
||||||
* a normal to be added |
* |
||||||
* @param normalMap |
* @param normalToAdd |
||||||
* merges normals of faces that will be rendered smooth; the key is the vertex and the value - its normal vector |
* a normal to be added |
||||||
* @param smooth |
* @param normalMap |
||||||
* the variable that indicates wheather to merge normals (creating the smooth mesh) or not |
* merges normals of faces that will be rendered smooth; the key is the vertex and the value - its normal vector |
||||||
* @param vertices |
* @param smooth the variable that indicates whether to merge normals |
||||||
* a list of vertices read from the blender file |
* (creating the smooth mesh) or not |
||||||
*/ |
* @param vertices |
||||||
private void addNormal(Vector3f normalToAdd, Map<Vector3f, Vector3f> normalMap, boolean smooth, Vector3f... vertices) { |
* a list of vertices read from the blender file |
||||||
for (Vector3f v : vertices) { |
*/ |
||||||
Vector3f n = normalMap.get(v); |
private void addNormal(Vector3f normalToAdd, Map<Vector3f, Vector3f> normalMap, boolean smooth, Vector3f... vertices) { |
||||||
if (!smooth || n == null) { |
for (Vector3f v : vertices) { |
||||||
normalMap.put(v, normalToAdd.clone()); |
Vector3f n = normalMap.get(v); |
||||||
} else { |
if (!smooth || n == null) { |
||||||
n.addLocal(normalToAdd).normalizeLocal(); |
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 |
* This method validates the input data. It throws {@link IllegalArgumentException} if |
||||||
* @param nurbKnots knots of the surface |
* the data is invalid. |
||||||
* @param uSegments the amount of U segments |
* @param controlPoints space control points |
||||||
* @param vSegments the amount of V segments |
* @param nurbKnots knots of the surface |
||||||
*/ |
* @param uSegments the amount of U segments |
||||||
private void validateInputData(List<List<Vector4f>> controlPoints, List<Float>[] nurbKnots, |
* @param vSegments the amount of V segments |
||||||
int uSegments, int vSegments) { |
*/ |
||||||
int uPointsAmount = controlPoints.get(0).size(); |
private void validateInputData(List<List<Vector4f>> controlPoints, List<Float>[] nurbKnots, |
||||||
for (int i = 1; i < controlPoints.size(); ++i) { |
int uSegments, int vSegments) { |
||||||
if (controlPoints.get(i).size() != uPointsAmount) { |
int uPointsAmount = controlPoints.get(0).size(); |
||||||
throw new IllegalArgumentException("The amount of 'U' control points is invalid!"); |
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 (uSegments <= 0) { |
||||||
if (vSegments < 0) { |
throw new IllegalArgumentException("U segments amount should be positive!"); |
||||||
throw new IllegalArgumentException("V segments amount cannot be negative!"); |
} |
||||||
} |
if (vSegments < 0) { |
||||||
if (nurbKnots.length != 2) { |
throw new IllegalArgumentException("V segments amount cannot be negative!"); |
||||||
throw new IllegalArgumentException("Nurb surface should have two rows of knots!"); |
} |
||||||
} |
if (nurbKnots.length != 2) { |
||||||
for (int i = 0; i < nurbKnots.length; ++i) { |
throw new IllegalArgumentException("Nurb surface should have two rows of knots!"); |
||||||
for (int j = 0; j < nurbKnots[i].size() - 1; ++j) { |
} |
||||||
if (nurbKnots[i].get(j) > nurbKnots[i].get(j + 1)) { |
for (int i = 0; i < nurbKnots.length; ++i) { |
||||||
throw new IllegalArgumentException("The knots' values cannot decrease!"); |
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!"); |
||||||
} |
} |
||||||
} |
} |
||||||
} |
} |
||||||
|
} |
||||||
|
} |
||||||
|
Loading…
Reference in new issue