Skip to content

Commit 318383d

Browse files
committed
light rendering issues and bugs fixed #125
1 parent 6e0ff77 commit 318383d

28 files changed

+793
-406
lines changed

.gitignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,10 @@
11
/bin
2+
.gradle/
3+
.idea/
4+
app/build/generated/
5+
app/build/intermediates/
6+
app/build/outputs/apk/debug/
7+
app/build/outputs/logs/
8+
app/build/reports/
9+
build/
10+
local.properties

README.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,12 @@ The application does not use any third party library.
1313
* Collada format (DAE): https://en.wikipedia.org/wiki/COLLADA
1414

1515

16-
News (20/10/2019)
16+
News (06/11/2019)
1717
=================
1818

19-
* New: Stereoscopic rendering: anaglyph (red-green glasses) & VR glasses (cardboard)
20-
* Fix: Bugs fixed - better support for collada DAE format - multiple geometries support
21-
* New: Engine refactoring
22-
19+
* Fix: Shader lightning fixed !
20+
* Fix: Better support for multiple geometries
21+
* Fix: Bugs fixed
2322

2423

2524
Demo
@@ -180,6 +179,9 @@ ChangeLog
180179

181180
(f) fixed, (i) improved, (n) new feature
182181

182+
- 2.6.1 (06/10/2019)
183+
- (f) fixed light rendering issues on shaders #125
184+
- (f) fixed bugs when DAE had multiple geometries #125
183185
- 2.6.0 (20/10/2019)
184186
- (n) #81 Support for collada files with multiple geometries
185187
- (f) #94 fixed setVisible(boolean)

app/app.iml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,21 +86,33 @@
8686
<sourceFolder url="file://$MODULE_DIR$/src/test/shaders" isTestSource="true" />
8787
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/assets" />
8888
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/blame" />
89+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/build-info" />
90+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/builds" />
8991
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/check-manifest" />
9092
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/classes" />
9193
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental" />
94+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental-classes" />
95+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental-runtime-classes" />
96+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental-verifier" />
97+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/instant-run-apk" />
98+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/instant-run-main-apk-res" />
9299
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/javaPrecompile" />
93100
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/jniLibs" />
101+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/manifest-checker" />
94102
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/manifests" />
95103
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/prebuild" />
96104
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/processing-tools" />
105+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/reload-dex" />
97106
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/res" />
107+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/resources" />
98108
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/rs" />
99109
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/shaders" />
110+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/split-apk" />
100111
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/splits-support" />
101112
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/symbols" />
102113
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/transforms" />
103114
<excludeFolder url="file://$MODULE_DIR$/build/outputs" />
115+
<excludeFolder url="file://$MODULE_DIR$/build/reports" />
104116
<excludeFolder url="file://$MODULE_DIR$/build/tmp" />
105117
</content>
106118
<orderEntry type="jdk" jdkName="Android API 28 Platform" jdkType="Android SDK" />
2.14 KB
Binary file not shown.

app/src/main/AndroidManifest.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
33
xmlns:tools="http://schemas.android.com/tools"
44
package="org.andresoviedo.dddmodel2"
5-
android:versionCode="22"
6-
android:versionName="2.6.0" >
5+
android:versionCode="23"
6+
android:versionName="2.6.1" >
77

88
<uses-sdk
99
android:minSdkVersion="14"

app/src/main/java/org/andresoviedo/app/model3D/demo/SceneLoader.java

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ public class SceneLoader implements LoaderTask.Callback {
7171
/**
7272
* Whether to draw face normals. Normally used to debug models
7373
*/
74+
// TODO: toggle feature normals + blending
7475
private boolean drawNormals = false;
7576
/**
7677
* Whether to draw using textures
@@ -251,19 +252,19 @@ public synchronized List<Object3DData> getObjects() {
251252

252253
public void toggleWireframe() {
253254
if (!this.drawWireframe && !this.drawingPoints && !this.drawSkeleton){
254-
this.drawWireframe = true;
255-
makeToastText("Wireframe", Toast.LENGTH_SHORT);
255+
this.drawWireframe = true;
256+
makeToastText("Wireframe", Toast.LENGTH_SHORT);
256257
} else if (!this.drawingPoints && !this.drawSkeleton){
257-
this.drawWireframe = false;
258-
this.drawingPoints = true;
259-
makeToastText("Points", Toast.LENGTH_SHORT);
258+
this.drawWireframe = false;
259+
this.drawingPoints = true;
260+
makeToastText("Points", Toast.LENGTH_SHORT);
260261
} else if (!this.drawSkeleton){
261-
this.drawingPoints = false;
262-
this.drawSkeleton = true;
263-
makeToastText("Skeleton", Toast.LENGTH_SHORT);
262+
this.drawingPoints = false;
263+
this.drawSkeleton = true;
264+
makeToastText("Skeleton", Toast.LENGTH_SHORT);
264265
} else {
265-
this.drawSkeleton = false;
266-
makeToastText("Faces", Toast.LENGTH_SHORT);
266+
this.drawSkeleton = false;
267+
makeToastText("Faces", Toast.LENGTH_SHORT);
267268
}
268269
requestRender();
269270
}
@@ -321,18 +322,14 @@ public void toggleLighting() {
321322
}
322323

323324
public void toggleAnimation() {
324-
if (!this.doAnimation && !this.showBindPose){
325+
if (!this.doAnimation){
325326
this.doAnimation = true;
327+
this.showBindPose = false;
326328
makeToastText("Animation on", Toast.LENGTH_SHORT);
327-
}
328-
else if (!this.showBindPose) {
329-
this.doAnimation = true;
330-
this.showBindPose = true;
331-
makeToastText("Bind pose", Toast.LENGTH_SHORT);
332329
} else {
333330
this.doAnimation = false;
334-
this.showBindPose = false;
335-
makeToastText("Animation off", Toast.LENGTH_SHORT);
331+
this.showBindPose = true;
332+
makeToastText("Bind pose", Toast.LENGTH_SHORT);
336333
}
337334
}
338335

@@ -500,4 +497,8 @@ public void processTouch(float x, float y) {
500497
public void processMove(float dx1, float dy1) {
501498
userHasInteracted = true;
502499
}
500+
501+
public boolean isRotatingLight() {
502+
return rotatingLight;
503+
}
503504
}

app/src/main/java/org/andresoviedo/app/model3D/view/ModelRenderer.java

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -277,15 +277,26 @@ private void onDrawFrame(float[] viewMatrix, float[] projectionMatrix, float[] v
277277

278278
Object3D lightBulbDrawer = drawer.getPointDrawer();
279279

280-
Matrix.multiplyMM(modelViewMatrix, 0, viewMatrix, 0, scene.getLightBulb().getModelMatrix(), 0);
281-
282-
// Calculate position of the light in eye space to support lighting
283-
Matrix.multiplyMV(lightPosInEyeSpace, 0, modelViewMatrix, 0, scene.getLightPosition(), 0);
284-
285-
// Draw a point that represents the light bulb
286-
lightBulbDrawer.draw(scene.getLightBulb(), projectionMatrix, viewMatrix, -1, lightPosInEyeSpace,
287-
colorMask);
280+
// Calculate position of the light in world space to support lighting
281+
if (scene.isRotatingLight()) {
282+
Matrix.multiplyMV(lightPosInEyeSpace, 0, scene.getLightBulb().getModelMatrix(), 0, scene.getLightPosition(), 0);
283+
// Draw a point that represents the light bulb
284+
lightBulbDrawer.draw(scene.getLightBulb(), projectionMatrix, viewMatrix, -1, lightPosInEyeSpace,
285+
colorMask);
286+
} else {
287+
// FIXME: memory leak
288+
lightPosInEyeSpace = new float[]{scene.getCamera().xPos, scene.getCamera().yPos,
289+
scene.getCamera().zPos, 0f};
290+
}
288291

292+
// FIXME: memory leak
293+
if (scene.isDrawNormals()) {
294+
lightBulbDrawer.draw(Object3DBuilder.buildLine(new float[]{lightPosInEyeSpace[0],
295+
lightPosInEyeSpace[1], lightPosInEyeSpace[2], 0, 0, 0}), projectionMatrix,
296+
viewMatrix, -1,
297+
lightPosInEyeSpace,
298+
colorMask);
299+
}
289300
}
290301

291302
// draw axis
@@ -415,7 +426,9 @@ else if (scene.isDrawSkeleton() && objData instanceof AnimatedModel && ((Animate
415426
}
416427
}
417428
if (normalData != null) {
418-
Object3D normalsDrawer = drawer.getFaceNormalsDrawer();
429+
Object3D normalsDrawer = drawer.getDrawer(normalData,false,false,scene.isDoAnimation(),
430+
false);
431+
animator.update(normalData, scene.isShowBindPose());
419432
normalsDrawer.draw(normalData, projectionMatrix, viewMatrix, -1, null);
420433
}
421434
}

engine/engine.iml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@
8787
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/shaders" isTestSource="true" />
8888
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/annotations" />
8989
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/attr" />
90+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/blame" />
9091
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/check-manifest" />
9192
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/classes" />
9293
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/extractedTypedefs" />

engine/src/main/java/org/andresoviedo/android_3d_model_engine/drawer/DrawerImpl.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -137,9 +137,9 @@ public void draw(Object3DData obj, float[] pMatrix, float[] vMatrix, int drawMod
137137
mTextureHandle = setTexture(obj, textureId);
138138
}
139139

140-
// light rendering needs mv matrix
141-
if (supportsMvMatrix()) {
142-
setMvMatrix(mvMatrix);
140+
// light rendering needs the model matrix
141+
if (supportsMMatrix()) {
142+
setMMatrix(mMatrix);
143143
}
144144

145145
// TODO: remove this null check
@@ -288,16 +288,16 @@ private void setLightPos(float[] lightPosInEyeSpace) {
288288
GLES20.glUniform3f(mLightPosHandle, lightPosInEyeSpace[0], lightPosInEyeSpace[1], lightPosInEyeSpace[2]);
289289
}
290290

291-
private boolean supportsMvMatrix() {
291+
private boolean supportsMMatrix() {
292292
return features.contains("u_MVMatrix");
293293
}
294294

295-
private void setMvMatrix(float[] mvMatrix) {
295+
private void setMMatrix(float[] modelMatrix) {
296296
int mMVMatrixHandle = GLES20.glGetUniformLocation(mProgram, "u_MVMatrix");
297297
GLUtil.checkGlError("glGetUniformLocation");
298298

299299
// Pass in the modelview matrix.
300-
GLES20.glUniformMatrix4fv(mMVMatrixHandle, 1, false, mvMatrix, 0);
300+
GLES20.glUniformMatrix4fv(mMVMatrixHandle, 1, false, modelMatrix, 0);
301301
GLUtil.checkGlError("glUniformMatrix4fv");
302302
}
303303

engine/src/main/java/org/andresoviedo/android_3d_model_engine/model/AnimatedModel.java

Lines changed: 0 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,9 @@ public class AnimatedModel extends Object3DData {
3131

3232
// cache
3333
private float[][] jointMatrices;
34-
private float[] bindShapeMatrix;
35-
private final float[] newModelMatrix;
3634

3735
public AnimatedModel(FloatBuffer vertexArrayBuffer){
3836
super(vertexArrayBuffer);
39-
this.newModelMatrix = new float[16];
40-
Matrix.setIdentityM(newModelMatrix,0);
4137
}
4238

4339
/**
@@ -118,60 +114,11 @@ public Joint getRootJoint() {
118114
* animation pose.
119115
*/
120116
public float[][] getJointTransforms() {
121-
//addJointsToArray(rootJoint, jointMatrices);
122117
return jointMatrices;
123118
}
124119

125-
/**
126-
* This adds the current model-space transform of a joint (and all of its
127-
* descendants) into an array of transforms. The joint's transform is added
128-
* into the array at the position equal to the joint's index.
129-
*
130-
* @param headJoint
131-
* - the current joint being added to the array. This method also
132-
* adds the transforms of all the descendents of this joint too.
133-
* @param jointMatrices
134-
* - the array of joint transforms that is being filled.
135-
*/
136-
private void addJointsToArray(Joint headJoint, float [][] jointMatrices) {
137-
if (headJoint.getIndex() >= 0) {
138-
jointMatrices[headJoint.getIndex()] = headJoint.getAnimatedTransform();
139-
}
140-
for (int i=0; i<headJoint.getChildren().size(); i++) {
141-
Joint childJoint = headJoint.getChildren().get(i);
142-
addJointsToArray(childJoint, jointMatrices);
143-
}
144-
}
145-
146120
public void updateAnimatedTransform(Joint joint){
147121
jointMatrices[joint.getIndex()] = joint.getAnimatedTransform();
148122
}
149123

150-
// binding coming from skeleton
151-
public void setBindShapeMatrix(float[] bindTransform) {
152-
this.bindShapeMatrix = bindTransform;
153-
this.updateModelMatrix();
154-
}
155-
156-
157-
public float[] getBindShapeMatrix() {
158-
return bindShapeMatrix;
159-
}
160-
161-
@Override
162-
protected void updateModelMatrix() {
163-
super.updateModelMatrix();
164-
if (this.bindShapeMatrix == null){
165-
// geometries not linked to any joint does not have bind shape transform
166-
System.arraycopy(super.modelMatrix,0,this.newModelMatrix,0,16);
167-
} else {
168-
Matrix.multiplyMM(newModelMatrix, 0, super.modelMatrix, 0, this.bindShapeMatrix, 0);
169-
}
170-
}
171-
172-
@Override
173-
public float[] getModelMatrix() {
174-
return this.newModelMatrix;
175-
}
176-
177124
}

0 commit comments

Comments
 (0)