I am baffled beyond beyondness :)) or I’m just plain crazy
In the following code if I change the value 0.3f to 0.1f in the line marked with “XXX:” i.e. “static final float[] evilPos = { 0.3f” that line
there’s the blue rectangle flashing all the time and has 2 half circles inside it which move depending on the camera position
I added SPACE key to change this position between the two values 0.1f and 1f but it still flashes.
I have to stop the program, change the value back to 0.3f and then run it to see the rectangle being 100% filled blue and all right and pressing SPACE doesn’t change it…
I don’t understand what is happening O_o
Help ?
the code was taken from http://jmonkeyengine.googlecode.com/svn/branches/stable-alpha4/engine/src/test/jme3test/model/shape/TestCustomMesh.java which was a link on this page originally https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:advanced:custom_meshes
and I modified it to include only the parts that were causing the issue, or so I tried …to also isolate stuff thinking it’s due to missing .clone()s<br /> Upon attempting to take a screenie I noticed the rectangle switched between a rectangle 100% filled and a circle 100% filled blue contained inside the original rectangle, that is when value is 0.1f<br /> though I cannot take the screenshot when the circle appears O_o it's always capturing the 100% filled rectangle but as I said above upon moving camera the smallest bit the circle is distorted into 2 halves of a circle<br /> I also tried restarting eclipse (not running inside jmp) and running it again, thinking maybe some memory issues...<br /> ok I managed to capture both frames while running the program with 0.1f value,<br /> <img src='http://i.imgur.com/thdWt.png'>http://i.imgur.com/thdWt.png</img><br /> <img src='http://i.imgur.com/tfArh.png'>http://i.imgur.com/tfArh.png</img><br />
pre type=“java”`
/*
- Copyright (c) 2009-2010 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
- 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
- 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
- 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 org.jme3.tests;
import com.jme3.app.SimpleApplication;
import com.jme3.input.KeyInput;
import com.jme3.input.controls.ActionListener;
import com.jme3.input.controls.KeyTrigger;
import com.jme3.material.Material;
import com.jme3.math.ColorRGBA;
import com.jme3.math.Vector2f;
import com.jme3.math.Vector3f;
import com.jme3.scene.Geometry;
import com.jme3.scene.Mesh;
import com.jme3.scene.VertexBuffer.Type;
import com.jme3.util.BufferUtils;
/**
- How to create custom meshes by specifying vertices We render the mesh in
- three different ways, once with a solid blue color, once with vertex colors,
- and once with a wireframe material.
-
-
@author KayTrance
*/
public class TestCustomMesh extends SimpleApplication {
static final float[] evilPos = { 0.3f,// XXX: buggy Z pos, change this to
// 0.1f for buggy
1f, // fixed Z pos
};
short switcher = 0;
Geometry geoBlue;
public static void main(String[] args) {
TestCustomMesh app = new TestCustomMesh();
app.setShowSettings(false);
app.start();
}
private final String mapSwitchPos = “mapSwitchPos”;
@Override
public void simpleInitApp() {
flyCam.setMoveSpeed(20f);
cam.setLocation(new Vector3f(4, 4, 14));
makeBlue();
makePointy();
inputManager.addMapping(mapSwitchPos,
new KeyTrigger(KeyInput.KEY_SPACE));
inputManager.addListener(actionListener, mapSwitchPos);
}
// private final AnalogListener analogListener =
// new AnalogListener()
// {
//
// @Override
// public
// void
// onAnalog(
// String name,
// float value,
// float tpf )
// {
// Vector3f posNow =
// geoBlue.getLocalTranslation();
// geoBlue.setLocalTranslation(
// posNow.getX(),
// posNow.getY(),
// posNow.getZ()
// + value );
// }
// };
private final ActionListener actionListener = new ActionListener() {
@Override
public void onAction(String name, boolean isPressed, float tpf) {
if ((mapSwitchPos == name) && (isPressed)) {
Vector3f posNow = geoBlue.getLocalTranslation();
switcher++;
switcher %= evilPos.length;
geoBlue.setLocalTranslation(posNow.getX(), posNow.getY(),
evilPos[switcher]);
}
}
};
private void makeBlue() {
// Vertex positions in space
final Vector3f[] vertices = new Vector3f[4];
vertices[0] = new Vector3f(0, 0, 0);
vertices[1] = new Vector3f(3, 0, 0);
vertices[2] = new Vector3f(0, 3, 0);
vertices[3] = new Vector3f(3, 3, 0);
// Texture coordinates
final Vector2f[] texCoord = new Vector2f[4];
texCoord[0] = new Vector2f(0, 0);
texCoord[1] = new Vector2f(1, 0);
texCoord[2] = new Vector2f(0, 1);
texCoord[3] = new Vector2f(1, 1);
// Indexes. We define the order in which mesh should be constructed
final int[] indexes = { 2, 0, 1, 1, 3, 2 };
Mesh meshBlue = new Mesh();
// Setting buffers
meshBlue.setBuffer(Type.Position, 3,
BufferUtils.createFloatBuffer(vertices.clone()));
meshBlue.setBuffer(Type.TexCoord, 2,
BufferUtils.createFloatBuffer(texCoord.clone()));
meshBlue.setBuffer(Type.Index, 1,
BufferUtils.createIntBuffer(indexes.clone()));
meshBlue.updateBound();
// *************************************************************************
// First mesh uses one solid color
// *************************************************************************
// Creating a geometry, and apply a single color material to it
geoBlue = new Geometry(“OurMesh”, meshBlue.clone());
Material matBlue = new Material(assetManager,
“Common/MatDefs/Misc/Unshaded.j3md”);
matBlue.setColor(“Color”, ColorRGBA.Blue);
geoBlue.setMaterial(matBlue);
// Attaching our geometry to the root node.
geoBlue.setLocalTranslation(4, 4, 0.1f);
rootNode.attachChild(geoBlue);
}
private void makePointy() {
final Vector3f[] vertices = new Vector3f[4];
vertices[0] = new Vector3f(0, 0, 0);
vertices[1] = new Vector3f(3, 0, 0);
vertices[2] = new Vector3f(0, 3, 0);
vertices[3] = new Vector3f(3, 3, 0);
// Texture coordinates
final Vector2f[] texCoord = new Vector2f[4];
texCoord[0] = new Vector2f(0, 0);
texCoord[1] = new Vector2f(1, 0);
texCoord[2] = new Vector2f(0, 1);
texCoord[3] = new Vector2f(1, 1);
// Indexes. We define the order in which mesh should be constructed
final int[] indexes = { 2, 0, 1, 1, 3, 2 };
// *************************************************************************
// Second mesh uses vertex colors to color each vertex
// ***********************************************************************
// Mesh cMesh =
// m.clone();
// Geometry coloredMesh =
// new Geometry(
// “ColoredMesh”,
// cMesh );
Material matVC = new Material(assetManager,
“Common/MatDefs/Misc/Unshaded.j3md”);
matVC.setBoolean(“VertexColor”, true);
// We have 4 vertices and 4 color values for each of them.
// If you have more vertices, you need ‘new float[yourVertexCount * 4]’
// here!
final float[] colorArray = new float[4 * 4];
int colorIndex = 0;
// Set custom RGBA value for each Vertex. Values range from 0.0f to 1.0f
for (int i = 0; i < 4; i++) {
// Red value (is increased by .2 on each next vertex here)
colorArray[colorIndex++] = 0.1f + (.2f * i);
// Green value (is reduced by .2 on each next vertex)
colorArray[colorIndex++] = 0.9f - (0.2f * i);
// Blue value (remains the same in our case)
colorArray[colorIndex++] = 0.5f;
// Alpha value (no transparency set here)
colorArray[colorIndex++] = 1f;
}
// // Set the color buffer
// cMesh.setBuffer(
// Type.Color,
// 4,
// colorArray );
// coloredMesh.setMaterial( matVC );
// // move mesh a bit so that it doesn’t intersect with the first one
// coloredMesh.setLocalTranslation(
// 4,
// 0,
// 0 );
// rootNode.attachChild( coloredMesh );
// coloredMesh.setCullHint( CullHint.Never );
// / Alternatively, you can show the mesh vertixes as points
// * instead of coloring the faces. */
Mesh dMesh = new Mesh();
dMesh.setBuffer(Type.Position, 3,
BufferUtils.createFloatBuffer(vertices));
dMesh.setBuffer(Type.TexCoord, 2,
BufferUtils.createFloatBuffer(texCoord));
dMesh.setBuffer(Type.Index, 1, BufferUtils.createIntBuffer(indexes));
dMesh.updateBound();
dMesh.setBuffer(Type.Color, 4, colorArray);
dMesh.setMode(Mesh.Mode.Points);
dMesh.setPointSize(10f);
dMesh.updateBound();
dMesh.setStatic();
Geometry points = new Geometry(“Points”, dMesh);
points.setMaterial(matVC);
points.setLocalTranslation(0.1f, 4, evilPos[switcher]);
// Node n =
// new Node();
// n.attachChild( points );
rootNode.attachChild(points);
// *************************************************************************
// Third mesh will use a wireframe shader to show wireframe
// *************************************************************************
// Mesh wfMesh =
// m.clone();
// Geometry wfGeom =
// new Geometry(
// “wireframeGeometry”,
// wfMesh );
// Material matWireframe =
// new Material(
// assetManager,
// “Common/MatDefs/Misc/Unshaded.j3md” );
// matWireframe.setColor(
// “Color”,
// ColorRGBA.Green );
// matWireframe.getAdditionalRenderState().setWireframe(
// true );
// wfGeom.setMaterial( matWireframe );
// wfGeom.setLocalTranslation(
// 4,
// 4,
// 0 );
// rootNode.attachChild( wfGeom );
}
}
/pre