geometry.java
来自「java 3d game jme 工程开发源代码」· Java 代码 · 共 943 行 · 第 1/3 页
JAVA
943 行
vertQuantity = 0;
}
/**
* Set the fog coordinates buffer. This should have the vertex count entries
*
* @param fogBuf The fog buffer to use in this geometry
*/
public void setFogCoordBuffer(FloatBuffer fogBuf) {
this.fogBuf = fogBuf;
}
/**
* The fog depth coord buffer
*
* @return The per vertex depth values for fog coordinates
*/
public FloatBuffer getFogBuffer() {
return fogBuf;
}
/**
* <code>getNormalBuffer</code> retrieves this geometry's normal
* information as a float buffer.
*
* @return the float buffer containing the geometry information.
*/
public FloatBuffer getNormalBuffer() {
return normBuf;
}
/**
* <code>setNormalBuffer</code> sets this geometry's normals via a float
* buffer consisting of groups of three floats: x,y and z.
*
* @param normBuf
* the new normal buffer.
*/
public void setNormalBuffer(FloatBuffer normBuf) {
this.normBuf = normBuf;
}
/**
* <code>getColorBufferfer</code> retrieves the float buffer that contains
* this geometry's color information.
*
* @return the buffer that contains this geometry's color information.
*/
public FloatBuffer getColorBuffer() {
return colorBuf;
}
/**
* <code>setColorBuffer</code> sets this geometry's colors via a float
* buffer consisting of groups of four floats: r,g,b and a.
*
* @param colorBuf
* the new color buffer.
*/
public void setColorBuffer(FloatBuffer colorBuf) {
this.colorBuf = colorBuf;
}
/**
* <code>copyTextureCoords</code> copys the texture coordinates of a given
* texture unit to another location. If the texture unit is not valid, then
* the coordinates are ignored. Coords are multiplied by the given factor.
*
* @param fromIndex
* the coordinates to copy.
* @param toIndex
* the texture unit to set them to.
* @param factor
* a multiple to apply when copying
*/
public void copyTextureCoordinates(int fromIndex, int toIndex, float factor) {
if (texBuf == null)
return;
if (fromIndex < 0 || fromIndex >= texBuf.size()
|| texBuf.get(fromIndex) == null) {
return;
}
if (toIndex < 0 || toIndex == fromIndex) {
return;
}
// make sure we are big enough
while (toIndex >= texBuf.size()) {
texBuf.add(null);
}
TexCoords dest = texBuf.get(toIndex);
TexCoords src = texBuf.get(fromIndex);
if (dest == null || dest.coords.capacity() != src.coords.limit()) {
dest = new TexCoords(BufferUtils.createFloatBuffer(src.coords.capacity()), src.perVert);
texBuf.set(toIndex, dest);
}
dest.coords.clear();
int oldLimit = src.coords.limit();
src.coords.clear();
for (int i = 0, len = dest.coords.capacity(); i < len; i++) {
dest.coords.put(factor * src.coords.get());
}
src.coords.limit(oldLimit);
dest.coords.limit(oldLimit);
if (vboInfo != null) {
vboInfo.resizeTextureIds(this.texBuf.size());
}
checkTextureCoordinates();
}
/**
* <code>getTextureBuffers</code> retrieves this geometry's texture
* information contained within a float buffer array.
*
* @return the float buffers that contain this geometry's texture
* information.
*/
public ArrayList<TexCoords> getTextureCoords() {
return texBuf;
}
/**
* <code>getTextureAsFloatBuffer</code> retrieves the texture buffer of a
* given texture unit.
*
* @param textureUnit
* the texture unit to check.
* @return the texture coordinates at the given texture unit.
*/
public TexCoords getTextureCoords(int textureUnit) {
if (texBuf == null)
return null;
if (textureUnit >= texBuf.size())
return null;
return texBuf.get(textureUnit);
}
/**
* <code>setTextureBuffer</code> sets this geometry's textures (position
* 0) via a float buffer. This convenience method assumes we are setting
* coordinates for texture unit 0 and that there are 2 coordinate values per
* vertex.
*
* @param coords
* the new coords for unit 0.
*/
public void setTextureCoords(TexCoords coords) {
setTextureCoords(coords, 0);
}
/**
* <code>setTextureBuffer</code> sets this geometry's textures at the
* position given via a float buffer. This convenience method assumes that
* there are 2 coordinate values per vertex.
*
* @param coords
* the new coords.
* @param unit
* the texture unit we are providing coordinates for.
*/
public void setTextureCoords(TexCoords coords, int unit) {
while (unit >= texBuf.size()) {
texBuf.add(null);
}
texBuf.set(unit, coords);
if (vboInfo != null) {
vboInfo.resizeTextureIds(texBuf.size());
}
checkTextureCoordinates();
}
/**
* Clears all vertex, normal, texture, and color buffers by setting them to
* null.
*/
public void clearBuffers() {
reconstruct(null, null, null, null);
}
/**
* <code>updateBound</code> recalculates the bounding object assigned to
* the geometry. This resets it parameters to adjust for any changes to the
* vertex information.
*/
public void updateModelBound() {
if (bound != null && getVertexBuffer() != null) {
bound.computeFromPoints(getVertexBuffer());
updateWorldBound();
}
}
/**
* <code>setModelBound</code> sets the bounding object for this geometry.
*
* @param modelBound
* the bounding object for this geometry.
*/
public void setModelBound(BoundingVolume modelBound) {
this.worldBound = null;
this.bound = modelBound;
}
/**
* <code>draw</code> prepares the geometry for rendering to the display.
* The renderstate is set and the subclass is responsible for rendering the
* actual data.
*
* @see com.jme.scene.Spatial#draw(com.jme.renderer.Renderer)
* @param r
* the renderer that displays to the context.
*/
@Override
public void draw(Renderer r) {
}
/**
* <code>updateWorldBound</code> updates the bounding volume that contains
* this geometry. The location of the geometry is based on the location of
* all this node's parents.
*
* @see com.jme.scene.Spatial#updateWorldBound()
*/
public void updateWorldBound() {
if (bound != null) {
worldBound = bound.transform(getWorldRotation(),
getWorldTranslation(), getWorldScale(), worldBound);
}
}
/**
* <code>applyRenderState</code> determines if a particular render state
* is set for this Geometry. If not, the default state will be used.
*/
@Override
protected void applyRenderState(Stack<? extends RenderState>[] states) {
for (int x = 0; x < states.length; x++) {
if (states[x].size() > 0) {
this.states[x] = ((RenderState) states[x].peek()).extract(
states[x], this);
} else {
this.states[x] = Renderer.defaultStateList[x];
}
}
}
/**
* sorts the lights based on distance to geometry bounding volume
*/
public void sortLights() {
if (lightState != null && lightState.getLightList().size() > LightState.MAX_LIGHTS_ALLOWED) {
LightUtil.sort(this, lightState.getLightList());
}
}
/**
* <code>randomVertex</code> returns a random vertex from the list of
* vertices set to this geometry. If there are no vertices set, null is
* returned.
*
* @param fill
* a Vector3f to fill with the results. If null, one is created.
* It is more efficient to pass in a nonnull vector.
* @return Vector3f a random vertex from the vertex list. Null is returned
* if the vertex list is not set.
*/
public Vector3f randomVertex(Vector3f fill) {
if (getVertexBuffer() == null)
return null;
int i = (int) (FastMath.nextRandomFloat() * getVertexCount());
if (fill == null)
fill = new Vector3f();
BufferUtils.populateFromBuffer(fill, getVertexBuffer(), i);
localToWorld(fill, fill);
return fill;
}
/**
* Check if this geom intersects the ray if yes add it to the results.
*
* @param ray
* ray to check intersection with. The direction of the ray must
* be normalized (length 1).
* @param results
* result list
*/
@Override
public void findPick(Ray ray, PickResults results) {
if (getWorldBound() == null || !isCollidable) {
return;
}
if (getWorldBound().intersects(ray)) {
// find the triangle that is being hit.
// add this node and the triangle to the PickResults list.
results.addPick(ray, this);
}
}
/**
* <code>setDefaultColor</code> sets the color to be used if no per vertex
* color buffer is set.
*
* @param color
*/
public void setDefaultColor(ColorRGBA color) {
defaultColor = color;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?