2 * Copyright (c) 2003-2009 jMonkeyEngine
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
12 * * Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * * Neither the name of 'jMonkeyEngine' nor the names of its contributors
17 * may be used to endorse or promote products derived from this software
18 * without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 package com.jme.scene.shape;
35 import java.nio.FloatBuffer;
37 import com.jme.math.Vector3f;
38 import com.jme.scene.TexCoords;
39 import com.jme.scene.TriMesh;
40 import com.jme.util.geom.BufferUtils;
43 * A box made from a strip mode tri-mesh.
46 * @author Joshua Slack (conversion from Box to StripBox)
47 * @version $Revision$, $Date$
49 public class StripBox extends AbstractBox {
51 private static final long serialVersionUID = 1L;
53 /** <strong>NOT API:</strong> for internal use, do not call from user code. */
59 * Constructor instantiates a new <code>StripBox</code> object. Center and
60 * vertice information must be supplied later.
63 * the name of the scene element. This is required for
64 * identification and comparision purposes.
66 public StripBox(String name) {
71 * Constructor instantiates a new <code>StripBox</code> object. The minimum and
72 * maximum point are provided. These two points define the shape and size of
73 * the box, but not it's orientation or position. You should use the
74 * <code>setLocalTranslation</code> and <code>setLocalRotation</code>
75 * for those attributes.
78 * the name of the scene element. This is required for
79 * identification and comparision purposes.
81 * the minimum point that defines the box.
83 * the maximum point that defines the box.
85 public StripBox(String name, Vector3f min, Vector3f max) {
87 updateGeometry(min, max);
91 * Constructs a new box. The box has the given center and extends in the x,
92 * y, and z out from the center (+ and -) by the given amounts. So, for
93 * example, a box with extent of .5 would be the unit cube.
100 * x extent of the box, in both directions.
102 * y extent of the box, in both directions.
104 * z extent of the box, in both directions.
106 public StripBox(String name, Vector3f center, float xExtent, float yExtent,
109 updateGeometry(center, xExtent, yExtent, zExtent);
112 protected void duUpdateGeometryVertices() {
113 setVertexBuffer(BufferUtils.createVector3Buffer(getVertexBuffer(), 8));
114 Vector3f[] vert = computeVertices(); // returns 8
115 getVertexBuffer().clear();
116 getVertexBuffer().put(vert[0].x).put(vert[0].y).put(vert[0].z);
117 getVertexBuffer().put(vert[1].x).put(vert[1].y).put(vert[1].z);
118 getVertexBuffer().put(vert[2].x).put(vert[2].y).put(vert[2].z);
119 getVertexBuffer().put(vert[3].x).put(vert[3].y).put(vert[3].z);
120 getVertexBuffer().put(vert[4].x).put(vert[4].y).put(vert[4].z);
121 getVertexBuffer().put(vert[5].x).put(vert[5].y).put(vert[5].z);
122 getVertexBuffer().put(vert[6].x).put(vert[6].y).put(vert[6].z);
123 getVertexBuffer().put(vert[7].x).put(vert[7].y).put(vert[7].z);
126 protected void duUpdateGeometryNormals() {
127 Vector3f[] vert = computeVertices(); // returns 8
128 setNormalBuffer(BufferUtils.createVector3Buffer(getNormalBuffer(), 8));
129 Vector3f norm = new Vector3f();
131 getNormalBuffer().clear();
132 for (int i = 0; i < 8; i++) {
133 norm.set(vert[i]).normalizeLocal();
134 getNormalBuffer().put(norm.x).put(norm.y).put(norm.z);
138 protected void duUpdateGeometryTextures() {
139 if (getTextureCoords().get(0) == null) {
140 getTextureCoords().set(0,new TexCoords(BufferUtils.createVector2Buffer(24)));
141 FloatBuffer tex = getTextureCoords().get(0).coords;
142 tex.put(1).put(0); //0
143 tex.put(0).put(0); //1
144 tex.put(0).put(1); //2
145 tex.put(1).put(1); //3
146 tex.put(1).put(0); //4
147 tex.put(0).put(0); //5
148 tex.put(1).put(1); //6
149 tex.put(0).put(1); //7
153 protected void duUpdateGeometryIndices() {
154 setMode(TriMesh.Mode.Strip);
155 if (getIndexBuffer() == null) {
156 int[] indices = { 1, 0, 4, 5, 7, 0, 3, 1, 2, 4, 6, 7, 2, 3 };
157 setIndexBuffer(BufferUtils.createIntBuffer(indices));
162 * Creates a new StripBox object containing the same data as this one.
164 * @return the new StripBox
166 public StripBox clone() {
167 return new StripBox(getName() + "_clone",
168 (Vector3f) center.clone(),
169 xExtent, yExtent, zExtent);