首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在安卓中使用Rajawali显示.obj不起作用

在安卓中使用Rajawali显示.obj不起作用
EN

Stack Overflow用户
提问于 2016-11-26 04:11:41
回答 1查看 1.1K关注 0票数 1

我想使用Rajawali框架在android应用程序中显示3d对象。我使用Autodesk 3DS MAX创建了一个三维对象。(我读过一些文章,建议你使用搅拌机。但我下载了一个我想使用的模型,它是一个.3ds文件)

我将.obj和.mtl放在raw文件夹中(按照mymodel_obj和mymodel_mtl中的建议对文件进行了重命名),然后我创建了一个渲染器类:

代码语言:javascript
复制
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) {}
}

我想以片段的形式显示模型。这是片段:

代码语言:javascript
复制
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);
}
}

当我启动我的应用程序时,我只得到一个黑色的背景,没有任何模型,并出现以下错误:

代码语言:javascript
复制
 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格式,然后将其导入blender,然后再次导出为.obj。但它也不起作用。我注意到了以下导出规则:https://github.com/Rajawali/Rajawali/wiki/Tutorial-17-Importing-.Obj-Files,但我在blender中找不到“包含法线”选项,所以我选择了“编写法线”。

EN

回答 1

Stack Overflow用户

发布于 2017-01-12 22:10:18

在您的代码中,我认为您需要在initScene()下添加灯光和摄像头

在Blender上,在导出之前,我建议确保底层纹理图像文件名为小型大写。导出时,请选择“条带路径”选项。

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/40811732

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档