Search in sources :

Example 16 with Material

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

the class BoundingSphere method drawBoundingVolume.

public void drawBoundingVolume(Camera camera, final Matrix4 vpMatrix, final Matrix4 projMatrix, final Matrix4 vMatrix, final Matrix4 mMatrix) {
    if (mVisualSphere == null) {
        mVisualSphere = new Sphere(1, 8, 8);
        Material material = new Material();
        mVisualSphere.setMaterial(material);
        mVisualSphere.setColor(0xffffff00);
        mVisualSphere.setDrawingMode(GLES20.GL_LINE_LOOP);
        mVisualSphere.setDoubleSided(true);
    }
    mVisualSphere.setPosition(mPosition);
    mVisualSphere.setScale(mRadius * mScale);
    mVisualSphere.render(camera, vpMatrix, projMatrix, vMatrix, mTmpMatrix, null);
}
Also used : Sphere(org.rajawali3d.primitives.Sphere) Material(org.rajawali3d.materials.Material)

Example 17 with Material

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

the class BlockSimpleMaterial method parseBlock.

public void parseBlock(AWDLittleEndianDataInputStream dis, BlockHeader blockHeader) throws Exception {
    // Lookup name
    mLookupName = dis.readVarString();
    // Material type
    mMaterialType = dis.readByte();
    // Shading method count
    mShadingMethodCount = dis.readByte();
    // Read properties
    final AwdProperties properties = dis.readProperties(EXPECTED_PROPS);
    mSpezialType = (Integer) properties.get((short) 4, 0);
    // Spezial type 2 or higher is not supported in the specification
    if (mSpezialType >= 2)
        throw new NotParsableException("Spezial type " + mSpezialType + " is not currently supported.");
    // Debug
    if (RajLog.isDebugEnabled()) {
        RajLog.d("  Lookup Name: " + mLookupName);
        RajLog.d("  Material Type: " + mMaterialType);
        RajLog.d("  Shading Methods: " + mShadingMethodCount);
        RajLog.d("  Spezial Type: " + mSpezialType);
    }
    // Parse the methods
    for (int i = 0; i < mShadingMethodCount; ++i) {
        // TODO Looking at the AWD source, this appears to be completely unused?
        dis.readUnsignedShort();
        dis.readProperties();
        dis.readUserAttributes(null);
    }
    final HashMap<String, Object> attributes = new HashMap<String, Object>();
    dis.readUserAttributes(attributes);
    mMaterial = new Material();
    long diffuseTexture = 0, ambientTexture = 0, diffuseColor = 0;
    // remove any chars that will break shader compile
    String cleanName = cleanName(mLookupName);
    switch(mMaterialType) {
        case TYPE_COLOR:
            // default to 0xcccccc per AWD implementation
            diffuseColor = (Long) properties.get((short) 1, 0xccccccL);
            final float[] colorFloat = new float[4];
            colorFloat[0] = ((diffuseColor >> 16) & 0xff) / 255.0f;
            colorFloat[1] = ((diffuseColor >> 8) & 0xff) / 255.0f;
            colorFloat[2] = (diffuseColor & 0xff) / 255.0f;
            colorFloat[3] = (((int) ((Double) properties.get(PROP_ALPHA, 1.0d) * 0xff)) & 0xff) / 255.0f;
            mMaterial.setColor(colorFloat);
            break;
        case TYPE_TEXTURE:
            diffuseTexture = (Long) properties.get(PROP_TEXTURE, 0L);
            ambientTexture = (Long) properties.get(PROP_AMBIENT_TEXTURE, 0L);
            if (diffuseTexture == 0 && ambientTexture == 0)
                throw new ParsingException("Texture ID can not be 0, document corrupt or unsupported version.");
            if (diffuseTexture > 0)
                mMaterial.addTexture(new Texture(cleanName + diffuseTexture, lookup(blockHeader, diffuseTexture)));
            if (ambientTexture > 0)
                mMaterial.addTexture(new Texture(cleanName + ambientTexture, lookup(blockHeader, ambientTexture)));
            mMaterial.setColorInfluence(0);
            break;
    }
    // either material type can have specular and/or normal maps
    long specularTexture = (Long) properties.get(PROP_SPECULAR_TEXTURE, 0L);
    long normalTexture = (Long) properties.get(PROP_NORMAL_TEXTURE, 0L);
    // either material type can have settings for diffuse, ambient, specular lighting
    double diffuseLevel = (Double) properties.get(PROP_DIFFUSE_LEVEL, 1.0d);
    long ambientColor = (Long) properties.get(PROP_AMBIENT_COLOR, (long) Color.WHITE);
    double ambientLevel = (Double) properties.get(PROP_AMBIENT_LEVEL, 1.0d);
    long specularColor = (Long) properties.get(PROP_SPECULAR_COLOR, (long) Color.WHITE);
    double specularGloss = (Double) properties.get(PROP_SPECULAR_GLOSS, 50.0D);
    double specularLevel = (Double) properties.get(PROP_SPECULAR_LEVEL, 1.0d);
    if (specularTexture > 0)
        mMaterial.addTexture(new SpecularMapTexture(cleanName + specularTexture, lookup(blockHeader, specularTexture)));
    if (normalTexture > 0)
        mMaterial.addTexture(new NormalMapTexture(cleanName + normalTexture, lookup(blockHeader, normalTexture)));
    // ambient 1.0 is default, washes-out object; assume < 1 is intended
    ambientLevel = (ambientLevel < 1.0 ? ambientLevel : 0.0);
    mMaterial.setAmbientIntensity(ambientLevel, ambientLevel, ambientLevel);
    mMaterial.setAmbientColor((int) ambientColor);
    if (// always 1.0 in current AWD implementation
    diffuseLevel > 0)
        mMaterial.setDiffuseMethod(new DiffuseMethod.Lambert());
    if (specularLevel > 0) {
        SpecularMethod.Phong phong = new SpecularMethod.Phong();
        phong.setSpecularColor((int) specularColor);
        phong.setShininess((float) specularGloss);
        phong.setIntensity((float) specularLevel);
        mMaterial.setSpecularMethod(phong);
    }
    // don't enable lighting if specular and diffuse are absent, otherwise enable
    if (diffuseLevel > 0 || specularLevel > 0)
        mMaterial.enableLighting(true);
}
Also used : HashMap(java.util.HashMap) NotParsableException(org.rajawali3d.loader.awd.exceptions.NotParsableException) Material(org.rajawali3d.materials.Material) NormalMapTexture(org.rajawali3d.materials.textures.NormalMapTexture) AwdProperties(org.rajawali3d.loader.LoaderAWD.AwdProperties) SpecularMapTexture(org.rajawali3d.materials.textures.SpecularMapTexture) SpecularMapTexture(org.rajawali3d.materials.textures.SpecularMapTexture) Texture(org.rajawali3d.materials.textures.Texture) NormalMapTexture(org.rajawali3d.materials.textures.NormalMapTexture) SpecularMethod(org.rajawali3d.materials.methods.SpecularMethod) ParsingException(org.rajawali3d.loader.ParsingException)

Example 18 with Material

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

the class LoaderFBX method getMaterialForMesh.

private Material getMaterialForMesh(Object3D o, String name) {
    Material mat = new Material();
    FBXMaterial material = null;
    Stack<Connect> conns = mFbx.connections.connections;
    int num = conns.size();
    String materialName = null;
    for (int i = 0; i < num; ++i) {
        if (conns.get(i).object2.equals(name)) {
            materialName = conns.get(i).object1;
            break;
        }
    }
    if (materialName != null) {
        Stack<FBXMaterial> materials = mFbx.objects.materials;
        num = materials.size();
        for (int i = 0; i < num; ++i) {
            if (materials.get(i).name.equals(materialName)) {
                material = materials.get(i);
                break;
            }
        }
    }
    if (material != null) {
        mat.setDiffuseMethod(new DiffuseMethod.Lambert());
        mat.enableLighting(true);
        Vector3 color = material.properties.diffuseColor;
        mat.setColor(Color.rgb((int) (color.x * 255.f), (int) (color.y * 255.f), (int) (color.z * 255.f)));
        color = material.properties.ambientColor;
        mat.setAmbientColor(Color.rgb((int) (color.x * 255.f), (int) (color.y * 255.f), (int) (color.z * 255.f)));
        float intensity = material.properties.ambientFactor.floatValue();
        mat.setAmbientIntensity(intensity, intensity, intensity);
        if (material.shadingModel.equals("phong")) {
            SpecularMethod.Phong method = new SpecularMethod.Phong();
            if (material.properties.specularColor != null) {
                color = material.properties.specularColor;
                method.setSpecularColor(Color.rgb((int) (color.x * 255.f), (int) (color.y * 255.f), (int) (color.z * 255.f)));
            }
            if (material.properties.shininess != null)
                method.setShininess(material.properties.shininess);
        }
    }
    return mat;
}
Also used : Connect(org.rajawali3d.loader.fbx.FBXValues.Connections.Connect) FBXMaterial(org.rajawali3d.loader.fbx.FBXValues.Objects.FBXMaterial) Material(org.rajawali3d.materials.Material) FBXMaterial(org.rajawali3d.loader.fbx.FBXValues.Objects.FBXMaterial) Vector3(org.rajawali3d.math.vector.Vector3) SpecularMethod(org.rajawali3d.materials.methods.SpecularMethod) DiffuseMethod(org.rajawali3d.materials.methods.DiffuseMethod)

Example 19 with Material

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

the class LoaderMD5Mesh method createObjects.

private void createObjects() throws TextureException, ParsingException, SkeletalAnimationException {
    SkeletalAnimationObject3D root = new SkeletalAnimationObject3D();
    root.uBoneMatrix = mBindPoseMatrix;
    root.mInverseBindPoseMatrix = mInverseBindPoseMatrix;
    root.setJoints(mJoints);
    mRootObject = root;
    for (int i = 0; i < mNumMeshes; ++i) {
        SkeletonMeshData mesh = mMeshes[i];
        SkeletalAnimationChildObject3D o = new SkeletalAnimationChildObject3D();
        o.setData(mesh.vertices, GLES20.GL_STREAM_DRAW, mesh.normals, GLES20.GL_STREAM_DRAW, mesh.textureCoordinates, GLES20.GL_STATIC_DRAW, null, GLES20.GL_STATIC_DRAW, mesh.indices, GLES20.GL_STATIC_DRAW, false);
        o.setMaxBoneWeightsPerVertex(mesh.maxBoneWeightsPerVertex);
        o.setSkeletonMeshData(mesh.numVertices, mesh.boneVertices, mesh.numWeights, mesh.boneWeights);
        o.setName("MD5Mesh_" + i);
        o.setSkeleton(mRootObject);
        o.setInverseZScale(true);
        boolean hasTexture = mesh.textureName != null && mesh.textureName.length() > 0;
        Material mat = new Material();
        mat.addPlugin(new SkeletalAnimationMaterialPlugin(mNumJoints, mesh.maxBoneWeightsPerVertex));
        mat.enableLighting(true);
        mat.setDiffuseMethod(new DiffuseMethod.Lambert());
        o.setMaterial(mat);
        if (!hasTexture) {
            o.setColor(0xff000000 + (int) (Math.random() * 0xffffff));
        } else {
            int identifier = mResources.getIdentifier(mesh.textureName, "drawable", mResources.getResourcePackageName(mResourceId));
            if (identifier == 0) {
                throw new ParsingException("Couldn't find texture " + mesh.textureName);
            }
            mat.setColorInfluence(0);
            mat.addTexture(new Texture("md5tex" + i, identifier));
        }
        mRootObject.addChild(o);
        mesh.destroy();
        mesh = null;
    }
}
Also used : SkeletalAnimationChildObject3D(org.rajawali3d.animation.mesh.SkeletalAnimationChildObject3D) ParsingException(org.rajawali3d.loader.ParsingException) SkeletalAnimationMaterialPlugin(org.rajawali3d.materials.plugins.SkeletalAnimationMaterialPlugin) DiffuseMethod(org.rajawali3d.materials.methods.DiffuseMethod) SkeletalAnimationObject3D(org.rajawali3d.animation.mesh.SkeletalAnimationObject3D) Material(org.rajawali3d.materials.Material) Texture(org.rajawali3d.materials.textures.Texture) SkeletonJoint(org.rajawali3d.animation.mesh.SkeletalAnimationFrame.SkeletonJoint)

Example 20 with Material

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

the class PipRenderer method initScene.

@Override
public void initScene() {
    mMainQuadMaterial = new Material();
    mMainQuadMaterial.setColorInfluence(0);
    mMiniQuadMaterial = new Material();
    mMiniQuadMaterial.setColorInfluence(0);
    mMainQuad = new WorkaroundScreenQuad();
    mMainQuad.setMaterial(mMainQuadMaterial);
    mMainQuad.setTransparent(true);
    // Set-up viewport dimensions of mini quad for touch event processing
    setupMiniTouchLimits();
    mMiniQuad = new WorkaroundScreenQuad();
    // Set the size of the mini view using a scale factor (mPipScale times the main view)
    mMiniQuad.setScale(mPipScale);
    // Position the mini view in the top right corner
    // For X and Y, the position is:
    //   50% screen shift to the right/top minus half the size of the minimap to bring it back
    //   left/bottom into full view plus a little bit more left/bottom to leave margin
    mMiniQuad.setX(.5d - mPipScale / 2d - mPipMarginX / mDefaultViewportWidth);
    mMiniQuad.setY(.5d - mPipScale / 2d - mPipMarginY / mDefaultViewportHeight);
    mMiniQuad.setMaterial(mMiniQuadMaterial);
    mMainRenderTarget = new RenderTarget("pipMainRT", mDefaultViewportWidth, mDefaultViewportHeight);
    mMainRenderTarget.setFullscreen(false);
    mMiniRenderTarget = new RenderTarget("pipMiniRT", mDefaultViewportWidth, mDefaultViewportHeight);
    mMiniRenderTarget.setFullscreen(false);
    addRenderTarget(mMainRenderTarget);
    addRenderTarget(mMiniRenderTarget);
    mCompositeScene = getCurrentScene();
    mCompositeScene.addChild(mMainQuad);
    mCompositeScene.addChild(mMiniQuad);
    try {
        mMiniQuadMaterial.addTexture(mMiniRenderTarget.getTexture());
        mMainQuadMaterial.addTexture(mMainRenderTarget.getTexture());
    } catch (ATexture.TextureException e) {
        e.printStackTrace();
    }
    // Init main scene
    mMainRenderer.initScene();
    // Init mini scene
    mMiniRenderer.initScene();
}
Also used : ATexture(org.rajawali3d.materials.textures.ATexture) WorkaroundScreenQuad(org.rajawali3d.renderer.pip.WorkaroundScreenQuad) 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