我是java / android的新手,之前只是处理过。因此,所有这些包,源,库对我来说都是一个问题。 现在我想使用min3d库加载.obj文件。问题是,我想在commmander 3d tablet上显示.obj。因此,我从此SDK no need to log in下载了具有立体3D渲染器类的平板电脑的工作示例。在包中,在我的示例多维数据集生成的地方,我想改为加载.obj。但我得到一个活动错误。我不确定,如果找到.obj,但我认为应该,因为如果我只加载它并且不解析它,我不会收到错误。但是,如果我开始解析:“parser.parse();”一团糟就开始了。 .obj位于此文件夹中:SampleActivity> res>原始> camaro_obj。接下来的3行是我已经取消注释的解析,因为起初这应该有效。但我已经知道,appChild是不可用的。这将是下一个问题。下面是包的代码,控制台和logCat。非常感谢你!!!最好的马库斯!
/*
* Copyright (c) 2014. Sun Game Corp. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the License.
*/
package com.sungame.sdeck.sample.render;
import android.content.Context;
import android.opengl.Matrix;
import android.view.*;
import com.sungame.sdeck.sample.R;
import com.sungame.sdeck.sample.model.Scene;
import com.sungame.sdeck.sample.shader.ShaderProgram;
import com.sungame.sdeck.sample.shader.TextureProgram;
//import min3d.sampleProject1.IParser;
import org.sdeck.SDeConfig;
import org.sdeck.SDecKit;
import org.sdeck.renderer.AbstractRenderer;
import static android.opengl.GLES20.*;
import min3d.core.Object3dContainer;
import min3d.core.RendererActivity;
import min3d.parser.IParser;
import min3d.parser.Parser;
import min3d.vos.Light;
/**
* Render a stereo scene.
*/
public class StereoRenderer extends AbstractRenderer implements View.OnTouchListener {
private final Scene scene;
private ShaderProgram program;
private float mDepthZ = -10.0f;
private float mPrevX;
private float mPrevY;
protected final float[] mvpMatrix = newMatrix(); // "Model View Projection Matrix"
protected final float[] projMatrix = newMatrix(); // Projection matrix
protected final float[] viewMatrix = newMatrix(); // View matrix
private static final float EYE_Z = -1f;
private static final float NEAR_Z = 3.0f;
private static final float FAR_Z = 30.0f;
private static final float MAX_DEPTH_Z = -(NEAR_Z + 2.0f);
private static final float MIN_DEPTH_Z = -(FAR_Z - 7.0f);
private static final float SCREEN_PLANE_Z = 10.0f;
private static final float FOV = 45.0f;
private static final float IOD = 0.2f;
private Object3dContainer objModel;
public StereoRenderer (Context context, Scene scene) {
super( createKit(context) );
this.scene = scene;
IParser parser = Parser.createParser(Parser.Type.OBJ,context.getResources(), "com.sungame.sdeck.sample:raw/camaro_obj", true);
parser.parse();
//objModel = parser.getParsedObject();
//objModel.scale().x = objModel.scale().y = objModel.scale().z = .7f;
//scene.addChild(objModel);
}
private static SDecKit createKit (Context context) {
SDeConfig config = new SDeConfig.Builder( context.getApplicationContext() )
.setNearZ( NEAR_Z )
.setFarZ( FAR_Z )
.setScreenZ( SCREEN_PLANE_Z )
.setFOV( FOV )
.setIOD( IOD )
.create();
return new SDecKit( config );
}
@Override
protected float[] onSetupProjection () {
return projMatrix;
}
private void setupGL () {
glClearColor( 0, 0, 0, 0 );
glEnable( GL_TEXTURE_2D );
glEnable ( GL_CULL_FACE );
glEnable( GL_DEPTH_TEST );
glDisable( GL_DITHER );
}
@Override
protected void onSurfaceCreated () {
setupGL();
program = new TextureProgram( R.raw.texture_vertex, R.raw.texture_shader );
program.useProgram();
}
@Override
protected void onSurfaceChanged (int w, int h) {
scene.setup( w, h );
}
/**
* Draw the full scene.
*/
protected void onDrawFrame () {
// Draw background color
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
super.onDrawFrame(); // let super handler the rest.
scene.drawEnd();
}
@Override
protected void onDrawScene (float[] projMatrix) {
// Set the camera position (View matrix)
//setLookAtM( viewMatrix, 0, 0f, 0f, EYE_Z, 0f, 0f, 0f, 0f, 1f, 0f );
Matrix.setIdentityM( viewMatrix, 0 );
// Calculate the projection and view transformation
Matrix.multiplyMM( mvpMatrix, 0, projMatrix, 0, viewMatrix, 0 );
Matrix.translateM( mvpMatrix, 0, 0, 0, mDepthZ );
// Draw
scene.draw( mvpMatrix, program );
}
public void moveCam (float deltaX) {
deltaX /= (float)width;
deltaX *= 20.0f;
mDepthZ += deltaX;
if (mDepthZ >= MAX_DEPTH_Z)
mDepthZ = MAX_DEPTH_Z;
else if (mDepthZ <= MIN_DEPTH_Z)
mDepthZ = MIN_DEPTH_Z;
}
@Override
public boolean onTouch (View v, MotionEvent e) {
if (e.getActionMasked() == MotionEvent.ACTION_DOWN) {
mPrevX = e.getX();
mPrevY = e.getY();
}
if (e.getActionMasked() == MotionEvent.ACTION_MOVE) {
float deltaX = e.getX() - mPrevX;
float deltaY = e.getY() - mPrevY;
moveCam( deltaX );
scene.onTouch( deltaX, deltaY );
mPrevX = e.getX();
mPrevY = e.getY();
}
return true;
}
}
> Android Launch!
[2014-11-17 15:10:10 - SampleActivity] adb is running normally.
[2014-11-17 15:10:10 - SampleActivity] Performing com.sungame.sdeck.sample.SampleActivity activity launch
[2014-11-17 15:10:11 - SampleActivity] Application already deployed. No need to reinstall.
[2014-11-17 15:10:11 - SampleActivity] Starting activity com.sungame.sdeck.sample.SampleActivity on device 0146D5EF0801D014
[2014-11-17 15:10:11 - SampleActivity] ActivityManager: Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.sungame.sdeck.sample/.SampleActivity }
11-17 22:08:00.960: I/SDecKit(5151): S3D runtime environment available.
11-17 22:08:01.023: D/libEGL(5151): loaded /system/lib/egl/libGLES_android.so
11-17 22:08:01.031: D/libEGL(5151): loaded /vendor/lib/egl/libEGL_POWERVR_SGX544_112.so
11-17 22:08:01.039: D/libEGL(5151): loaded /vendor/lib/egl/libGLESv1_CM_POWERVR_SGX544_112.so
11-17 22:08:01.039: D/libEGL(5151): loaded /vendor/lib/egl/libGLESv2_POWERVR_SGX544_112.so
11-17 22:08:01.257: D/OpenGLRenderer(5151): Enabling debug mode 0
11-17 22:08:01.460: D/dalvikvm(5151): GC_FOR_ALLOC freed 142K, 3% free 9096K/9347K, paused 10ms
11-17 22:08:01.460: I/dalvikvm-heap(5151): Grow heap (frag case) to 9.954MB for 1048592-byte allocation
11-17 22:08:01.484: D/dalvikvm(5151): GC_CONCURRENT freed 1K, 4% free 10119K/10439K, paused 1ms+1ms
11-17 22:08:18.570: I/Process(5214): Sending signal. PID: 5214 SIG: 9
11-17 22:08:22.195: I/SDecKit(5253): S3D runtime environment available.
11-17 22:08:22.210: D/Min3D(5253): Start parsing object com.sungame.sdeck.sample:raw/camaro_obj
11-17 22:08:22.210: D/Min3D(5253): Start time 1416233302218
11-17 22:08:22.218: D/AndroidRuntime(5253): Shutting down VM
11-17 22:08:22.218: W/dalvikvm(5253): threadid=1: thread exiting with uncaught exception (group=0x40aa41f8)
11-17 22:08:22.218: E/AndroidRuntime(5253): FATAL EXCEPTION: main
11-17 22:08:22.218: E/AndroidRuntime(5253): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.sungame.sdeck.sample/com.sungame.sdeck.sample.SampleActivity}: java.lang.NullPointerException
11-17 22:08:22.218: E/AndroidRuntime(5253): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1956)
11-17 22:08:22.218: E/AndroidRuntime(5253): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
11-17 22:08:22.218: E/AndroidRuntime(5253): at android.app.ActivityThread.access$600(ActivityThread.java:123)
11-17 22:08:22.218: E/AndroidRuntime(5253): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
11-17 22:08:22.218: E/AndroidRuntime(5253): at android.os.Handler.dispatchMessage(Handler.java:99)
11-17 22:08:22.218: E/AndroidRuntime(5253): at android.os.Looper.loop(Looper.java:137)
11-17 22:08:22.218: E/AndroidRuntime(5253): at android.app.ActivityThread.main(ActivityThread.java:4424)
11-17 22:08:22.218: E/AndroidRuntime(5253): at java.lang.reflect.Method.invokeNative(Native Method)
11-17 22:08:22.218: E/AndroidRuntime(5253): at java.lang.reflect.Method.invoke(Method.java:511)
11-17 22:08:22.218: E/AndroidRuntime(5253): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
11-17 22:08:22.218: E/AndroidRuntime(5253): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
11-17 22:08:22.218: E/AndroidRuntime(5253): at dalvik.system.NativeStart.main(Native Method)
11-17 22:08:22.218: E/AndroidRuntime(5253): Caused by: java.lang.NullPointerException
11-17 22:08:22.218: E/AndroidRuntime(5253): at min3d.Utils.makeBitmapFromResourceId(Utils.java:26)
11-17 22:08:22.218: E/AndroidRuntime(5253): at min3d.Utils.makeBitmapFromResourceId(Utils.java:47)
11-17 22:08:22.218: E/AndroidRuntime(5253): at min3d.parser.ObjParser.readMaterialLib(ObjParser.java:213)
11-17 22:08:22.218: E/AndroidRuntime(5253): at min3d.parser.ObjParser.parse(ObjParser.java:107)
11-17 22:08:22.218: E/AndroidRuntime(5253): at com.sungame.sdeck.sample.render.StereoRenderer.<init>(StereoRenderer.java:72)
11-17 22:08:22.218: E/AndroidRuntime(5253): at com.sungame.sdeck.sample.SampleActivity.onCreate(SampleActivity.java:52)
11-17 22:08:22.218: E/AndroidRuntime(5253): at android.app.Activity.performCreate(Activity.java:4465)
11-17 22:08:22.218: E/AndroidRuntime(5253): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
11-17 22:08:22.218: E/AndroidRuntime(5253): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
11-17 22:08:22.218: E/AndroidRuntime(5253): ... 11 more
11-17 22:08:22.664: I/dalvikvm(5253): threadid=3: reacting to signal 3
11-17 22:08:22.671: I/dalvikvm(5253): Wrote stack traces to '/data/anr/traces.txt'
11-17 22:08:22.757: I/dalvikvm(5253): threadid=3: reacting to signal 3
11-17 22:08:22.757: I/dalvikvm(5253): Wrote stack traces to '/data/anr/traces.txt'