Main Menu
Menu

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.

Show posts Menu

Messages - tomzwo

#1
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)?
#2
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?
#3
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):


// 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));
             myObject.setTexture(tmp);
           }
         }
// ja: zuweisen
         else
           myObjcet.setTexture(tmp);
}


the identifying string is quite easy (normal X11-Style)

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

   tmp = Integer.toHexString(this.red);
   rv += (tmp.length() >= 2 ? "" : "0") + tmp;
   tmp = Integer.toHexString(this.green);
   rv += (tmp.length() >= 2 ? "" : "0") + tmp;
   tmp = Integer.toHexString(this.blue);
   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


 public InputStream createPngImageStream(Image img)
 {
   if(img == null)
     return(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;
   
   for(n=0;n<width*height;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);
   return(img);
 }



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

I found the PngEncoder mentioned at http://www.chemaxon.com/marvin/doc/user/PngEncoder.java (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)
#4
Support / VertexController
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
#5
Support / VertexController
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();

Regards
#6
Support / VertexController
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 http://www.jpct.net/forum/viewtopic.php?t=58&sid=32df672d03d554c73d05aea39064604e

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]);
tmp.build();
NUScale scaler = new NUScale(this, middle);
if(tmp.getMesh().setVertexController(scaler, IVertexController.PRESERVE_SOURCE_MESH) == false)
         return(null);

// ....

public class NUScale extends GenericVertexController
{
//...
 public void apply()
 {
   env.debug("NUScale.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