Skip to content

Commit c912076

Browse files
committed
Skeletal animations
1 parent 5a4ab3d commit c912076

25 files changed

+1186
-165
lines changed

README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,10 @@ The purpose of this application is to learn and share how to draw using OpenGL l
1212
* STereoLithography format (STL): https://en.wikipedia.org/wiki/STL_(file_format)
1313

1414

15-
News (21/11/2017)
15+
News (24/11/2017)
1616
=================
1717

18+
* Support for collada files with skeletal animations :)
1819
* Fixed #28: Load texture feature is now available
1920
* Fixed #18: Removed asReadOnlyBuffer() - not working on Android 7
2021
* Enhancement #17: Added support for TLS format
@@ -50,7 +51,6 @@ Whats next
5051
==========
5152

5253
* Stabilize app performance
53-
* Skeletal animations
5454
* Code refactoring
5555
* Carboard support
5656
* Chromecast support
@@ -127,6 +127,9 @@ ChangeLog
127127

128128
(f) fixed, (i) improved, (n) new feature
129129

130+
- 2.0.0 (24/11/2017)
131+
- (n) Support for collada files with skeletal animations :)
132+
130133
- 1.4.1 (21/11/2017)
131134
- (f) #29: Crash loading obj with only vertex info
132135

app/build/outputs/apk/app-release.apk

536 KB
Binary file not shown.

app/src/main/AndroidManifest.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
33
package="org.andresoviedo.dddmodel2"
4-
android:versionCode="13"
5-
android:versionName="1.4.1" >
4+
android:versionCode="14"
5+
android:versionName="2.0.0" >
66

77
<uses-sdk
88
android:minSdkVersion="8"

app/src/main/assets/models/cowboy.dae

Lines changed: 901 additions & 0 deletions
Large diffs are not rendered by default.

app/src/main/assets/models/cowboy.png

452 KB
Loading

app/src/main/java/org/andresoviedo/app/model3D/animation/Animator.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import android.opengl.Matrix;
44
import android.os.SystemClock;
5+
import android.util.Log;
56

67
import java.util.HashMap;
78
import java.util.Map;
@@ -68,7 +69,7 @@ public void update(Object3DData obj) {
6869
* reset, causing the animation to loop.
6970
*/
7071
private void increaseAnimationTime(AnimatedModel obj) {
71-
animationTime += SystemClock.uptimeMillis();
72+
animationTime += 0.01; // System.nanoTime();
7273
if (animationTime > obj.getAnimation().getLength()) {
7374
this.animationTime %= obj.getAnimation().getLength();
7475
}
@@ -139,8 +140,9 @@ private void applyPoseToJoints(Map<String, float[]> currentPose, Joint joint, fl
139140
for (Joint childJoint : joint.children) {
140141
applyPoseToJoints(currentPose, childJoint, currentTransform);
141142
}
142-
Matrix.multiplyMM(currentTransform,0,joint.getInverseBindTransform(), 0, currentTransform, 0);
143-
joint.setAnimationTransform(currentTransform);
143+
float[] animationTransform = new float[16];
144+
Matrix.multiplyMM(animationTransform, 0, currentTransform, 0, joint.getInverseBindTransform(),0);
145+
joint.setAnimationTransform(animationTransform);
144146
}
145147

146148
/**

app/src/main/java/org/andresoviedo/app/model3D/animation/JointTransform.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,8 @@ protected float[] getLocalTransform() {
5656
float[] matrix = new float[16];
5757
Matrix.setIdentityM(matrix,0);
5858
Matrix.translateM(matrix,0,matrix,0,position.x,position.y,position.z);
59-
float[] ret = new float[16];
60-
Matrix.multiplyMM(ret,0,matrix,0,rotation.toRotationMatrix(),0);
61-
return ret;
59+
Matrix.multiplyMM(matrix,0,matrix,0,rotation.toRotationMatrix(),0);
60+
return matrix;
6261
}
6362

6463
/**

app/src/main/java/org/andresoviedo/app/model3D/entities/Camera.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public class Camera {
5454

5555
public Camera() {
5656
// Initialize variables...
57-
this(0, 0, 3, 0, 0, -1, 0, 1, 0);
57+
this(0, 0, 6, 0, 0, -1, 0, 1, 0);
5858

5959
}
6060

@@ -198,7 +198,7 @@ private boolean isOutOfBounds(float[] buffer) {
198198
buffer[0] / buffer[3]
199199
, buffer[1] / buffer[3]
200200
, buffer[2] / buffer[3] )) {
201-
Log.d("Camera", "Inside bounds of '" + objects.get(i).getId() + "'");
201+
Log.i("Camera", "Inside bounds of '" + objects.get(i).getId() + "'");
202202
return true;
203203
}
204204
}

app/src/main/java/org/andresoviedo/app/model3D/model/Object3D.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
public interface Object3D {
44

55
// number of coordinates per vertex in this array
6-
final int COORDS_PER_VERTEX = 3;
7-
final int VERTEX_STRIDE = COORDS_PER_VERTEX * 4; // 4 bytes per
6+
int COORDS_PER_VERTEX = 3;
7+
int VERTEX_STRIDE = COORDS_PER_VERTEX * 4; // 4 bytes per
88

9-
final float[] DEFAULT_COLOR = { 1.0f, 0.0f, 0, 1.0f };
9+
float[] DEFAULT_COLOR = { 1.0f, 0.0f, 0, 1.0f };
1010

1111
void draw(Object3DData obj, float[] pMatrix, float[] vMatrix, int textureId, float[] lightPosInEyeSpace);
1212

app/src/main/java/org/andresoviedo/app/model3D/model/Object3DBuilder.java

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ public static Object3DData buildAxis() {
340340
public static Object3DData buildCubeV1() {
341341
return new Object3DData(
342342
createNativeByteBuffer(cubePositionData.length * 4).asFloatBuffer().put(cubePositionData))
343-
.setDrawMode(GLES20.GL_TRIANGLES).setId("cubeV1").centerAndScale(1.0f);
343+
.setDrawMode(GLES20.GL_TRIANGLES).setId("cubeV1").centerAndScale(1.0f).setFaces(new Faces(8));
344344
}
345345

346346
public static Object3DData buildCubeV1_with_normals() {
@@ -350,22 +350,22 @@ public static Object3DData buildCubeV1_with_normals() {
350350
createNativeByteBuffer(cubeColorData.length * 4).asFloatBuffer().put(cubeColorData))
351351
.setVertexNormalsArrayBuffer(
352352
createNativeByteBuffer(cubeNormalData.length * 4).asFloatBuffer().put(cubeNormalData))
353-
.setDrawMode(GLES20.GL_TRIANGLES).setId("cubeV1_light").centerAndScale(1.0f);
353+
.setDrawMode(GLES20.GL_TRIANGLES).setId("cubeV1_light").centerAndScale(1.0f).setFaces(new Faces(8));
354354
}
355355

356356
public static Object3DData buildSquareV2() {
357-
return new Object3DData(
358-
createNativeByteBuffer(squarePositionData.length * 4).asFloatBuffer().put(squarePositionData),
359-
createNativeByteBuffer(squareDrawOrderData.length * 4).asIntBuffer().put(squareDrawOrderData)
360-
.asReadOnlyBuffer()).setDrawMode(GLES20.GL_TRIANGLES).setId("cubeV2").centerAndScale(1.0f);
357+
IntBuffer drawBuffer = createNativeByteBuffer(squareDrawOrderData.length * 4).asIntBuffer().put(squareDrawOrderData);
358+
FloatBuffer vertexBuffer = createNativeByteBuffer(squarePositionData.length * 4).asFloatBuffer().put(squarePositionData);
359+
return new Object3DData(vertexBuffer,drawBuffer.asReadOnlyBuffer()).setDrawMode(GLES20.GL_TRIANGLES).setId("cubeV2")
360+
.centerAndScale(1.0f).setFaces(new Faces(8)).setDrawOrder(drawBuffer);
361361
}
362362

363363
public static Object3DData buildCubeV3(byte[] textureData) {
364364
return new Object3DData(
365365
createNativeByteBuffer(cubePositionData.length * 4).asFloatBuffer().put(cubePositionData),
366366
createNativeByteBuffer(cubeTextureCoordinateData.length * 4).asFloatBuffer()
367367
.put(cubeTextureCoordinateData).asReadOnlyBuffer(),
368-
textureData).setDrawMode(GLES20.GL_TRIANGLES).setId("cubeV3").centerAndScale(1.0f);
368+
textureData).setDrawMode(GLES20.GL_TRIANGLES).setId("cubeV3").centerAndScale(1.0f).setFaces(new Faces(8));
369369
}
370370

371371
public static Object3DData buildCubeV4(byte[] textureData) {
@@ -374,7 +374,7 @@ public static Object3DData buildCubeV4(byte[] textureData) {
374374
createNativeByteBuffer(cubeColorData.length * 4).asFloatBuffer().put(cubeColorData).asReadOnlyBuffer(),
375375
createNativeByteBuffer(cubeTextureCoordinateData.length * 4).asFloatBuffer()
376376
.put(cubeTextureCoordinateData).asReadOnlyBuffer(),
377-
textureData).setDrawMode(GLES20.GL_TRIANGLES).setId("cubeV4").centerAndScale(1.0f);
377+
textureData).setDrawMode(GLES20.GL_TRIANGLES).setId("cubeV4").centerAndScale(1.0f).setFaces(new Faces(8));
378378
}
379379

380380
public static Object3DData loadV5(AssetManager assets, String assetDir, String assetFilename) {
@@ -397,6 +397,7 @@ public static Object3DData loadV5(AssetManager assets, String assetDir, String a
397397
data3D.setId(assetFilename);
398398
data3D.setAssetsDir(assetDir);
399399
data3D.setDimensions(wfl.getDimensions());
400+
//data3D.centerAndScale(5,new float[]{0,0,0});
400401
data3D.centerScale();
401402

402403
data3D.setDrawMode(GLES20.GL_TRIANGLES);
@@ -483,7 +484,7 @@ public static Object3DData generateArrays(AssetManager assets, Object3DData obj)
483484

484485
// build file normals
485486
final FloatBuffer vertexNormalsBuffer = obj.getNormals();
486-
if (vertexNormalsBuffer.capacity() > 0) {
487+
if (vertexNormalsBuffer != null && vertexNormalsBuffer.capacity() > 0) {
487488
Log.i("Object3DBuilder", "Populating normals buffer...");
488489
for (int n=0; n<faces.facesNormIdxs.size(); n++) {
489490
int[] normal = faces.facesNormIdxs.get(n);

0 commit comments

Comments
 (0)