Giter VIP home page Giter VIP logo

Comments (18)

andresoviedo avatar andresoviedo commented on May 22, 2024 2

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.

from android-3d-model-viewer.

andresoviedo avatar andresoviedo commented on May 22, 2024 1

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 });

from android-3d-model-viewer.

sk8darr avatar sk8darr commented on May 22, 2024 1

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?

from android-3d-model-viewer.

andresoviedo avatar andresoviedo commented on May 22, 2024

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

from android-3d-model-viewer.

ritup22 avatar ritup22 commented on May 22, 2024

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

from android-3d-model-viewer.

andresoviedo avatar andresoviedo commented on May 22, 2024

from android-3d-model-viewer.

ritup22 avatar ritup22 commented on May 22, 2024

from android-3d-model-viewer.

andresoviedo avatar andresoviedo commented on May 22, 2024

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.

from android-3d-model-viewer.

ritup22 avatar ritup22 commented on May 22, 2024

from android-3d-model-viewer.

andresoviedo avatar andresoviedo commented on May 22, 2024

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

from android-3d-model-viewer.

ritup22 avatar ritup22 commented on May 22, 2024

from android-3d-model-viewer.

andresoviedo avatar andresoviedo commented on May 22, 2024

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"

from android-3d-model-viewer.

biswanathsahoo avatar biswanathsahoo commented on May 22, 2024

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.

from android-3d-model-viewer.

sk8darr avatar sk8darr commented on May 22, 2024

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

from android-3d-model-viewer.

sk8darr avatar sk8darr commented on May 22, 2024

// 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

from android-3d-model-viewer.

andresoviedo avatar andresoviedo commented on May 22, 2024

@sk8dar yes. You would need to:

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

Regards

from android-3d-model-viewer.

andresoviedo avatar andresoviedo commented on May 22, 2024

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

from android-3d-model-viewer.

xiaoxing1992 avatar xiaoxing1992 commented on May 22, 2024

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

from android-3d-model-viewer.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.