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

#1
Support / Re: Change object texture in loop.
April 25, 2017, 04:03:09 PM
I got it. I tried to setTexture() on Parent, not its Child and thought that it is impossible in draw method . Thanks for quick reply.  ;)

long current = System.currentTimeMillis();

        for (int i = 0; i < mTrackableObjects.size(); i++) {
            TrackableObject3d trackableObject = mTrackableObjects.get(i);

            if (mTrackableObjects.get(i).isObjectVisible()) {
                List<Object3D> mChildren = trackableObject.getChildren();
                Object3D  first = mChildren.get(0);
                if (current - START_TIME > delay) {

                    if (delay % 2 != 0) {
                        first.setTexture("green");
                    } else {
                         first.setTexture("red");
                    }
                    delay += 301;
                }
            }
            trackableObject.updateMarkerTransformation();
        }
#2
Support / Change object texture in loop.
April 25, 2017, 02:02:05 PM
Hi. I'm working on android ARToolkit and JPCT-AE app. I'd like to switch 2 textures of 3D object in some amount of time.
There I define objects:

public final List<TrackableObject3d> getTrackableObject3DList() {
        List<TrackableObject3d> list = new ArrayList<TrackableObject3d>();
        populateTrackableObjects(list);
        return list;
    }

    protected void populateTrackableObjects(List<TrackableObject3d> list) {
        Texture green = new Texture(ContextCompat.getDrawable(this, getTextureRes()[0]));
        TextureManager.getInstance().addTexture(TEXTURE_NAME, green);

        Texture red = new Texture(ContextCompat.getDrawable(this, getTextureRes()[1]));
        TextureManager.getInstance().addTexture(TEXTURE_NAME_RED, red);

        String extention = ".patt;80";

        for (String name : markerString().keySet()) {
            String type = markerString().get(name).toLowerCase();
            switch (type){
                case "single" :
                    extention = ".patt;80";
                    break;
                case "nft" :
                    extention = "";
                    break;
                case "multi" :
                    extention = ".dat";

            }
            list.add(getTrackableObject(type+";Data/"+name+extention));
        }
    }

    private TrackableObject3d getTrackableObject(String name) {
        TrackableObject3d result = new TrackableObject3d(name);

        try {
            Object3D[] object = Loader.loadOBJ(getAssets().open(OBJ),
                    getAssets().open(MTL), 300);
            object[0].setOrigin(new SimpleVector(80, -75, 0));
            object[0].setTexture(TEXTURE_NAME_RED);
            object[0].setCollisionMode(Object3D.COLLISION_CHECK_OTHERS);

            result.addChild(object[0]);

            Object3D object3D = Primitives.getPlane(2, 100);
            object3D.rotateX((float) Math.PI);
            object3D.setOrigin(new SimpleVector(0, 0, -5));
            object3D.setTransparencyMode(Object3D.TRANSPARENCY_MODE_DEFAULT);
            object3D.setTransparency(0);
            object3D.setLighting(Object3D.LIGHTING_NO_LIGHTS);
            object3D.setCollisionMode(Object3D.COLLISION_CHECK_OTHERS);

            result.addChild(object3D);

        } catch (Exception ignored) {
        }
        return result;
    }


My questions:
1. Where i should do animation, in "draw(GL10 gl)" method?
2. Is this should be animation or is any simpler way to change textures?

Additionally my draw(GL10 gl)

public final void draw(GL10 gl) {
        mBuffer.clear();

        float[] projection = ARToolKit.getInstance().getProjectionMatrix();

        projMatrix.setDump(projection);
        mCamera.setBack(projMatrix);
        SimpleVector translation = projMatrix.getTranslation();

        if (!mFovSet) {
            // Calculate FOV based on projection values, but do it only once
            float value1 = projection[5];
            float vFov = (float) Math.atan2(1, value1)*2;
            mCamera.setYFovAngle(vFov);
            float aspect = projection[5] / projection[0];


            float fov = (float) (2 * Math.atan2(mCamera.getYFOV() , 2 ) * aspect);
            mCamera.setFovAngle(fov);
            mFovSet = true;

        }

        SimpleVector dir = projMatrix.getZAxis();
        SimpleVector up = projMatrix.getYAxis();
        mCamera.setPosition(translation);
        mCamera.setOrientation(dir, up);

        for (int i=0; i<mTrackableObjects.size(); i++) {
            TrackableObject3d trackableObject = mTrackableObjects.get(i);
            trackableObject.updateMarkerTransformation();
        }

        mWorld.renderScene(mBuffer);
        mWorld.draw(mBuffer);
        mBuffer.display();
    }