Hello, to all
I’ve been working for a while in a project, and this is the only thing is driving me crazy…
Sorry if this is obvious for JME Gurus, but i’ve tried to figure out what is wrong in here but i’ve failed miserably.
Here is my problem.
I’m working on a “Logic Circuit Simulator” using JME, all models are imported from Blender, Circuit Components have a Symbol which have a “Lighting.j3md” material applied when component receive a signal it glows (Using post filter) all is working as I expect for the components but I’m having problems with the wires.
Wire material is the same:Lighting.j3md
The wires are created using custom method, which is using “A*” algorithm to create path from initial component to final component, this line is made by vertices that this algorithm returns, when line is finished is drawn using the color from parent component , my problem is this color is not applied correctly on whole line, sometimes line is totally black, and sometimes it has some of the color it should have, and sometimes is rendered with the real color…
I really do not know where is the problem here is how it looks graphically:
You can see what I mean with material not being applied to all line…
If I move the components to other positions then some of the lines are rendered correctly but also some of them have this black patch:
Here is the code for custom line creation:
[java]
/**
-
This method will create wire from initial node until final node
-
if reWire is true, it will “re-make” the actual wire to a new
-
geometry keeping the same wire node.
*/public synchronized void createWire(boolean reWire)
{
//
//
// This previous calculation will compensate the component position and also will
// compensate Cirucuit board position
//
Vector3f realLocation=initialPin.getWorldTranslation().add((Vector3f)initialPin.getUserData(“Location”));
initialPinLocation=realLocation.subtract(getOffsetVector());
Vector3f realLocation1=finalPin.getWorldTranslation().add((Vector3f)finalPin.getUserData(“Location”));
finalPinLocation=realLocation1.subtract(getOffsetVector());Vector3f wirePath[]=calculateWirePath(); if (wirePath==null) { return; } Vector3f initialSegment=new Vector3f(wirePath[0].x-0.1f,wirePath[0].y,wirePath[0].z); Vector3f finalSegment=new Vector3f(wirePath[wirePath.length-1].x+0.1f,wirePath[wirePath.length-1].y,wirePath[wirePath.length-1].z); wirePath[0]=initialSegment; wirePath[wirePath.length-1]=finalSegment; int numIndexes = 2 * wirePath.length; int numLines = numIndexes / 2; int padding = 0; int[] indexes = new int[numIndexes]; for (int i = 0; i < numLines - padding; i++) { indexes[2 * i] = i; indexes[2 * i + 1] = (i + 1) % numLines; } Mesh wireMesh = new Mesh(); wireMesh.setMode(Mesh.Mode.Lines); wireMesh.setLineWidth(5.0f); wireMesh.setBuffer(VertexBuffer.Type.Position, 3,BufferUtils.createFloatBuffer(wirePath)); wireMesh.setBuffer(VertexBuffer.Type.Index, 3, indexes); wireMesh.updateBound(); wireMesh.updateCounts(); // if it's a re-draw of wire I need to delete the old one. // Node existingWireNode=(Node)baseCircuitBoard.getChild(getWireName()); if (reWire && existingWireNode!=null) { setWireGeometry(null); existingWireNode.detachChildNamed("GEOM:"+getWireName()); } Geometry lineGeometry = new Geometry("GEOM:"+getWireName(), wireMesh); Material lineMaterial = new Material(assetManager,"Common/MatDefs/Light/Lighting.j3md"); lineMaterial.setBoolean("UseMaterialColors", true); if (getWireSignal()!=0) { lineMaterial.setColor("GlowColor", getWireColor()); } else { lineMaterial.setColor("GlowColor", ColorRGBA.Black); } lineMaterial.setColor("Ambient", getWireColor()); lineMaterial.setColor("Diffuse", getWireColor());
// lineMaterial.setReceivesShadows(false);
lineGeometry.setMaterial(lineMaterial);
lineGeometry.setMesh(wireMesh);
setWireGeometry(lineGeometry);
if (reWire && existingWireNode!=null)
{
// if is an existing wire, just attach new Geometry
existingWireNode.attachChild(lineGeometry);
// addNewWire(getWireName(),this);
}
else
{
Node nwire=new Node();
nwire.setName(getWireName());
nwire.attachChild(lineGeometry);
baseCircuitBoard.attachChild(nwire);
}
CircuitComponent iNode=getInitialComponent();
CircuitComponent fNode=getFinalComponent();
setWireSignal(iNode.getOutputSignalFromPin(initialPin.getName()));
fNode.setInputPinSignal(this.getFinalPinName(), getWireSignal());
}
[/java]
And here is code for the scene setup, I’m using a single light source:
[java]
/**
-
Setup Scene
*/
private void setupScene()
{
// Setting up scene
// Disable flying camera
float frustumSize = 15;
flyCam.setDragToRotate(false);
flyCam.setEnabled(false);cam.setParallelProjection(true);
float aspect = (float) cam.getWidth() / cam.getHeight();
cam.setFrustum(-1000, 1000, -aspect * frustumSize, aspect * frustumSize, frustumSize, -frustumSize);
cam.lookAt(new Vector3f(0f,0f,-35f), Vector3f.UNIT_Z);
//cam.lookAt(new Vector3f(0f,-35f,0f), Vector3f.UNIT_Y);// Setup Lighting
DirectionalLight sun = new DirectionalLight();
sun.setColor(ColorRGBA.White);
sun.setDirection(new Vector3f(-.5f,-.5f,-.5f).normalizeLocal());
// AmbientLight al=new AmbientLight();
// al.setColor(ColorRGBA.White.mult(0.5f));// Setup default camera position
cam.setLocation(new Vector3f(0f,0f,0f));
// rootNode.addLight(al);
rootNode.addLight(sun);
rootNode.setCullHint(CullHint.Never);
}
[/java]
So any help is welcomed…
Thanks