Rajawali / RajawaliExamples

Rajawali 3D Engine for Android Examples
https://github.com/MasDennis/Rajawali
171 stars 145 forks source link

Setting the color of .obj file. #72

Open abhishek1508 opened 7 years ago

abhishek1508 commented 7 years ago

Hello,

I am new to the field of 3D modeling in android. I am trying to load an .obj file (in this case, it is a car) and try to rotate it 360 degrees. I have been successfully able to do that. Now, I am trying to change the color of the car using the code below to black color.

`public class ObjectRenderer extends RajawaliRenderer {

private DirectionalLight directionalLight;
private Object3D mObjectGroup;
private Animation3D mCameraAnim, mLightAnim;

public ObjectRenderer(Context context) {
    super(context);
}

@Override
protected void initScene() {
    getCurrentScene().setBackgroundColor(1.0f, 1.0f, 1.0f, 1.0f);
    getCurrentCamera().setZ(16);

    LoaderOBJ objParser = new LoaderOBJ(mContext.getResources(), mTextureManager, R.raw.bmw);
    try {
        objParser.parse();
        mObjectGroup = objParser.getParsedObject();
        mObjectGroup.setScale(0.04f);
        mObjectGroup.setPosition(0.0f, -1.5f, 5.0f);
        //mObjectGroup.setColor(Color.BLACK) // I have tried this as well

        Material simple = new Material();
        simple.setColor(Color.BLACK); //I am setting the color here to black
        mObjectGroup.setMaterial(simple);

        getCurrentScene().addChild(mObjectGroup);

        mCameraAnim = new RotateOnAxisAnimation(Vector3.Axis.Y, 360);
        mCameraAnim.setDurationMilliseconds(8000);
        mCameraAnim.setRepeatMode(Animation.RepeatMode.INFINITE);
        mCameraAnim.setTransformable3D(mObjectGroup);
    } catch (ParsingException e) {
        e.printStackTrace();
    }
    getCurrentScene().registerAnimation(mCameraAnim);
    mCameraAnim.play();
}

@Override
public void onOffsetsChanged(float xOffset, float yOffset, float xOffsetStep, float yOffsetStep, int xPixelOffset, int yPixelOffset) {
}

@Override
public void onTouchEvent(MotionEvent event) {
}

}`

The issue is I cannot see the color change on the object. This is what I see no matter what color I add.

screenshot_2017-10-04-06-05-06-197_com application threesixtyrotation

Can please someone tell me if I am missing something.

jwoolston commented 7 years ago

Before setting the material add sjmple.setColorInfluence(1.0f)

abhishek1508 commented 7 years ago

@jwoolston Thanks for the reply. I added this line of code. It still doesn't work. I also tried to add a texture to the Material. That doesn't work as well. simple.addTexture(new Texture("texture", R.drawable.checkerboard));

SenthilPrabhuBose commented 6 years ago

@abhishek1508 I am also struck with the same issue. Is there any solution or work around for this issue.

MrSagarShah commented 6 years ago

@jwoolston Hi I am new to this. As fas as i have read the coloring code for the .obj model is stored in side the .mtl file. So my question is how can i load .mtl file coded color in my .obj model? Thanks

surajappentus commented 10 months ago

Still similar issue facing , please provide solution or (update the library) @jwoolston @abhishek1508 @MrSagarShah @SenthilPrabhuBose @tenaciousRas

Thanks

surajappentus commented 10 months ago
ss_sofa_non_colored