Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.

Messages - tomzwo

Pages: [1]
Support / Applying Colors to Objects - a possible solution
« on: March 12, 2005, 01:50:09 pm »
basically its a simple object editor integrated into a (web) shop system: customers are able to configure products from a set of components and order them. 3D is the icing on the cake in order to give them an idea of the result. Depending on my customer, I'll post a link as soon as it's online and I'm allowed to...

have you thought about my question (edged in different color)?

Support / Applying Colors to Objects - a possible solution
« on: March 10, 2005, 10:12:10 am »
and... while we're at it, there's a question I have, too: how can I display object edges in a different color (if it's possible at all) - meaning something like a mixture of wireframe and solid model in order to be able to view objects more clearly?

Support / Applying Colors to Objects - a possible solution
« on: March 10, 2005, 10:10:27 am »
JPCT documentation states that objects may have textures (handled by the singleton TextureManager) - and that's it, full stop.

In a gaming environment this is all very well (since game artefacts and levels have to be designed via tools or similar) and in sophisticated object management scenarios, too - but in a simple situation you might want to be able to apply colors programmatically. At least, I wanted to...

The solution I found is based on TextureManager's ability to load from a stream (some code parts omitted):

Code: [Select]

// we have a color associated with an object (in this case within another class)
if(this.theColor != null)
// create identifying string (see below)
String tmp = new colorHelper(this.theColor).x11String();
// do we have the texture ?
          if(txman.containsTexture(tmp) == false)
// create the texture - see below
            InputStream in;
            if((in = cr.createTexture(this.theColor)) != null)
              txman.addTexture(tmp, new Texture(in));
// ja: zuweisen

the identifying string is quite easy (normal X11-Style)
Code: [Select]

  public String x11String() {
    String rv = "#";
    String tmp;

    tmp = Integer.toHexString(;
    rv += (tmp.length() >= 2 ? "" : "0") + tmp;
    tmp = Integer.toHexString(;
    rv += (tmp.length() >= 2 ? "" : "0") + tmp;
    tmp = Integer.toHexString(;
    rv += (tmp.length() >= 2 ? "" : "0") + tmp;
    return(new String(rv));

so far, nothing special - let's have a look at the creating method (this does not really match the call above, since my classes are a little more complicated) - createTexture is basically a call to createPngImageStream below with createImage and a fixed size of 8x8 which is perfectly sufficient

Code: [Select]

  public InputStream createPngImageStream(Image img)
    if(img == null)
    PngEncoder enc = new PngEncoder(img);
    byte[] results = enc.pngEncode();
    return(new ByteArrayInputStream(results));

  public Image createImage(int width, int height, Color color)
    int[] pixels = new int[width * height];
    int n;
      pixels[n] = color.getRGB();
    return(this.createImage(width, height, pixels));

  private Image createImage(int width, int height, int[] pixels)
    DirectColorModel cm = new DirectColorModel(32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000);
    MemoryImageSource prod = new MemoryImageSource(width, height, cm, pixels, 0, width);

// durch das Toolkit sind wir von Komponenten unabhaengig
    Toolkit tk = Toolkit.getDefaultToolkit();
    Image img = tk.createImage(prod);

(the code above could be simplified for demonstration purposes, but - frankly - I do not feel like it)

I found the PngEncoder mentioned at (the encoder there is GPL'ed); in its original version a few things have to be deleted from the source code (just calls to a progress displaying object). I'm using this encoder because my application needs to run in Java 1.1 environments - for Java 2 the builtin encoder methods might be a better idea.

Of course, this is somewhat crude - maybe a future version of TextureManager might be able to read from an Image...? (pretty please)

Also: this has not been tested outside my development environment so far (JDK 1.4.2 / Windows). I'll post updates as soon as I know more.

Comments welcome.

Of course, using a different algorithm for the pixel array, it is possible to create bit-patterned multicolor thingies (I do this, too)

Support / VertexController
« on: March 10, 2005, 08:55:44 am »
tried it and it works like a charm (exactly as you described it) - thank you very much.

Regarding the color thingy: see other post

Support / VertexController
« on: March 09, 2005, 07:34:32 pm »
that explains a lot (I might have fond it had I looked closely at the Mesh documentation...) I'll try it first thing tomorrow.

Did I get this right: applying VertexController Things and other transformations go together quite well? That would make things very easy: translate and rotate with the standard methods - (btw: being able to set the rotation pivot spot is very useful) and do some non-uniform scaling with VertexController.

Something else: I found a - in my eyes - rather smart solution for the obstacle of not being able to apply colors to objects. Interested, anyone? if(InterestList.length > 0) postExample();


Support / VertexController
« on: March 09, 2005, 04:08:04 pm »
Since I need non-uniform scaling, I implemented a simple vertex controller based on the sample found under

However, the apply() method gets never called (I check this via some System.out.println()). Contrary to the mentioned sample, I use this not with a  plane but with a cylinder.

source parts:

Object3D tmp = new Object3D(source[n]);;
NUScale scaler = new NUScale(this, middle);
if(tmp.getMesh().setVertexController(scaler, IVertexController.PRESERVE_SOURCE_MESH) == false)

// ....

public class NUScale extends GenericVertexController
  public void apply()
// ...

(never mind that the source looks strange - I've omitted a few things)

While we're at it: a few more questions on VertexControllers (please forgive me if some answers may be found elsewhere):

- what about other modifications applied to the object (i.e. translate() and rotate()) - are they reflected into the mesh/normals? if so, what is the order?

- are the vector coordinates in sourceMesh / sourceNormals world-coordinates or object-coordinates?

Thanks in advance

Pages: [1]