Search in sources :

Example 6 with TextureException

use of org.rajawali3d.materials.textures.ATexture.TextureException in project Rajawali by Rajawali.

the class LoaderFBX method parse.

@Override
public LoaderFBX parse() throws ParsingException {
    super.parse();
    BufferedReader buffer = null;
    if (mFile == null) {
        InputStream fileIn = mResources.openRawResource(mResourceId);
        buffer = new BufferedReader(new InputStreamReader(fileIn));
    } else {
        try {
            buffer = new BufferedReader(new FileReader(mFile));
        } catch (FileNotFoundException e) {
            RajLog.e("[" + getClass().getCanonicalName() + "] Could not find file.");
            throw new ParsingException(e);
        }
    }
    String line;
    try {
        while ((line = buffer.readLine()) != null) {
            String repl = line.replaceAll(REGEX_CLEAN, REPLACE_EMPTY);
            if (repl.length() == 0 || repl.charAt(0) == COMMENT)
                continue;
            readLine(buffer, line);
        }
        buffer.close();
    } catch (Exception e) {
        throw new ParsingException(e);
    }
    // -- get lights
    Stack<Model> lights = mFbx.objects.getModelsByType(FBXValues.MODELTYPE_LIGHT);
    int numLights = lights.size();
    Renderer.setMaxLights(numLights == 0 ? 1 : numLights);
    Stack<ALight> sceneLights = new Stack<ALight>();
    for (int i = 0; i < numLights; ++i) {
        Model l = lights.get(i);
        // -- really need to add more light types
        sceneLights.add(buildLight(l));
    }
    if (numLights == 0) {
        ALight light = new DirectionalLight();
        light.setPosition(2, 0, -5);
        light.setPower(1);
        sceneLights.add(light);
    }
    // -- check fog
    //TODO: add fog support
    /*if(mFbx.version5.fogOptions.fogEnable != null && mFbx.version5.fogOptions.fogEnable == 1) {
			FogOptions fogOptions = mFbx.version5.fogOptions;
			mRenderer.setFogEnabled(true);
			Camera cam = mRenderer.getCamera();
			cam.setFogEnabled(true);
			cam.setFogNear(fogOptions.fogStart);
			cam.setFogColor(fogOptions.fogColor.color);
			mRenderer.setBackgroundColor(fogOptions.fogColor.color);
		}*/
    // -- get meshes
    Stack<Model> models = mFbx.objects.getModelsByType(FBXValues.MODELTYPE_MESH);
    try {
        for (int i = 0; i < models.size(); ++i) {
            buildMesh(models.get(i), sceneLights);
        }
    } catch (TextureException tme) {
        throw new ParsingException(tme);
    }
    // -- get cameras
    Stack<Model> cameras = mFbx.objects.getModelsByType(FBXValues.MODELTYPE_CAMERA);
    Model camera = null;
    for (int i = 0; i < cameras.size(); ++i) {
        if (cameras.get(i).hidden == null || !cameras.get(i).hidden.equals("True")) {
            camera = cameras.get(i);
            break;
        }
    }
    if (camera != null) {
        //TODO: FIX
        Camera cam = mRenderer.getCurrentCamera();
        cam.setPosition(camera.position);
        cam.setX(mRenderer.getCurrentCamera().getX() * -1);
        cam.setRotation(camera.properties.lclRotation);
        Vector3 lookAt = camera.lookAt;
        //			lookAt.x = -lookAt.x;
        cam.setLookAt(lookAt);
        cam.setNearPlane(camera.properties.nearPlane);
        cam.setFarPlane(camera.properties.farPlane);
        cam.setFieldOfView(camera.properties.fieldOfView);
    }
    return this;
}
Also used : InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) FileNotFoundException(java.io.FileNotFoundException) Vector3(org.rajawali3d.math.vector.Vector3) TextureException(org.rajawali3d.materials.textures.ATexture.TextureException) ParsingException(org.rajawali3d.loader.ParsingException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) InvocationTargetException(java.lang.reflect.InvocationTargetException) Stack(java.util.Stack) TextureException(org.rajawali3d.materials.textures.ATexture.TextureException) ParsingException(org.rajawali3d.loader.ParsingException) DirectionalLight(org.rajawali3d.lights.DirectionalLight) BufferedReader(java.io.BufferedReader) Model(org.rajawali3d.loader.fbx.FBXValues.Objects.Model) FileReader(java.io.FileReader) Camera(org.rajawali3d.cameras.Camera) ALight(org.rajawali3d.lights.ALight)

Example 7 with TextureException

use of org.rajawali3d.materials.textures.ATexture.TextureException in project Rajawali by Rajawali.

the class Scene method setSkybox.

/**
     * Creates a skybox with the specified 6 {@link Bitmap} textures.
     *
     * @param bitmaps {@link Bitmap} array containing the cube map textures.
     */
public boolean setSkybox(Bitmap[] bitmaps) {
    final AFrameTask task = new AFrameTask() {

        @Override
        protected void doTask() {
            for (int i = 0, j = mCameras.size(); i < j; ++i) mCameras.get(i).setFarPlane(1000);
        }
    };
    final Cube skybox = new Cube(700, true);
    final CubeMapTexture texture = new CubeMapTexture("bitmap_skybox", bitmaps);
    texture.isSkyTexture(true);
    final Material material = new Material();
    material.setColorInfluence(0);
    try {
        material.addTexture(texture);
    } catch (TextureException e) {
        RajLog.e(e.getMessage());
    }
    skybox.setMaterial(material);
    synchronized (mNextCameraLock) {
        mNextSkybox = skybox;
    }
    return internalOfferTask(task);
}
Also used : TextureException(org.rajawali3d.materials.textures.ATexture.TextureException) AFrameTask(org.rajawali3d.renderer.AFrameTask) Cube(org.rajawali3d.primitives.Cube) Material(org.rajawali3d.materials.Material) ShadowMapMaterial(org.rajawali3d.postprocessing.materials.ShadowMapMaterial) CubeMapTexture(org.rajawali3d.materials.textures.CubeMapTexture)

Example 8 with TextureException

use of org.rajawali3d.materials.textures.ATexture.TextureException in project Rajawali by Rajawali.

the class VuforiaRenderer method onRenderSurfaceSizeChanged.

@Override
public void onRenderSurfaceSizeChanged(GL10 gl, int width, int height) {
    RajLog.i("onRenderSurfaceSizeChanged " + width + ", " + height);
    super.onRenderSurfaceSizeChanged(gl, width, height);
    updateRendering(width, height);
    QCAR.onSurfaceChanged(width, height);
    getCurrentCamera().setProjectionMatrix(getFOV(), getVideoWidth(), getVideoHeight());
    if (mBackgroundRenderTarget == null) {
        mBackgroundRenderTarget = new RenderTarget("rajVuforia", width, height);
        addRenderTarget(mBackgroundRenderTarget);
        Material material = new Material();
        material.setColorInfluence(0);
        try {
            material.addTexture(mBackgroundRenderTarget.getTexture());
        } catch (TextureException e) {
            e.printStackTrace();
        }
        mBackgroundQuad = new ScreenQuad();
        if (mVuforiaManager.getScreenOrientation() == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE)
            mBackgroundQuad.setScaleY((float) height / (float) getVideoHeight());
        else
            mBackgroundQuad.setScaleX((float) width / (float) getVideoWidth());
        mBackgroundQuad.setMaterial(material);
        getCurrentScene().addChildAt(mBackgroundQuad, 0);
    }
}
Also used : TextureException(org.rajawali3d.materials.textures.ATexture.TextureException) ScreenQuad(org.rajawali3d.primitives.ScreenQuad) Material(org.rajawali3d.materials.Material) RenderTarget(org.rajawali3d.renderer.RenderTarget)

Aggregations

TextureException (org.rajawali3d.materials.textures.ATexture.TextureException)8 IOException (java.io.IOException)4 Material (org.rajawali3d.materials.Material)4 FileNotFoundException (java.io.FileNotFoundException)3 InputStream (java.io.InputStream)3 Bitmap (android.graphics.Bitmap)2 BufferedReader (java.io.BufferedReader)2 FileInputStream (java.io.FileInputStream)2 FileReader (java.io.FileReader)2 InputStreamReader (java.io.InputStreamReader)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 Camera (org.rajawali3d.cameras.Camera)2 ParsingException (org.rajawali3d.loader.ParsingException)2 Texture (org.rajawali3d.materials.textures.Texture)2 ScreenQuad (org.rajawali3d.primitives.ScreenQuad)2 BufferedInputStream (java.io.BufferedInputStream)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Stack (java.util.Stack)1 StringTokenizer (java.util.StringTokenizer)1