The issue was reported at https://code.google.com/p/jmonkeyengine/issues/detail?id=635
While the presence of WireBox.fromBoundingBox() suggests that this class can be used to debug bounding boxes, the current implementation always generates a box centered on the origin.
For reusability, I think meshes should generally be origin-centered (with offsets specified in the Geometry). However, this seems like a case where users can reasonably expect to specify an offset center.
In order to preserve the existing updatePositions(float, float, float) interface, the center must be stored in a field, which requires overriding Mesh.read() and Mesh.write(). I took the liberty of adding a constructor which specifies the center. Here is the proposed replacement for the existing /branches/gradle-restructure/jme3-core/src/main/java/com/jme3/scene/debug/WireBox.java and /trunk/engine/src/core/com/jme3/scene/debug/WireBox.java :
[java]
/*
- Copyright Ā© 2009-2012 jMonkeyEngine
- All rights reserved.
- Redistribution and use in source and binary forms, with or without
- modification, are permitted provided that the following conditions are
- met:
-
- Redistributions of source code must retain the above copyright
- notice, this list of conditions and the following disclaimer.
-
- Redistributions in binary form must reproduce the above copyright
- notice, this list of conditions and the following disclaimer in the
- documentation and/or other materials provided with the distribution.
-
- Neither the name of ājMonkeyEngineā nor the names of its contributors
- may be used to endorse or promote products derived from this software
- without specific prior written permission.
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- āAS ISā AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
- TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
- CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.jme3.scene.debug;
import com.jme3.bounding.BoundingBox;
import com.jme3.export.InputCapsule;
import com.jme3.export.JmeExporter;
import com.jme3.export.JmeImporter;
import com.jme3.export.OutputCapsule;
import com.jme3.math.Vector3f;
import com.jme3.scene.Mesh;
import com.jme3.scene.VertexBuffer;
import com.jme3.scene.VertexBuffer.Format;
import com.jme3.scene.VertexBuffer.Type;
import com.jme3.scene.VertexBuffer.Usage;
import com.jme3.util.BufferUtils;
import java.io.IOException;
import java.nio.FloatBuffer;
public class WireBox extends Mesh {
Vector3f center;
public WireBox() {
this(1f, 1f, 1f);
}
public WireBox(float xRadius, float yRadius, float zRadius) {
this(Vector3f.ZERO, xRadius, yRadius, zRadius);
}
public WireBox(Vector3f center, float xRadius, float yRadius, float zRadius) {
super();
this.center = center.clone();
updatePositions(xRadius, yRadius, zRadius);
setBuffer(Type.Index, 2,
new short[]{
0, 1,
1, 2,
2, 3,
3, 0,
4, 5,
5, 6,
6, 7,
7, 4,
0, 4,
1, 5,
2, 6,
3, 7
});
setMode(Mesh.Mode.Lines);
updateCounts();
}
public void fromBoundingBox(BoundingBox bbox) {
center.set(bbox.getCenter());
updatePositions(bbox.getXExtent(), bbox.getYExtent(), bbox.getZExtent());
}
@Override
public void read(JmeImporter importer) throws IOException {
super.read(importer);
InputCapsule in = importer.getCapsule(this);
center = (Vector3f) in.readSavable("center", Vector3f.ZERO.clone());
}
public void updatePositions(float xRadius, float yRadius, float zRadius) {
VertexBuffer vertexBuffer = getBuffer(Type.Position);
FloatBuffer floatBuffer;
if (vertexBuffer == null) {
vertexBuffer = new VertexBuffer(Type.Position);
floatBuffer = BufferUtils.createVector3Buffer(8);
vertexBuffer.setupData(Usage.Dynamic, 3, Format.Float, floatBuffer);
setBuffer(vertexBuffer);
} else {
floatBuffer = (FloatBuffer) vertexBuffer.getData();
vertexBuffer.updateData(floatBuffer);
}
floatBuffer.rewind();
float xHigh = center.x + xRadius;
float yHigh = center.y + yRadius;
float zHigh = center.z + zRadius;
float xLow = center.x - xRadius;
float yLow = center.y - yRadius;
float zLow = center.z - zRadius;
floatBuffer.put(new float[]{
xLow, yLow, zHigh,
xHigh, yLow, zHigh,
xHigh, yHigh, zHigh,
xLow, yHigh, zHigh,
xLow, yLow, zLow,
xHigh, yLow, zLow,
xHigh, yHigh, zLow,
xLow, yHigh, zLow
});
updateBound();
}
@Override
public void write(JmeExporter exporter) throws IOException {
super.write(exporter);
OutputCapsule out = exporter.getCapsule(this);
out.write(center, "center", null);
}
}
[/java]