使用Rajawali无法正常显示Android中的.obj

时间:2016-11-25 20:11:41

标签: android opengl-es 3d 3dsmax rajawali

我想使用Rajawali框架在Android应用程序中显示一个3d对象。我用Autodesk 3DS MAX创建了一个3d对象。 (我读过有关建议使用搅拌机的文章。但我下载了一个我想使用的模型及其.3ds文件)

我将.obj和.mtl放在原始文件夹中(根据mymodel_obj和mymodel_mtl中的建议重命名文件),然后我创建了一个Renderer类:

public class Renderer extends RajawaliRenderer {

private Context context;
private Object3D mObject;


//constructor
public Renderer(Context context) {
    super(context);
    this.context = context;
    setFrameRate(60);
}

@Override
protected void initScene() {
    try {
        LoaderOBJ objParser = new LoaderOBJ(context.getResources(),mTextureManager, R.raw.denture_obj);
        objParser.parse();
        mObject = objParser.getParsedObject();       
        getCurrentScene().addChild(mObject);  
    }catch (ParsingException e){
        e.printStackTrace();
    }
}

@Override
public void onOffsetsChanged(float xOffset, float yOffset, float xOffsetStep, float yOffsetStep, int xPixelOffset, int yPixelOffset) {}

@Override
public void onTouchEvent(MotionEvent event) {}
}

我想在片段中显示模型。这是碎片:

public class VisualizationFragment extends Fragment {

private IRajawaliSurface surface;
private Renderer mRenderer;
private final static String TAG = "VFRAG";

@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    super.onCreateView(inflater, container, savedInstanceState);
    View v = inflater.inflate(R.layout.visualization_frag, container, false);
    mRenderer = new Renderer(getActivity());
    applyRenderer(v);
    return v;
}

protected void applyRenderer(View v) {
    surface = (IRajawaliSurface) v.findViewById(R.id.brush_surface);
    surface.setSurfaceRenderer(mRenderer);
}
}

当我启动我的应用程序时,我只是在没有任何模型的情况下获得黑色背景并且出现以下错误:

 11-25 20:33:19.677 3187-3201/com.example.marti.ibrush E/Rajawali: Getting location of uniform: uModelMatrix returned -1!
 11-25 20:33:19.678 3187-3201/com.example.marti.ibrush E/Rajawali: Getting location of uniform: uTime returned -1!
 11-25 20:33:19.683 3187-3201/com.example.marti.ibrush E/Rajawali: Getting location of uniform: uModelMatrix returned -1!
 11-25 20:33:19.683 3187-3201/com.example.marti.ibrush E/Rajawali: Getting location of uniform: uTime returned -1!
 11-25 20:33:19.686 3187-3201/com.example.marti.ibrush E/Rajawali: Getting location of uniform: uModelMatrix returned -1!
 11-25 20:33:19.686 3187-3201/com.example.marti.ibrush E/Rajawali: Getting location of uniform: uTime returned -1!
 11-25 20:33:19.689 3187-3201/com.example.marti.ibrush E/Rajawali: Getting location of uniform: uModelMatrix returned -1!
 11-25 20:33:19.689 3187-3201/com.example.marti.ibrush E/Rajawali: Getting location of uniform: uTime returned -1!

我还试图以3ds格式导出​​我的模型,然后将其导入混合器并再次导出到.obj中。但它也不起作用。 我注意到以下出口法规: https://github.com/Rajawali/Rajawali/wiki/Tutorial-17-Importing-.Obj-Files 但我在搅拌机中找不到“Include Normals”选项,所以我选择了“Write Normals”。

1 个答案:

答案 0 :(得分:0)

在您的代码中,我认为您需要在initScene()

下添加Light和Camera

在Blender上,在导出之前,我建议确保底层纹理图像文件名是小上限。 在导出时,请选择“剥离路径”'选项。

请记住将纹理图像文件复制到应用项目下的res \ drawable文件夹中。