Hey there,
I want to create a growing fading Sphere. I have a solution how to create a growing Sphere with keyframes but I have no clue how make it fading …
I didn't find a similar problem in the tutorials or in the forum. My idea was to set the material of the starting and ending sphere, but i only managed to set the material of the morphing sphere. Anyone has an idea?
my code:
...
TriMesh growingSphere = loadGrowingSphere();
this.attachChild(growingSphere);
...
}
private TriMesh loadGrowingSphere(){
/** Create a ZBuffer to display pixels closest to the camera above farther ones. */
ZBufferState buf = DisplaySystem.getDisplaySystem("LWJGL").getRenderer().createZBufferState();
buf.setEnabled(true);
buf.setFunction(ZBufferState.TestFunction.LessThanOrEqualTo);
// StartSphere
TriMesh startSphere=new Sphere("beginning explosion",position,15,15,0.5f);
// Null colors,normals,textures because they aren't being updated
startSphere.setColorBuffer(null);
startSphere.setNormalBuffer(null);
//startSphere.setRenderState(this.getTextureForSphere("gras.jpg"));
//startSphere.setRenderState(buf);
//startSphere.updateRenderState();
startSphere.setTextureCoords((ArrayList<TexCoords>)null);
// Die Endexplosion
TriMesh finalSphere=new Sphere("ending explosion",position,15,15,radius);
finalSphere.setColorBuffer(null);
finalSphere.setNormalBuffer(null);
//finalSphere.setRenderState(this.getTextureForSphere("gras.jpg"));
//finalSphere.setRenderState(buf);
//finalSphere.updateRenderState();
finalSphere.setTextureCoords((ArrayList<TexCoords>)null);
TriMesh renderedObject=new Sphere("Rendered Object",position,15,15,radius);
this.attachChild(renderedObject);
//
// Create my KeyframeController
KeyframeController kc=new KeyframeController();
// Assign the object I'll be changing
kc.setMorphingMesh(renderedObject);
// Assign for a time, what my renderedObject will look like
kc.setKeyframe(0,startSphere);
kc.setKeyframe(lifeTimeOfAnimation,finalSphere);
kc.setRepeatType(Controller.RT_CLAMP);
//setTexture
renderedObject.setRenderState(getTextureForSphere("gras.jpg"));
renderedObject.setRenderState(buf);
renderedObject.updateRenderState();
// Add the controller to my object
renderedObject.addController(kc);
return renderedObject;
}
private TextureState getTextureForSphere(String name){
// Point to the monkey image
URL monkeyLoc = Explosion.class.getClassLoader().getResource(
"data/textures/"+name);
// Get my TextureState
TextureState ts = DisplaySystem.getDisplaySystem("LWJGL").getRenderer().createTextureState();
// Get my Texture
Texture t = TextureManager.loadTexture(monkeyLoc,
Texture.MinificationFilter.BilinearNearestMipMap,
Texture.MagnificationFilter.Bilinear);
// Set a wrap for my texture so it repeats
t.setWrap(Texture.WrapMode.Repeat);
// Set the texture to the TextureState
ts.setTexture(t);
return ts;
}
Thanks for your anwers!!