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 - cintix

#1
Support / Re: Project texture down on ground and objects
November 21, 2011, 05:30:34 PM
It worked like a charm!
I would say I love you Egon, but I'm sure you would ban me for declaring you a big a love statement..  ;-)

One last thing..
To get a really nice marking on the ground, would the right way not be to center the markerProjector over where the user is pointing with the mouse ?? I cant getting it to look really great.

I use this for the mouse


    /**
     *
     * @param world
     * @param cam
     * @param buffer
     * @return
     */
    public SimpleVector get3DCoordinate(World world, Camera cam, FrameBuffer buffer) {
        SimpleVector rezult = null;
        if (cam != null && buffer != null) {
            SimpleVector rayTemp = Interact2D.reproject2D3DWS(cam, buffer, getMouseX(), getMouseY()).normalize();
            float distance = world.calcMinDistance(cam.getPosition(), rayTemp, 20000);
            rezult = new SimpleVector(cam.getPosition());
            rayTemp.scalarMul(distance);
            rezult.add(rayTemp);
        }
        return rezult;
    }


It seems to work great, I tried setting the projector to the location and then moving the camera up.. not really working like i thought it would :(
#2
Support / Re: Project texture down on ground and objects
November 21, 2011, 03:19:21 PM
I tried adjusting the min/max Fov setting and as said the image looks better in size but still expands 4 corners to the side..
What it looks like

What the textures should look like


What i'm doing now..

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package markedworld;

import com.threed.jpct.Camera;
import com.threed.jpct.FrameBuffer;
import com.threed.jpct.IRenderer;
import com.threed.jpct.Interact2D;
import com.threed.jpct.Loader;
import com.threed.jpct.Object3D;
import com.threed.jpct.PolygonManager;
import com.threed.jpct.Projector;
import com.threed.jpct.SimpleVector;
import com.threed.jpct.Texture;
import com.threed.jpct.TextureInfo;
import com.threed.jpct.TextureManager;
import com.threed.jpct.World;
import com.threed.jpct.util.KeyMapper;
import com.threed.jpct.util.KeyState;
import com.threed.jpct.util.Light;
import com.threed.jpct.util.ShadowHelper;
import java.awt.Color;
import java.awt.event.KeyEvent;
import java.io.File;
import java.util.Enumeration;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;

/**
*
* @author migo
*/
class MarkedWorld {

    private World world;
    private FrameBuffer buffer;
    private Object3D ground, object;
    private Camera cam;
    private ShadowHelper sh;
    private Projector projector, markerProjector;
    private MouseMapper mouseMapper;
    private KeyMapper keyMapper;
    private Light sun;
    private boolean doLoop = true;
    private TextureManager tm = TextureManager.getInstance();
    private List<Object3D> model3DManager = new LinkedList<Object3D>();

    public static void main(String[] args)
            throws Exception {
        new MarkedWorld().loop();
    }

    public MarkedWorld() throws Exception {
        world = new World();
        world.setAmbientLight(50, 50, 50);

        Light light = new Light(world);
        light.setIntensity(255, 255, 255);
        light.setPosition(new SimpleVector(0, 0, -10));



        world.getCamera().setPosition(0, 0, -150);
    }

    private void loop() throws Exception {
        // default world
        world = new World();
        world.setAmbientLight(130, 130, 130);


        // new buffer
        buffer = new FrameBuffer(800, 600, FrameBuffer.SAMPLINGMODE_GL_AA_4X);
        buffer.disableRenderer(IRenderer.RENDERER_SOFTWARE);
        buffer.enableRenderer(IRenderer.RENDERER_OPENGL, IRenderer.RENDERER_OPENGL);
        projector = new Projector();
        projector.rotateX((float) Math.PI / 2f);
        projector.setFOVLimits(0, 2);
        projector.setFOV(2);

        markerProjector = new Projector();
        markerProjector.rotateX((float) Math.PI / 2f);
        markerProjector.setFOVLimits(0.2f, 0.5f);
        markerProjector.setFOV(0.4f);

        sh = new ShadowHelper(world, buffer, projector, 2048);
        sh.setCullingMode(false);
        sh.setAmbientLight(new Color(130, 130, 130));
        sh.setLightMode(true);
        sh.setBorder(1);

        // Initialize mappers

        mouseMapper = new MouseMapper(buffer);
        mouseMapper.hide();
        keyMapper = new KeyMapper();

        // Setup dynamic light source

        sun = new Light(world);
        sun.setIntensity(250, 250, 250);
        sun.setAttenuation(800);

        cam = world.getCamera();
        cam.moveCamera(Camera.CAMERA_MOVEOUT, 160);
        cam.moveCamera(Camera.CAMERA_MOVEUP, 120);
        cam.setFOV(1.5f);

        addTextures("textures/");
        ground = load3DS("ground.3ds", "models/ground.3ds");
        object = load3DS("object.3ds", "models/object.3ds");

        object.build();
        ground.build();

        model3DManager.add(object);
        model3DManager.add(ground);
       
        Texture cursor = tm.getTexture("cursor.png");

        // setMarker("groundmarker.png");

        for (Object3D md : model3DManager) {
            md.setRotationPivot(new SimpleVector(0, 0, 0));
        }

        ground.setTexture("Grass.JPG");

        world.addObject(ground);
        world.addObject(object);
       

        while (doLoop) {

            poll();
            if (ground != null) {
                projector.lookAt(ground.getTransformedCenter());
                markerProjector.lookAt(getAbsoluteCoordinate(world, world.getCamera(), buffer, mouseMapper.getMouseX(), mouseMapper.getMouseY()));
            }
            projector.moveCamera(ground.getTransformedCenter(), 215);
            sun.setPosition(projector.getPosition());
            sh.updateShadowMap();

            buffer.clear(java.awt.Color.BLACK);
            world.renderScene(buffer);
            world.draw(buffer);
            buffer.blit(cursor, 0, 0, mouseMapper.getMouseX(), mouseMapper.getMouseY(), cursor.getWidth(), cursor.getHeight(), true);
            buffer.update();
            buffer.displayGLOnly();
        }
        buffer.disableRenderer(IRenderer.RENDERER_OPENGL);
        buffer.dispose();
        System.exit(0);
    }

    /**
     * get 3d coordinate of srcPoint on object's surface from 2d coordinates.
     *
     * @param camera scene camera
     * @param buffer
     * @param x      screen (mouse) X coordinate
     * @param y      screen (mouse) Y coordinate
     * @return
     */
    public static SimpleVector getAbsoluteCoordinate(World world, Camera camera, FrameBuffer buffer, int x, int y) {
        SimpleVector rezult = null;
        if (camera != null && buffer != null) {
            SimpleVector rayTemp = Interact2D.reproject2D3DWS(camera, buffer, x, y).normalize();
            float distance = world.calcMinDistance(camera.getPosition(), rayTemp, 10000);
            rezult = new SimpleVector(camera.getPosition());
            rayTemp.scalarMul(distance);
            rezult.add(rayTemp);
        }
        return rezult;
    }

    public void poll() {
        KeyState ks = null;
        while ((ks = keyMapper.poll()) != KeyState.NONE) {
            if (ks.getKeyCode() == KeyEvent.VK_ESCAPE) {
                doLoop = false;
            }
        }
    }

    /**
     *
     * @param path
     */
    public void addTextures(String path) {
        File dir = new File(path);
        for (File file : dir.listFiles()) {
            System.out.println("Loading Textures! " + file.getName());
            if (file.isFile() && (file.getName().toLowerCase().endsWith(".jpg") || file.getName().toLowerCase().endsWith(".gif"))) {
                tm.addTexture(file.getName(), new Texture(file.getAbsoluteFile().toString()));
            }
            if (file.isFile() && file.getName().toLowerCase().endsWith(".png")) {
                tm.addTexture(file.getName(), new Texture(file.getAbsoluteFile().toString(), true));
            }
        }
    }

    private Object3D load3DS(String name, String modelPath) {
        Object3D object3D;
        object3D = Object3D.mergeAll(Loader.load3DS(modelPath, 0.3f));
        object3D.translate(0, -70, 0);
        object3D.setCulling(false);
        object3D.rotateX(-(float) Math.PI / 2);
        object3D.setSpecularLighting(true);
        object3D.setCollisionMode(Object3D.COLLISION_CHECK_OTHERS);
        object3D.setName(name);
        return object3D;
    }

    public void setMarker(String markerTextureName) {
        Enumeration e = tm.getNames();
        Map<Integer, TextureInfo> textureMap = new TreeMap<Integer, TextureInfo>();
        int maxID, textureIndex;
        PolygonManager manager;

        tm.getTexture(markerTextureName).setEnabled(true);
        tm.getTexture(markerTextureName).setProjector(markerProjector, true);

        while (e.hasMoreElements()) {
            String textureName = e.nextElement().toString();
            if (textureName.equals(markerTextureName)) {
                continue;
            }
            TextureInfo info = new TextureInfo(tm.getTextureID(textureName));
            info.add(tm.getTextureID(markerTextureName), TextureInfo.MODE_ADD);
            textureMap.put(tm.getTextureID(textureName), info);
        }



        for (Object3D md : model3DManager) {
            if (md != null) {
                manager = md.getPolygonManager();
                maxID = manager.getMaxPolygonID();
                for (int idx = 0; idx < maxID; idx++) {
                    textureIndex = manager.getPolygonTexture(idx);
                    manager.setPolygonTexture(idx, textureMap.get(textureIndex));
                }
            }
        }
    }
}



No dought this is my mistake somehow, but its just not obvious to me.
#3
Support / Re: Project texture down on ground and objects
November 21, 2011, 12:47:59 PM
Okay I tried and yes it does project the marker on all object, but it looses some of the textures on the objects.
In my Demo project I lost the roof texture and only the marker came up, and it shows the marker on both object at the same time

I tried adjusting  markerProjector.setFOV(0.3f); and the limits to get a better image, but it still streches it sides to width of the objects... 


    public void setMarker(String markerTextureName) {
        Enumeration e = tm.getNames();
        Map<Integer, TextureInfo> textureMap = new TreeMap<Integer, TextureInfo>();
        int maxID, textureIndex;
        PolygonManager manager;

        tm.getTexture(markerTextureName).setEnabled(true);
        tm.getTexture(markerTextureName).setProjector(markerProjector, true);

        while (e.hasMoreElements()) {
            String textureName = e.nextElement().toString();
            if (textureName.equals(markerTextureName)) {
                continue;
            }
            TextureInfo info = new TextureInfo(tm.getTextureID(textureName));
            info.add(tm.getTextureID(markerTextureName), TextureInfo.MODE_ADD);
            textureMap.put(tm.getTextureID(textureName), info);
        }


        Collection<Object3D> models = model3DManager.getModels();
        for (Object3D md : models) {
            if (md != skyModel) {
                manager = md.getPolygonManager();
                maxID = manager.getMaxPolygonID();
                for (int idx = 0; idx < maxID; idx++) {
                    textureIndex = manager.getPolygonTexture(idx);
                    manager.setPolygonTexture(idx, textureMap.get(textureIndex));
                }
            }
        }
   }
   
   // I allso tried to match the UV of the existing texture
    public void setMarker(String markerTextureName) {
        Map<Integer, TextureInfo> textureMap = new TreeMap<Integer, TextureInfo>();
        int maxID, textureIndex;
        PolygonManager manager;
        TextureInfo info;

        tm.getTexture(markerTextureName).setEnabled(true);
        tm.getTexture(markerTextureName).setProjector(markerProjector, true);

        Collection<Object3D> models = model3DManager.getModels();
        for (Object3D md : models) {
            if (md != skyModel) {
                manager = md.getPolygonManager();
                maxID = manager.getMaxPolygonID();
                for (int idx = 0; idx < maxID; idx++) {
                    textureIndex = manager.getPolygonTexture(idx);
                    info = new TextureInfo(textureIndex);
                    SimpleVector uv1 = manager.getTextureUV(idx, 0);
                    SimpleVector uv2 = manager.getTextureUV(idx, 1);
                    SimpleVector uv3 = manager.getTextureUV(idx, 2);
                    info.add(tm.getTextureID(markerTextureName),uv1.x,uv1.y,uv2.x,uv2.y,uv3.x,uv3.y,TextureInfo.MODE_ADD);
                    manager.setPolygonTexture(idx, info);
                }
            }
        }
    }
#4
Support / Re: Project texture down on ground and objects
November 21, 2011, 07:10:51 AM
Arhhh I see !!

I was look at the polygonManager at looked at setPolygonTexture(int polyID, int textureID) , didnt really notice that it had setPolygonTexture(int polyID, TextureInfo tInf) too.
It made no sense using the PolygonManager then, but now it does
#5
Support / Re: Project texture down on ground and objects
November 19, 2011, 07:52:35 PM
I'm not sure I understand... howto use that...
I created a small demo project, that projects a mark on the ground, there is allso a simple object more, that have two textures in the in the scene as well. I havent added any "mark" code for it, for I have nu glue where to start using the PolygonManager and setting the texture. The mark moves on the ground based on the Mouse or that was the idea, it does not work perfectly but I'll have to fix that later.   

If you get some time at some point, can you have a look at it and see if I'm overcomplicated what I'm trying to do, or maybe trying to do something impossible.

http://www.cintix.dk/MarkedWorld.zip

#6
Support / Re: Project texture down on ground and objects
November 19, 2011, 12:18:22 PM
Ohh thank you I can see that, but that just helps me getting all the Textures for a Model.
The PolygonManager can set a Texture for a Poly Id.

So when I found all my used Textures and wrapped them in a TextureInfo where I added my Marker to be projected down.
How do I reapply the Textures to the Model. The Model only takes one TextureInfo ? and all Textures are wrapped in their own TextureInfo and I need to apply two/Or more Textures back om model.

Is there a way I can set the TextureInfo in the TextureManager insted of a Texture, so lets say TextureManager.getInstance().addTexture("roof.jpg", textureInfoA); ??

I might be going around this the wrong way or misunderstand a lot of things, so please excuse my lack of knowledge.
#7
Support / Re: Project texture down on ground and objects
November 19, 2011, 10:23:40 AM
LOL I'm loosing my marbles here.
I have my Model, it is a grouped with with lets say 2 parts in it, and one part have TextureA and the other TextureB

When I create a TextureInfo its for a single Texture like TexturaA or TextureB, so I create two TextureInfo foreach Texture.
Now when I want to reapply the Textures as TextureInfo on my Object3D then I can only set one TextureInfo.

And uses that for the hole model ? I havent tried yet ., but that would be my believe.
So how do I added the second TextureInfo.
#8
Support / Re: Project texture down on ground and objects
November 19, 2011, 08:56:19 AM
Its not all that important.
I can write a simple utill class to read the names from the loader if its a 3DS and just do a simple pattern search for other models.
Then i can recreate a TextureInfo containing all textures for a given model
#9
Support / Re: Project texture down on ground and objects
November 19, 2011, 08:37:06 AM
I'm sorry, you so correct dont know what I was thinking.
Is there anyway to get the Textures or TextureInfo from the Object3D, so it returns what allready been set on it or is it impossible or maybe just the Texture names found when it got Loaded throw the Loader ?

I search the java doc and the only way I could find out what texture names belong to what Object3D is using the Loader.readTextureNames3DS.
This will tell me what texture name belongs to what object, but how do I read the texture names set for a Wave Object (obj) or other model ?




#10
Support / Re: Any Download Site for MD2 Model?
November 18, 2011, 07:00:27 PM
Egon,
I think it sounds great if you would put some models up, so people had something to start up with :-)

Here are some links to MD2 models, that I found.

http://www.blackrayne.net/models_1.php
http://planetquake.gamespy.com/View.php?view=Modeloftheweek.List&game=5&category_select_id=2
http://www.md2.sitters-electronics.nl/models.html

There should be alot of models you can pick up and use to start up with :-)
#11
Support / Re: Project texture down on ground and objects
November 18, 2011, 06:41:59 PM
I can't seem to get the Projector to show anything at all.
I created a new Projector and just set it to look at the center of my landscape.

I added the texture to all the textures, but nothing is coming up. I apply the texture to the TextureInfo after the models have been loaded and the textures have been set. Could this be the problem ? Would I have to set the texture on the Object again ?

right now I'm doing this.

    public void setMarker(String texturename) {
        markerTextureID = texturename;
        Enumeration e = tm.getNames();
        while (e.hasMoreElements()) {
            String textureID = e.nextElement().toString();
            if (textureID.equals(markerTextureID)) {
                continue;
            }
            TextureInfo info = new TextureInfo(tm.getTextureID(textureID));
            info.add(tm.getTextureID(markerTextureID), TextureInfo.MODE_ADD);
        }

        tm.getTexture(markerTextureID).setEnabled(true);
        tm.getTexture(markerTextureID).setProjector(markerProjector, true);
        drawMarker = true;
    }
#12
Support / Re: Problem with Object picking
November 18, 2011, 11:03:07 AM
Okay,

I just thought the first method that worked for none-compiled object was a bit faster and then maybe more precis, so if it was possible then it would be a more correct approach to use.
#13
Support / Re: Project texture down on ground and objects
November 18, 2011, 10:35:52 AM
Thank you again Egon

I think I'm going to try working on using the Projector, I was think about creating a Light and moving it around, but its only a color and I wantet a bit more maybe create a animation.
#14
Support / Re: Problem with Object picking
November 18, 2011, 10:18:03 AM
Thank you Egon.
Using Interact2D.reproject2D3DWS(...) made it work MUCH better, I should have noticed that.
I think its so great you take out the time, to support and help even idiots like me ;-)

I know I'm using both methods, and the first one will not work in my current code.
The reason for it, is that the object3d don't have to be compiled, it a setting I use and now its set to compile.
I just have not yet transfered the setting to the method, so it only do the correct check based on the setting.

its it a bad idea to have some object build and others not ? would it be to expensive to run both calls, if I have a mix of Objects some compiled and others not ?
#15
Support / Project texture down on ground and objects
November 18, 2011, 09:26:59 AM
Hi people,

I'm trying to figure out howto draw a texture "mark like a circle" on location with the mouse on the ground and objects.
Is that possible ? anybody done something like that ?  I was thing to get the position to draw it like picking on Objects maybe,  and somehow projecting a texture down on anything below it. maybe blit ?

I hope this make sense  :-)