Comments (4)
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.
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.
Ir order to support multiple textures there is 2 options:
-
Break the mesh into multiple objects, so you can map the texture independently to every object.
-
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.
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)
- normals,How to configure a picture in code? Looking forward to your reply HOT 2
- improve demo feature
- implement geometry demo
- rename packages and rebrand to org.the3deer
- F-Droid build failed HOT 5
- How to rotate camera on Y axis by angle (-180 degrees ~ 180 degrees)
- I want to load a single model directly from REPO_URL HOT 1
- Load Texture from picture does not work
- How to display text under each object? I tried many methods but failed
- Load the text record for reference to anyone who encounters the same problem HOT 1
- How to add a sliding buffer effect when the gesture is dragged up HOT 1
- Some GLTF model load failed HOT 1
- lighting effects HOT 2
- How to display in AR?
- Can't build
- Camera lag
- The problem that the bounding box is not drawn
- Can we add jpeg or PNG file on GLTF file on specific position using library settings or functions
- Using android-3D-model-viewer as library
- The loaded 3D model can be deleted and then reloaded with a new one
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from android-3d-model-viewer.