Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dae multiple geometries + refactoring #124

Merged
merged 6 commits into from
Oct 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ The application does not use any third party library.
* Collada format (DAE): https://en.wikipedia.org/wiki/COLLADA


News (19/05/2019)
News (22/10/2019)
=================

* New: Stereoscopic rendering: anaglyph (red-green glasses) & VR glasses (cardboard)
* Fix: Bugs fixed - better support for collada DAE format - multiple geometries support
* New: Engine refactoring
* Fix: Bugs fixed



Expand Down Expand Up @@ -180,6 +180,8 @@ ChangeLog

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

- 2.6.0 (22/10/2019)
- (f) Support for collada files with multiple geometries
- 2.5.1 (20/05/2019)
- (f) wavefront loader fixed for faces point to negative indices
- 2.5.0 (19/05/2019)
Expand Down
27 changes: 9 additions & 18 deletions app/app.iml
Original file line number Diff line number Diff line change
Expand Up @@ -86,42 +86,33 @@
<sourceFolder url="file://$MODULE_DIR$/src/test/shaders" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/assets" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/blame" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/build-info" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/builds" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/check-manifest" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/classes" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental-classes" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental-runtime-classes" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental-verifier" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/instant-run-apk" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/instant-run-resources" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/javaPrecompile" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/jniLibs" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/manifest-checker" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/manifests" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/prebuild" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/processing-tools" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/reload-dex" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/res" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/resources" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/rs" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/shaders" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/split-apk" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/splits-support" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/symbols" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/transforms" />
<excludeFolder url="file://$MODULE_DIR$/build/outputs" />
<excludeFolder url="file://$MODULE_DIR$/build/tmp" />
</content>
<orderEntry type="jdk" jdkName="Android API 27 Platform" jdkType="Android SDK" />
<orderEntry type="jdk" jdkName="Android API 28 Platform" jdkType="Android SDK" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="Gradle: android.arch.lifecycle:common:1.1.0@jar" level="project" />
<orderEntry type="library" name="Gradle: com.android.support:support-annotations:27.1.1@jar" level="project" />
<orderEntry type="library" name="Gradle: android.arch.core:common:1.1.0@jar" level="project" />
<orderEntry type="library" name="Gradle: com.android.support:support-compat-27.1.1" level="project" />
<orderEntry type="library" name="Gradle: android.arch.lifecycle:runtime-1.1.0" level="project" />
<orderEntry type="library" name="Gradle: com.android.support:collections:28.0.0@jar" level="project" />
<orderEntry type="library" name="Gradle: android.arch.core:common:1.1.1@jar" level="project" />
<orderEntry type="library" name="Gradle: com.android.support:versionedparcelable-28.0.0" level="project" />
<orderEntry type="library" name="Gradle: com.android.support:support-annotations:28.0.0@jar" level="project" />
<orderEntry type="library" name="Gradle: android.arch.lifecycle:common:1.1.1@jar" level="project" />
<orderEntry type="library" name="Gradle: com.android.support:support-compat-28.0.0" level="project" />
<orderEntry type="library" name="Gradle: android.arch.lifecycle:runtime-1.1.1" level="project" />
<orderEntry type="module" module-name="engine" />
<orderEntry type="library" name="Gradle: android-android-27" level="project" />
<orderEntry type="library" name="Gradle: android-android-28" level="project" />
</component>
</module>
8 changes: 4 additions & 4 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 27
compileSdkVersion 28

defaultConfig {
applicationId "org.andresoviedo.dddmodel2"
minSdkVersion 8
targetSdkVersion 27
minSdkVersion 14
targetSdkVersion 28
}

signingConfigs {
Expand All @@ -32,6 +32,6 @@ android {
}

dependencies {
implementation 'com.android.support:support-compat:27.1.1'
implementation 'com.android.support:support-compat:28.0.0'
implementation project(':engine')
}
Binary file modified app/build/outputs/apk/release/app-release.apk
Binary file not shown.
8 changes: 4 additions & 4 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="org.andresoviedo.dddmodel2"
android:versionCode="21"
android:versionName="2.5.1" >
android:versionCode="22"
android:versionName="2.6.0" >

<uses-sdk
android:minSdkVersion=""
android:targetSdkVersion="27"
android:minSdkVersion="14"
android:targetSdkVersion="28"
tools:overrideLibrary="android.support.compat, android.arch.lifecycle" />

<uses-feature
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
public class MainActivity extends Activity {


// Custom handler: org/andresoviedo/app/util/url/android/Handler.class
// Custom handler: org/andresoviedo/util/android/assets/Handler.class
static {
System.setProperty("java.protocol.handler.pkgs", "org.andresoviedo.util.android");
URL.setURLStreamHandlerFactory(new AndroidURLStreamHandlerFactory());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public synchronized boolean onTouchEvent(MotionEvent motionEvent) {
case MotionEvent.ACTION_DOWN:
case MotionEvent.ACTION_POINTER_DOWN:
case MotionEvent.ACTION_HOVER_ENTER:
Log.d(TAG, "Gesture changed...");
Log.v(TAG, "Gesture changed...");
gestureChanged = true;
touchDelay = 0;
lastActionTime = SystemClock.uptimeMillis();
Expand All @@ -115,7 +115,7 @@ public synchronized boolean onTouchEvent(MotionEvent motionEvent) {
x1 = motionEvent.getX();
y1 = motionEvent.getY();
if (gestureChanged) {
Log.d(TAG, "x:" + x1 + ",y:" + y1);
Log.v(TAG, "x:" + x1 + ",y:" + y1);
previousX1 = x1;
previousY1 = y1;
}
Expand All @@ -134,7 +134,7 @@ public synchronized boolean onTouchEvent(MotionEvent motionEvent) {
vector[0] /= len;
vector[1] /= len;

// Log.d(TAG, "x1:" + x1 + ",y1:" + y1 + ",x2:" + x2 + ",y2:" + y2);
// Log.v(TAG, "x1:" + x1 + ",y1:" + y1 + ",x2:" + x2 + ",y2:" + y2);
if (gestureChanged) {
previousX1 = x1;
previousY1 = y1;
Expand Down Expand Up @@ -191,20 +191,20 @@ public synchronized boolean onTouchEvent(MotionEvent motionEvent) {
if (pointerCount == 1 && currentPress1 > 4.0f) {
} else if (pointerCount == 1) {
touchStatus = TOUCH_STATUS_MOVING_WORLD;
// Log.d(TAG, "Translating camera (dx,dy) '" + dx1 + "','" + dy1 + "'...");
// Log.v(TAG, "Translating camera (dx,dy) '" + dx1 + "','" + dy1 + "'...");
dx1 = (float)(dx1 / max * Math.PI * 2);
dy1 = (float)(dy1 / max * Math.PI * 2);
camera.translateCamera(dx1,dy1);
} else if (pointerCount == 2) {
if (fingersAreClosing) {
touchStatus = TOUCH_STATUS_ZOOMING_CAMERA;
float zoomFactor = (length - previousLength) / max * mRenderer.getFar();
Log.i(TAG, "Zooming '" + zoomFactor + "'...");
Log.v(TAG, "Zooming '" + zoomFactor + "'...");
camera.MoveCameraZ(zoomFactor);
}
if (isRotating) {
touchStatus = TOUCH_STATUS_ROTATING_CAMERA;
Log.i(TAG, "Rotating camera '" + Math.signum(rotationVector[2]) + "'...");
Log.v(TAG, "Rotating camera '" + Math.signum(rotationVector[2]) + "'...");
camera.Rotate((float) (Math.signum(rotationVector[2]) / Math.PI) / 4);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ private void onDrawFrame(float[] viewMatrix, float[] projectionMatrix, float[] v
}

if (!infoLogged.containsKey(objData)) {
Log.i("ModelRenderer","Model '"+objData.getId()+"'. Drawer "+drawerObject.getClass().getName());
Log.v("ModelRenderer","Drawing model: "+objData.getId());
infoLogged.put(objData, true);
}

Expand Down Expand Up @@ -359,6 +359,7 @@ else if (scene.isDrawWireframe() && objData.getDrawMode() != GLES20.GL_POINTS
drawerObject.draw(wireframe, projectionMatrix, viewMatrix, wireframe.getDrawMode(),
wireframe.getDrawSize(), textureId, lightPosInEyeSpace,
colorMask);
animator.update(wireframe, scene.isShowBindPose());
}catch(Error e){
Log.e("ModelRenderer",e.getMessage(),e);
}
Expand Down
4 changes: 2 additions & 2 deletions engine/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ android {


defaultConfig {
minSdkVersion 8
targetSdkVersion 27
minSdkVersion 14
targetSdkVersion 28
versionCode 1
versionName "1.0"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,20 +56,17 @@ public Animator() {
* time of the animation, and then applies that pose to all the model's
* joints by setting the joint transforms.
*/
public void update(Object3DData obj) {
this.update(obj,false);
}

public void update(Object3DData obj, boolean bindPoseOnly) {
if (!(obj instanceof AnimatedModel)) {
return;
}

// if (true) return;
AnimatedModel animatedModel = (AnimatedModel)obj;
if (animatedModel.getAnimation() == null) return;

if (!bindPoseOnly) {
if (animatedModel.getAnimation() == null) return;

// add missing key transformations
initAnimation(animatedModel);

Expand All @@ -78,13 +75,16 @@ public void update(Object3DData obj, boolean bindPoseOnly) {

Map<String, float[]> currentPose = calculateCurrentAnimationPose(animatedModel);

applyPoseToJoints(currentPose, (animatedModel).getRootJoint(), IDENTITY_MATRIX, 0);
applyPoseToJoints(animatedModel, currentPose, (animatedModel).getRootJoint(), IDENTITY_MATRIX, 0);
} else {
bindPose((animatedModel).getRootJoint(), IDENTITY_MATRIX);
bindPose(animatedModel, (animatedModel).getRootJoint(), IDENTITY_MATRIX);
}
}

private void bindPose(Joint joint, final float[] parentTransform){
private void bindPose(AnimatedModel animatedModel, Joint joint, final float[] parentTransform){

/*if (cache.containsKey(joint.getName()+"-already-processed"))
return;*/

// performance optimization - reuse buffers
float[] currentTransform = cache.get(joint.getName());
Expand All @@ -98,16 +98,25 @@ private void bindPose(Joint joint, final float[] parentTransform){

// apply calculated transform to inverse matrix for joints only
if (joint.getIndex() >= 0) {
Matrix.multiplyMM(joint.getAnimatedTransform(), 0, currentTransform, 0,
joint.getInverseBindTransform(), 0);
// FIXME: should work also when no skinning data available
if (joint.getInverseBindTransform() != null) {
Matrix.multiplyMM(joint.getAnimatedTransform(), 0, currentTransform, 0,
joint.getInverseBindTransform(), 0);
} else {
System.arraycopy(currentTransform, 0, joint.getAnimatedTransform(), 0, 16);
}
animatedModel.updateAnimatedTransform(joint);

}

// apply transform for joint child
// transform children
for (int i=0; i<joint.getChildren().size(); i++) {
Joint childJoint = joint.getChildren().get(i);
bindPose(childJoint, currentTransform);
bindPose(animatedModel, childJoint, currentTransform);
}

//cache.put(joint.getName()+"-already-processed", new float[0]);
}

private void initAnimation(AnimatedModel animatedModel) {
Expand Down Expand Up @@ -204,7 +213,7 @@ private Map<String, float[]> calculateCurrentAnimationPose(AnimatedModel obj) {
* loaded up to the vertex shader and used to transform the vertices into
* the current pose.
*
* @param currentPose
* @param animatedModel
* - a map of the local-space transforms for all the joints for
* the desired pose. The map is indexed by the name of the joint
* which the transform corresponds to.
Expand All @@ -214,16 +223,16 @@ private Map<String, float[]> calculateCurrentAnimationPose(AnimatedModel obj) {
* - the desired model-space transform of the parent joint for
* the pose.
*/
private void applyPoseToJoints(Map<String, float[]> currentPose, Joint joint, float[] parentTransform, int limit) {
private void applyPoseToJoints(AnimatedModel animatedModel, Map<String,float[]> currentPose, Joint joint, float[]
parentTransform, int limit) {

float[] currentTransform = cache.get(joint.getName());
if (currentTransform == null){
currentTransform = new float[16];
cache.put(joint.getName(), currentTransform);
}

// TODO: implement bind pose
if (limit <= 0){
if (limit <= 0) {
if (currentPose.get(joint.getName()) != null) {
Matrix.multiplyMM(currentTransform, 0, parentTransform, 0, currentPose.get(joint.getName()), 0);
} else {
Expand All @@ -234,16 +243,21 @@ private void applyPoseToJoints(Map<String, float[]> currentPose, Joint joint, fl
}

// calculate animation only if its used by vertices
//joint.calcInverseBindTransform2(parentTransform);
if (joint.getIndex() >= 0) {
Matrix.multiplyMM(joint.getAnimatedTransform(), 0, currentTransform, 0,
joint.getInverseBindTransform(), 0);
// FIXME: should work also when no skinning data available
if (joint.getInverseBindTransform() != null) {
Matrix.multiplyMM(joint.getAnimatedTransform(), 0, currentTransform, 0,
joint.getInverseBindTransform(), 0);
} else {
System.arraycopy(currentTransform, 0, joint.getAnimatedTransform(), 0, 16);
}
animatedModel.updateAnimatedTransform(joint);
}

// transform children
for (int i=0; i<joint.getChildren().size(); i++) {
Joint childJoint = joint.getChildren().get(i);
applyPoseToJoints(currentPose, childJoint, currentTransform, limit-1);
applyPoseToJoints(animatedModel, currentPose, childJoint, currentTransform, limit-1);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public DrawerFactory(Context context) throws IllegalAccessException, IOException
Field[] fields = R.raw.class.getFields();
for (int count = 0; count < fields.length; count++) {
String shaderId = fields[count].getName();
Log.i("DrawerFactory", "Loading shader... " + shaderId);
Log.d("DrawerFactory", "Loading shader... " + shaderId);
int shaderResId = fields[count].getInt(fields[count]);
byte[] shaderBytes = IOUtils.read(context.getResources().openRawResource(shaderResId));
String shaderCode = new String(shaderBytes);
Expand All @@ -44,7 +44,7 @@ public DrawerFactory(Context context) throws IllegalAccessException, IOException
public Object3D getDrawer(Object3DData obj, boolean usingTextures, boolean usingLights, boolean usingAnimation, boolean drawColors) {

// double check features
boolean isAnimated = usingAnimation && obj instanceof AnimatedModel && ((AnimatedModel) obj).getAnimation() != null;
boolean isAnimated = usingAnimation && obj instanceof AnimatedModel && (((AnimatedModel) obj).getAnimation() != null);
boolean isUsingLights = usingLights && (obj.getNormals() != null || obj.getVertexNormalsArrayBuffer() != null);
boolean isTextured = usingTextures && obj.getTextureData() != null && obj.getTextureCoordsArrayBuffer() != null;
boolean isColoured = drawColors && obj != null && obj.getVertexColorsArrayBuffer() != null;
Expand Down Expand Up @@ -73,11 +73,11 @@ public Object3D getDrawer(Object3DData obj, boolean usingTextures, boolean using
vertexShaderCode = vertexShaderCode.replace("void main(){", "void main(){\n\tgl_PointSize = 5.0;");

// create drawer
Log.i("Object3DImpl2", "\n---------- Vertex shader ----------\n");
Log.i("Object3DImpl2", vertexShaderCode);
Log.i("Object3DImpl2", "---------- Fragment shader ----------\n");
Log.i("Object3DImpl2", fragmentShaderCode);
Log.i("Object3DImpl2", "-------------------------------------\n");
Log.v("DrawerFactory", "\n---------- Vertex shader ----------\n");
Log.v("DrawerFactory", vertexShaderCode);
Log.v("DrawerFactory", "---------- Fragment shader ----------\n");
Log.v("DrawerFactory", fragmentShaderCode);
Log.v("DrawerFactory", "-------------------------------------\n");
drawer = DrawerImpl.getInstance(shaderId, vertexShaderCode, fragmentShaderCode);

// cache drawer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,21 +182,7 @@ public void draw(Object3DData obj, float[] pMatrix, float[] vMatrix, int drawMod
}

private float[] getMMatrix(Object3DData obj) {

// calculate object transformation
Matrix.setIdentityM(mMatrix, 0);
if (obj.getRotation() != null) {
Matrix.rotateM(mMatrix, 0, obj.getRotation()[0], 1f, 0f, 0f);
Matrix.rotateM(mMatrix, 0, obj.getRotation()[1], 0, 1f, 0f);
Matrix.rotateM(mMatrix, 0, obj.getRotationZ(), 0, 0, 1f);
}
if (obj.getScale() != null) {
Matrix.scaleM(mMatrix, 0, obj.getScaleX(), obj.getScaleY(), obj.getScaleZ());
}
if (obj.getPosition() != null) {
Matrix.translateM(mMatrix, 0, obj.getPositionX(), obj.getPositionY(), obj.getPositionZ());
}
return mMatrix;
return obj.getModelMatrix();
}

private float[] getMvMatrix(float[] mMatrix, float[] vMatrix) {
Expand Down
Loading