www.jpct.net
jPCT - a 3d engine for Java => Support => Topic started by: samreid on October 13, 2009, 08:18:14 am
-
Hi, it's my first 60 minutes with jPCT and I'm trying to use the software renderer to create a cube where each face has a different shade, like this (without the text)
(http://3.bp.blogspot.com/_stlK0ynJdqE/R7xdMhFmmjI/AAAAAAAAACA/50l3S_WfKLE/s400/cubebutton.bmp)
But when I use the HelloWorldSoftware, with this new initialization:
world = new World();
world.addLight( new SimpleVector( 30,30,30),Color.yellow );
TextureManager.getInstance().addTexture("box", new Texture(64,64, Color.red));
box = Primitives.getBox(13f, 2f);
box.setTexture("box");
box.setEnvmapped(Object3D.ENVMAP_ENABLED);
box.build();
world.addObject(box);
The object doesn't seem to have well defined edges, and comes out looking like this:
(http://www.colorado.edu/physics/phet/dev/temp/jpct/cube-jpct.png)
I also tried putting the light at (0,0,30), but that looked qualitatively similar. What's the easiest/best way to do this?
Also, is there a way to highlight the edges of a cube; for example, to have them appear with a dark outline?
Thanks,
Sam Reid
-
Actually, the results you are getting is what is wanted in most cases. Your example image shows some flat shading instead. You can simulate this in jPCT by calling setShadingMode(Object3D.SHADING_FAKED_FLAT); It's not real flat shading, but it should look similar. About the outlines: There are basically two options...either bake the outlines into the textures or use a separate object that defines the outlines.
-
Thanks for your quick response. I tried using SHADING_FAKED_FLAT, and obtained the desired results. It took a couple of tries to configure the light source so that it looked reasonable. Here's a screenshot:
(http://www.colorado.edu/physics/phet/dev/temp/jpct/jpct-flat-shading.png)
And the modified HelloWorldSoftware example code that was used to produce it:
package edu.colorado.phet.densityjava.view.jpct;
import java.awt.*;
import com.threed.jpct.*;
import javax.swing.*;
public class HelloJPCT {
private World world;
private FrameBuffer buffer;
private Object3D box;
private JFrame frame;
public static void main(String[] args) throws Exception {
new HelloJPCT().loop();
}
public HelloJPCT() throws Exception {
frame=new JFrame("Hello world");
frame.setSize(800, 600);
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
world = new World();
world.addLight( new SimpleVector( -20,-5,-25),Color.gray );
TextureManager.getInstance().addTexture("box", new Texture(64,64, Color.red));
box = Primitives.getBox(1f, 2f);
box.setTexture("box");
box.setEnvmapped(Object3D.ENVMAP_ENABLED);
box.setShadingMode( Object3D.SHADING_FAKED_FLAT );
box.build();
world.addObject(box);
world.getCamera().setPosition(5, -5, -2);
world.getCamera().lookAt(box.getTransformedCenter());
}
private void loop() throws Exception {
buffer = new FrameBuffer(800, 600, FrameBuffer.SAMPLINGMODE_NORMAL);
while (frame.isShowing()) {
box.rotateY(0.01f);
buffer.clear(java.awt.Color.BLUE);
world.renderScene(buffer);
world.draw(buffer);
buffer.update();
buffer.display(frame.getGraphics());
Thread.sleep(10);
}
buffer.disableRenderer(IRenderer.RENDERER_OPENGL);
buffer.dispose();
frame.dispose();
System.exit(0);
}
}
Thanks again,
Sam Reid