Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement API to change model colors #6

Closed
ritup22 opened this issue Feb 21, 2017 · 18 comments
Closed

Implement API to change model colors #6

ritup22 opened this issue Feb 21, 2017 · 18 comments

Comments

@ritup22
Copy link

ritup22 commented Feb 21, 2017

Not able to load correct .obj & .mtl
Please check here http://3dviewer.net/ ToyPlane.obj
It shows orange
Can you please help me with this?

@andresoviedo
Copy link
Member

Hi ritup. Are you trying to load ToyPlane.obj from external SD card? If so, please attach the log to see what error you have. KR

@ritup22
Copy link
Author

ritup22 commented Feb 22, 2017

No I am not having error
It shows green color in app & in online site it shows orange color

@andresoviedo
Copy link
Member

andresoviedo commented Feb 22, 2017 via email

@ritup22
Copy link
Author

ritup22 commented Feb 23, 2017 via email

@andresoviedo
Copy link
Member

Hey. Not sure to understand your last question. What API? The different Kd colors are linked to the different parts of the 3d obj file.

In the ToyModel example you have 3 colors only and a texture.

@ritup22
Copy link
Author

ritup22 commented Feb 23, 2017 via email

@andresoviedo
Copy link
Member

hi @ritup22 not sure to understand. are you trying to change the colors of the loaded model in your app?
regards

@ritup22
Copy link
Author

ritup22 commented Feb 28, 2017 via email

@andresoviedo
Copy link
Member

Hey. The change colors feature is not implemented.
If you want to do it yourself, you would have to post process the materials in Object3DData.java
Here is were the colors are generated for 3D Object3DBuilder.java#L515
I am chaning the title of this issue to "Implement API to change model colors"

@andresoviedo andresoviedo changed the title Not able to load correct .obj & .mtl Implement API to change model colors Feb 28, 2017
@biswanathsahoo
Copy link

Hi,
I am also getting the same issue. When I am loading a model, it's color is changing. The original color of the model is white but when I am loading the model its color is changing to green.

@sk8darr
Copy link

sk8darr commented Feb 7, 2019

Hi @andresoviedo,

I am also trying to implement this feature. I founded where can we change the material (in my case) attached to the obj but this is not showing when the object is already created and showing, i guess i need to refresh the scene or something...

How can i re-build or re-read the object to showing the changes?

Regards

@andresoviedo
Copy link
Member

Hi, Replace the setColor function in Object3DData.java like this:

public Object3DData setColor(float[] color) {
    // color variable when using single color
	this.color = color;
	
	// color buffer when using multiple colors
	if (this.vertexColorsArrayBuffer != null && this.vertexColorsArrayBuffer.capacity() > 0){
		for (int i=0; i<vertexColorsArrayBuffer.capacity(); i+=4){
			vertexColorsArrayBuffer.put(i,color[0]);
                            vertexColorsArrayBuffer.put(i+1,color[1]);
                            vertexColorsArrayBuffer.put(i+2,color[2]);
                            vertexColorsArrayBuffer.put(i+3,color[3]);
		}
	}
	return this;
}

Then call

obj.setColor(new float[] { 1f, 0f, 1f, 1f });

@sk8darr
Copy link

sk8darr commented Feb 7, 2019

// color buffer when using multiple colors
if (this.vertexColorsArrayBuffer != null && this.vertexColorsArrayBuffer.capacity() > 0){
for (int i=0; i<vertexColorsArrayBuffer.capacity(); i+=4){
vertexColorsArrayBuffer.put(i,color[0]);
vertexColorsArrayBuffer.put(i+1,color[1]);
vertexColorsArrayBuffer.put(i+2,color[2]);
vertexColorsArrayBuffer.put(i+3,color[3]);
}
}

Thanks for the answer. It works fine but this code paint all the object to the specified color. Is there any way to set the color to specified material? This is the code what i've works on

obj.materials.materials["Material.003"]?.kd = WavefrontLoader.Tuple3(0.0f, 0.0f, 0.0f)

obtaining the material and set the color to it.

screenshot_20190207-171232

->

screenshot_20190207-171224

@andresoviedo
Copy link
Member

Hi. If you want to paint yourself the model programmatically, you would have to parse the groups of the model and save it on the Object3DData. Then you will be able to paint them independently, with material or any color.

So, in order to save the groups for later processing, you need at least a structure like this:

IdGroup : gasoline_tank
vertexList:1,2,30,41,1000,etc

IdGroup:. wheels
vertexList:. 23,24,80,2000,etc

With that structure you can populate arrayVertexColorBuffer object.

@sk8darr
Copy link

sk8darr commented Feb 8, 2019

Hi. If you want to paint yourself the model programmatically, you would have to parse the groups of the model and save it on the Object3DData. Then you will be able to paint them independently, with material or any color.

So, in order to save the groups for later processing, you need at least a structure like this:

IdGroup : gasoline_tank
vertexList:1,2,30,41,1000,etc

IdGroup:. wheels
vertexList:. 23,24,80,2000,etc

With that structure you can populate arrayVertexColorBuffer object.

Hi. Ok, so that means i need to modify the WavefrontLoader class in the readModel method for parse the group over 'o' rigth?

@andresoviedo
Copy link
Member

@sk8dar yes. You would need to:

  • extend Object3DData with a Map<String,IntBuffer>
  • improve Wavefrontloader to parse groups.

Regards

@andresoviedo
Copy link
Member

API has the method Oject3DData.setColor(float[]) available.

@xiaoxing1992
Copy link

Hi. If you want to paint yourself the model programmatically, you would have to parse the groups of the model and save it on the Object3DData. Then you will be able to paint them independently, with material or any color.
So, in order to save the groups for later processing, you need at least a structure like this:

IdGroup : gasoline_tank
vertexList:1,2,30,41,1000,etc

IdGroup:. wheels
vertexList:. 23,24,80,2000,etc

With that structure you can populate arrayVertexColorBuffer object.

Hi. Ok, so that means i need to modify the WavefrontLoader class in the readModel method for parse the group over 'o' rigth?

Hello you this group of different color inside implements, please can you help me, I need your demo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants