Giter VIP home page Giter VIP logo

Comments (4)

liyihongcug avatar liyihongcug commented on May 22, 2024

Another prolem:
I need only mapping one face texture mapping of 8 faces.
I try it and this software api can't support it. Please think it over.
I only handle with one texture mapping of many faces.

from android-3d-model-viewer.

andresoviedo avatar andresoviedo commented on May 22, 2024

Hey body. Support for multiple textures is not implemented.
I am wondering if it's possible to map all the cube faces with just 1 bitmap.
Gonna change the title to add the feature in the future ;)

from android-3d-model-viewer.

andresoviedo avatar andresoviedo commented on May 22, 2024

Ir order to support multiple textures there is 2 options:

  1. Break the mesh into multiple objects, so you can map the texture independently to every object.

  2. Map multiple textures into the FragmentShader, That is:

a. Load multiple textures into opengl. Change this method so you can load multiple textures (as many as you like) instead of only 1:
https://github.com/andresoviedo/android-3D-model-viewer/blob/master/app/src/main/java/org/andresoviedo/app/model3D/util/GLUtil.java#L104

final int[] textureId = new int[NUMBER_OF_TEXTURES_YOU_WANT];
GLES20.glGenTextures(1, textureId, 0);
GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textureId[0]);
GLUtils.texImage2D(GLES20.GL_TEXTURE_2D, 0, bitmap0, 0);
GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textureId[1]);
GLUtils.texImage2D(GLES20.GL_TEXTURE_2D, 0, bitmap1, 0);

...

b. In the vertex shader declare an attribute of type int to store the index of the texture unit to use and pass it to the fragment shader:

attribute int a_TexCoordinateUnit;
varying int v_TexCoordinateUnit;
void main(){
  v_TexCoordinateUnit = a_TexCoordinateUnit;
}

c. In the fragment shader, declare an array of sample2D (you may have at most 8 textures active)

uniform sampler2D u_Texture[8];
varying int v_TexCoordinateUnit;
void main(){
  gl_FragColor = v_Color * texture2D(u_Texture[v_TexCoordinateUnit], v_TexCoordinate);
}

d. Load the different texture units into OpenGL as many times as texture units you want to load (maximum 8):

GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textureId[0]);
GLES20.glUniform1i(mTextureUniformHandle, 0);

GLES20.glActiveTexture(GLES20.GL_TEXTURE1);
GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textureId[1]);
GLES20.glUniform1i(mTextureUniformHandle, 1);

...
e. In the obj loader map every vertex with the corresponding texture into an IntBuffer (texture_unit_map)
f. Bind the texture_unit_map array into the vertex shader:

int mTextureCoordinateUnitHandle = GLES20.glGetAttribLocation(mProgram, "a_TexCoordinateUnit");
GLES20.glEnableVertexAttribArray(mTextureCoordinateUnitHandle );
obj.getTextureUnitMap().position(0);
GLES20.glVertexAttribPointer(mTextureCoordinateHandle, 1, GLES20.GL_INT, false, 0, obj.getTextureUnitMap());

from android-3d-model-viewer.

andresoviedo avatar andresoviedo commented on May 22, 2024

Dear @liyihongcug
Latest version of the app should solve most of the texture issues
so I am closing this for now
kind regards

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.