Search in sources :

Example 11 with Material

use of org.rajawali3d.materials.Material in project Rajawali by Rajawali.

the class WallpaperRenderer method initScene.

@Override
protected void initScene() {
    ALight light = new DirectionalLight(-1, 0, -1);
    light.setPower(2);
    getCurrentScene().addLight(light);
    getCurrentCamera().setPosition(0, 0, 7);
    getCurrentCamera().setLookAt(0, 0, 0);
    try {
        Cube cube = new Cube(1);
        Material material = new Material();
        material.enableLighting(true);
        material.setDiffuseMethod(new DiffuseMethod.Lambert());
        material.addTexture(new Texture("rajawaliTex", R.drawable.rajawali_tex));
        material.setColorInfluence(0);
        cube.setMaterial(material);
        getCurrentScene().addChild(cube);
        Vector3 axis = new Vector3(3, 1, 6);
        axis.normalize();
        Animation3D anim = new RotateOnAxisAnimation(axis, 0, 360);
        anim.setDurationMilliseconds(8000);
        anim.setRepeatMode(Animation.RepeatMode.INFINITE);
        anim.setInterpolator(new AccelerateDecelerateInterpolator());
        anim.setTransformable3D(cube);
        getCurrentScene().registerAnimation(anim);
        anim.play();
    } catch (ATexture.TextureException e) {
        e.printStackTrace();
    }
}
Also used : Material(org.rajawali3d.materials.Material) Vector3(org.rajawali3d.math.vector.Vector3) ATexture(org.rajawali3d.materials.textures.ATexture) Texture(org.rajawali3d.materials.textures.Texture) Animation3D(org.rajawali3d.animation.Animation3D) Cube(org.rajawali3d.primitives.Cube) RotateOnAxisAnimation(org.rajawali3d.animation.RotateOnAxisAnimation) DirectionalLight(org.rajawali3d.lights.DirectionalLight) ATexture(org.rajawali3d.materials.textures.ATexture) DiffuseMethod(org.rajawali3d.materials.methods.DiffuseMethod) AccelerateDecelerateInterpolator(android.view.animation.AccelerateDecelerateInterpolator) ALight(org.rajawali3d.lights.ALight)

Example 12 with Material

use of org.rajawali3d.materials.Material in project Rajawali by Rajawali.

the class PlanesGalore method init.

public void init() {
    mGaloreMat = new Material();
    mGaloreMat.enableTime(true);
    mMaterialPlugin = new PlanesGaloreMaterialPlugin();
    mGaloreMat.addPlugin(mMaterialPlugin);
    setMaterial(mGaloreMat);
    final int numPlanes = 2000;
    final float planeSize = .3f;
    int numVertices = numPlanes * 4;
    float[] vertices = new float[numVertices * 3];
    float[] textureCoords = new float[numVertices * 2];
    float[] normals = new float[numVertices * 3];
    float[] planePositions = new float[numVertices * 3];
    float[] rotationSpeeds = new float[numVertices];
    float[] colors = new float[numVertices * 4];
    int[] indices = new int[numPlanes * 6];
    for (int i = 0; i < numPlanes; ++i) {
        Vector3 r = new Vector3(-10f + (Math.random() * 20f), -10 + (Math.random() * 20f), (Math.random() * 80f));
        int randColor = 0xff000000 + (int) (0xffffff * Math.random());
        int vIndex = i * 4 * 3;
        vertices[vIndex + 0] = -planeSize;
        vertices[vIndex + 1] = planeSize;
        vertices[vIndex + 2] = 0;
        vertices[vIndex + 3] = planeSize;
        vertices[vIndex + 4] = planeSize;
        vertices[vIndex + 5] = 0;
        vertices[vIndex + 6] = planeSize;
        vertices[vIndex + 7] = -planeSize;
        vertices[vIndex + 8] = 0;
        vertices[vIndex + 9] = -planeSize;
        vertices[vIndex + 10] = -planeSize;
        vertices[vIndex + 11] = 0;
        for (int j = 0; j < 12; j += 3) {
            normals[vIndex + j] = 0;
            normals[vIndex + j + 1] = 0;
            normals[vIndex + j + 2] = 1;
            planePositions[vIndex + j] = (float) r.x;
            planePositions[vIndex + j + 1] = (float) r.y;
            planePositions[vIndex + j + 2] = (float) r.z;
        }
        vIndex = i * 4 * 4;
        for (int j = 0; j < 16; j += 4) {
            colors[vIndex + j] = Color.red(randColor) / 255f;
            colors[vIndex + j + 1] = Color.green(randColor) / 255f;
            colors[vIndex + j + 2] = Color.blue(randColor) / 255f;
            colors[vIndex + j + 3] = 1.0f;
        }
        vIndex = i * 4 * 2;
        float u1 = .25f * (int) Math.floor(Math.random() * 4f);
        float v1 = .25f * (int) Math.floor(Math.random() * 4f);
        float u2 = u1 + .25f;
        float v2 = v1 + .25f;
        textureCoords[vIndex + 0] = u2;
        textureCoords[vIndex + 1] = v1;
        textureCoords[vIndex + 2] = u1;
        textureCoords[vIndex + 3] = v1;
        textureCoords[vIndex + 4] = u1;
        textureCoords[vIndex + 5] = v2;
        textureCoords[vIndex + 6] = u2;
        textureCoords[vIndex + 7] = v2;
        vIndex = i * 4;
        int iindex = i * 6;
        indices[iindex + 0] = (short) (vIndex + 0);
        indices[iindex + 1] = (short) (vIndex + 1);
        indices[iindex + 2] = (short) (vIndex + 3);
        indices[iindex + 3] = (short) (vIndex + 1);
        indices[iindex + 4] = (short) (vIndex + 2);
        indices[iindex + 5] = (short) (vIndex + 3);
        float rotationSpeed = -1f + (float) (Math.random() * 2f);
        rotationSpeeds[vIndex + 0] = rotationSpeed;
        rotationSpeeds[vIndex + 1] = rotationSpeed;
        rotationSpeeds[vIndex + 2] = rotationSpeed;
        rotationSpeeds[vIndex + 3] = rotationSpeed;
    }
    setData(vertices, normals, textureCoords, colors, indices, true);
    mPlanePositions = ByteBuffer.allocateDirect(planePositions.length * Geometry3D.FLOAT_SIZE_BYTES).order(ByteOrder.nativeOrder()).asFloatBuffer();
    mPlanePositions.put(planePositions);
    mRotationSpeeds = ByteBuffer.allocateDirect(rotationSpeeds.length * Geometry3D.FLOAT_SIZE_BYTES).order(ByteOrder.nativeOrder()).asFloatBuffer();
    mRotationSpeeds.put(rotationSpeeds);
    createBuffers();
}
Also used : Material(org.rajawali3d.materials.Material) Vector3(org.rajawali3d.math.vector.Vector3)

Example 13 with Material

use of org.rajawali3d.materials.Material in project Rajawali by Rajawali.

the class Loader3DSMax method build.

public void build() throws TextureException {
    int num = mVertices.size();
    for (int j = 0; j < num; ++j) {
        ArrayList<Integer> indices = mIndices.get(j);
        ArrayList<Vector3> vertices = mVertices.get(j);
        ArrayList<Vector3> texCoords = null;
        ArrayList<Vector3> vertNormals = mVertNormals.get(j);
        if (mTexCoords.size() > 0)
            texCoords = mTexCoords.get(j);
        int len = indices.size();
        float[] aVertices = new float[len * 3];
        float[] aNormals = new float[len * 3];
        float[] aTexCoords = new float[len * 2];
        int[] aIndices = new int[len];
        int ic = 0;
        int itn = 0;
        int itc = 0;
        int ivi = 0;
        Vector3 coord;
        Vector3 texcoord;
        Vector3 normal;
        for (int i = 0; i < len; i += 3) {
            int v1 = indices.get(i);
            int v2 = indices.get(i + 1);
            int v3 = indices.get(i + 2);
            coord = vertices.get(v1);
            aVertices[ic++] = (float) coord.x;
            aVertices[ic++] = (float) coord.y;
            aVertices[ic++] = (float) coord.z;
            aIndices[ivi] = ivi++;
            coord = vertices.get(v2);
            aVertices[ic++] = (float) coord.x;
            aVertices[ic++] = (float) coord.y;
            aVertices[ic++] = (float) coord.z;
            aIndices[ivi] = ivi++;
            coord = vertices.get(v3);
            aVertices[ic++] = (float) coord.x;
            aVertices[ic++] = (float) coord.y;
            aVertices[ic++] = (float) coord.z;
            aIndices[ivi] = ivi++;
            if (texCoords != null && texCoords.size() > 0) {
                texcoord = texCoords.get(v1);
                aTexCoords[itc++] = (float) texcoord.x;
                aTexCoords[itc++] = (float) texcoord.y;
                texcoord = texCoords.get(v2);
                aTexCoords[itc++] = (float) texcoord.x;
                aTexCoords[itc++] = (float) texcoord.y;
                texcoord = texCoords.get(v3);
                aTexCoords[itc++] = (float) texcoord.x;
                aTexCoords[itc++] = (float) texcoord.y;
            }
            normal = vertNormals.get(v1);
            aNormals[itn++] = (float) normal.x;
            aNormals[itn++] = (float) normal.y;
            aNormals[itn++] = (float) normal.z;
            normal = vertNormals.get(v2);
            aNormals[itn++] = (float) normal.x;
            aNormals[itn++] = (float) normal.y;
            aNormals[itn++] = (float) normal.z;
            normal = vertNormals.get(v3);
            aNormals[itn++] = (float) normal.x;
            aNormals[itn++] = (float) normal.y;
            aNormals[itn++] = (float) normal.z;
        }
        Object3D targetObj = new Object3D(mObjNames.get(j));
        targetObj.setData(aVertices, aNormals, aTexCoords, null, aIndices, false);
        // -- diffuse material with random color. for now.
        Material material = new Material();
        material.setDiffuseMethod(new DiffuseMethod.Lambert());
        targetObj.setMaterial(material);
        targetObj.setColor(0xff000000 + (int) (Math.random() * 0xffffff));
        mRootObject.addChild(targetObj);
    }
}
Also used : DiffuseMethod(org.rajawali3d.materials.methods.DiffuseMethod) Vector3(org.rajawali3d.math.vector.Vector3) Material(org.rajawali3d.materials.Material) Object3D(org.rajawali3d.Object3D)

Example 14 with Material

use of org.rajawali3d.materials.Material in project Rajawali by Rajawali.

the class DebugLight method createLines.

private void createLines() {
    Stack<Vector3> points = new Stack<>();
    float segmentSize = 10;
    float radius = .2f;
    int count = 0;
    for (int i = 0; i < 360; i += segmentSize) {
        if (count++ % 2 == 0)
            continue;
        float radians1 = (float) MathUtil.degreesToRadians(i);
        float radians2 = (float) MathUtil.degreesToRadians(i + segmentSize);
        Vector3 p1 = new Vector3();
        p1.x = Math.cos(radians1) * radius;
        p1.y = Math.sin(radians1) * radius;
        Vector3 p2 = new Vector3();
        p2.x = Math.cos(radians2) * radius;
        p2.y = Math.sin(radians2) * radius;
        points.add(p1);
        points.add(p2);
    }
    Material material = new Material();
    mCircle = new Line3D(points, mLineThickness, mColor);
    mCircle.setMaterial(material);
    mCircle.setDrawingMode(GLES20.GL_LINES);
    mCircle.enableLookAt();
    addChild(mCircle);
    points = new Stack<>();
    if (mLight.getLightType() == mLight.DIRECTIONAL_LIGHT || mLight.getLightType() == mLight.SPOT_LIGHT) {
        for (int i = 0; i < 20; i += 2) {
            Vector3 p1 = new Vector3();
            p1.z = i * 0.5f;
            Vector3 p2 = new Vector3();
            p2.z = (i + 1) * 0.5f;
            points.add(p1);
            points.add(p2);
        }
        mLine = new Line3D(points, mLineThickness, mColor);
        mLine.setMaterial(material);
        mLine.setDrawingMode(GLES20.GL_LINES);
        mLine.enableLookAt();
        addChild(mLine);
    }
}
Also used : Vector3(org.rajawali3d.math.vector.Vector3) Material(org.rajawali3d.materials.Material) Line3D(org.rajawali3d.primitives.Line3D) Stack(java.util.Stack)

Example 15 with Material

use of org.rajawali3d.materials.Material in project Rajawali by Rajawali.

the class BoundingBox method drawBoundingVolume.

public void drawBoundingVolume(Camera camera, final Matrix4 vpMatrix, final Matrix4 projMatrix, final Matrix4 vMatrix, final Matrix4 mMatrix) {
    if (mVisualBox == null) {
        mVisualBox = new Cube(1);
        Material material = new Material();
        mVisualBox.setMaterial(material);
        mVisualBox.setColor(mBoundingColor.get());
        mVisualBox.setDrawingMode(GLES20.GL_LINE_LOOP);
        mVisualBox.setDoubleSided(true);
    }
    mVisualBox.setScale(Math.abs(mTransformedMax.x - mTransformedMin.x), Math.abs(mTransformedMax.y - mTransformedMin.y), Math.abs(mTransformedMax.z - mTransformedMin.z));
    mVisualBox.setPosition(mTransformedMin.x + (mTransformedMax.x - mTransformedMin.x) * .5, mTransformedMin.y + (mTransformedMax.y - mTransformedMin.y) * .5, mTransformedMin.z + (mTransformedMax.z - mTransformedMin.z) * .5);
    mVisualBox.render(camera, vpMatrix, projMatrix, vMatrix, mTmpMatrix, null);
}
Also used : Cube(org.rajawali3d.primitives.Cube) Material(org.rajawali3d.materials.Material)

Aggregations

Material (org.rajawali3d.materials.Material)25 Vector3 (org.rajawali3d.math.vector.Vector3)9 DiffuseMethod (org.rajawali3d.materials.methods.DiffuseMethod)7 Texture (org.rajawali3d.materials.textures.Texture)6 TextureException (org.rajawali3d.materials.textures.ATexture.TextureException)5 Object3D (org.rajawali3d.Object3D)4 ShadowMapMaterial (org.rajawali3d.postprocessing.materials.ShadowMapMaterial)4 Cube (org.rajawali3d.primitives.Cube)4 ParsingException (org.rajawali3d.loader.ParsingException)3 NormalMapTexture (org.rajawali3d.materials.textures.NormalMapTexture)3 DirectionalLight (org.rajawali3d.lights.DirectionalLight)2 AwdProperties (org.rajawali3d.loader.LoaderAWD.AwdProperties)2 SpecularMethod (org.rajawali3d.materials.methods.SpecularMethod)2 ATexture (org.rajawali3d.materials.textures.ATexture)2 CubeMapTexture (org.rajawali3d.materials.textures.CubeMapTexture)2 Matrix4 (org.rajawali3d.math.Matrix4)2 ScreenQuad (org.rajawali3d.primitives.ScreenQuad)2 Sphere (org.rajawali3d.primitives.Sphere)2 AFrameTask (org.rajawali3d.renderer.AFrameTask)2 RenderTarget (org.rajawali3d.renderer.RenderTarget)2