How do I Apply Decal Texture to an Object

I am trying to load a texture onto an object as a decal (one side only).  For instance, loading a face onto a head.  How do I set the location of the decal texture and how do I apply it to the object?



Here is the code that I've tried so far which doesn't seem to work.

  // just for a test - load a texture
            Node clone = ...
            java.net.URL loc = BaseTable.class.getClassLoader().getResource("texture/facialFeatures.png");
            Texture texture = TextureManager.loadTexture(loc, Texture.MinificationFilter.BilinearNoMipMaps, Texture.MagnificationFilter.Bilinear);
            texture.setApply(Texture.ApplyMode.Decal);
            TextureState ts = DisplaySystem.getDisplaySystem().getRenderer().createTextureState();
            ts.setTexture(texture,0);
            clone.setRenderState(ts);



Thanks

The ApplyMode just defines how the color of the texture will be handled.



I think you want to look into texture splatting or projected textures.

I tried splatting but that doesn't seem to be working.  Am I doing something wrong?  Is there a difference between splatting and projection?



Here is the code below.

         
                java.net.URL loc = BaseTable.class.getClassLoader().getResource("texture/facialFeatures.png");
                Texture t0 = TextureManager.loadTexture(loc,
                Texture.MinificationFilter.Trilinear,
                Texture.MagnificationFilter.Bilinear);
                t0.setApply(Texture.ApplyMode.Decal);
                TextureState ts = DisplaySystem.getDisplaySystem().getRenderer().createTextureState();
                 ts.setTexture(t0, 0);
           
                 PassNode splattingPassNode = new PassNode("SplatPassNode");
                 splattingPassNode.attachChild(clone);

                 PassNodeState passNodeState = new PassNodeState();
                 passNodeState.setPassState(ts);
                 splattingPassNode.addPass(passNodeState);
                // performance
                splattingPassNode.lockBounds();
                splattingPassNode.lockTransforms();
                splattingPassNode.lockShadows();
                splattingPassNode.setCullHint(Spatial.CullHint.Dynamic);
                clone.attachChild(splattingPassNode);

Can you explain more on what kind of object you want to apply the texture ?

Is it a simple Box, a model or terrain.

If its a model i guess the best way would be to set the correct texture coordiantes in a 3d modeller.

So I am trying to create a Nintendo Mii loader.  Once I get most of the loading code finished, I plan on open sourcing it via source forge (since that's where I have all my open source projects).



Basically the face (freckles, mouth, nose, etc) are textures.  So in order to provide the diversity that Nintendo does, I need to be able to add the texture based on the mii file. 



Note, I'm using http://www.myavatareditor.com/ as a reference and currently am only loading the XML format provided by this site.  After I get things working with the XML, then I'll add the binary mii files.

So basically, I want to apply a texture to a loaded object (.obj).  Currently I am trying to load a texture onto a head (sort of spherical).



Can anyone help me with this?



Thanks

In the xml file are x and y coordinates for the eyes for example, i guess you have to translate these somehow into texture corrdiantes for the head?

Your are correct.  There is also a rotation option on some of the components.

I've created a lookup table for the components and colors (color 4 might correspond to yellow for instance).  So what I don't know how to do is to load up textures from a file and add them as a decal to a model.

I should be open sourcing the project soon (this is in relation to a scale program I'm working on that records your weight from the wii balance board, keeps track of it, and graphs it out).  The 3D avatar code will be included so I'll post back once I have a sourceforge project created.

In the xml file are x and y coordinates for the eyes for example, i guess you have to translate these somehow into texture corrdiantes for the head?

http://www.myavatareditor.com/developers.html#avatarxml


  <Eye>
    <type>30</type>
    <color>4</color>
    <x>5</x>
    <y>10</y>
    <size>2</size>
    <rotation>1</rotation>
  </Eye>



i don't really know much about modelling/texturing  tho, hopefully someone else can help you. :)

Note, the project is now open source'd (GPLv3) on sourceforge