2016-11-25 80 views
1

我想在使用Rajawali框架的android应用程序中显示3d对象。我使用Autodesk 3DS MAX创建了一个3D对象。 (我已经阅读过推荐使用搅拌器的文章,但是我下载了一个我想用的模型和它的.3ds文件)在Android中使用Rajawali不显示.obj

我把.obj和.mtl放在原始文件夹中(重命名文件如在mymodel_obj和mymodel_mtl推荐),然后我创建渲染器类:

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 但我找不到“搅拌器中的”包括法线“选项,所以我选择了”写入法线“。

回答

0

在你的代码,我想你需要添加灯和照相机下initScene()

在搅拌器,出口之前,我建议,以确保底层的纹理图像文件名是中小盘。 导出时,请选择“Strip Path”选项。

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

相关问题