xcode 在 iOS 中加载 3D 模型
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9697348/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Loading 3D model in iOS
提问by TurnsCoffeeIntoScripts
I'm creating a game application from scratch with xcode for iOS, and I've use the OpenGL Game projet template to create mine.
我正在使用适用于 iOS 的 xcode 从头开始创建游戏应用程序,并且我使用 OpenGL 游戏项目模板来创建我的。
I've searched a lot in the past few days, but I can't find any tutorials or example as to how I would load 3D model (via .obj files) in my application. I've found some documentation on loading them onto an app with a console script, but I need to do it programmatically.
在过去的几天里,我进行了大量搜索,但找不到关于如何在我的应用程序中加载 3D 模型(通过 .obj 文件)的任何教程或示例。我找到了一些关于使用控制台脚本将它们加载到应用程序的文档,但我需要以编程方式进行。
Any help would be very appreciated
任何帮助将不胜感激
Also, my 3D models are created using blender
此外,我的 3D 模型是使用搅拌机创建的
回答by Tommy
The future will be here momentarily — SceneKit, available in OS X since v10.8, will be in iOS 8. It can build and render a scene with COLLADA (.DAE) models directly. No need for third-party tools or code, nothing complicated to learn.
未来就在眼前——从v10.8开始在 OS X 中可用的 SceneKit 将在 iOS 8 中可用。它可以直接使用 COLLADA (.DAE) 模型构建和渲染场景。无需第三方工具或代码,学习起来并不复杂。
Apple's documentation is pretty good but if you prefer then other tutorials are available.
Apple 的文档非常好,但如果您愿意,可以使用其他教程。
回答by whatnick
OpensceneGraphhas support for iOS and a lot of prebuilt code which can help you develop the game. It supports loading OBJ models.
OpensceneGraph支持 iOS 和许多可以帮助您开发游戏的预构建代码。它支持加载 OBJ 模型。
回答by PKN
You can download the zip file from hereand then run ./obj2opengl.pl 3DModel.obj in terminal .It will give you 3DModel.h file as output.
您可以从此处下载 zip 文件,然后在终端中运行 ./obj2opengl.pl 3DModel.obj 。它将为您提供 3DModel.h 文件作为输出。
You need to use glDrawArrays instead of glDrawElements as the .h file contains array.
您需要使用 glDrawArrays 而不是 glDrawElements,因为 .h 文件包含数组。
回答by Felix K.
Obj files are simple to parse and are well described on wikipedia. You should be able to load them in one or 2 hours. But if you want to load the materials you need to invest some more time in your engine and into loading the obj file.
Obj 文件很容易解析并且在wikipedia上有很好的描述。您应该能够在一两个小时内加载它们。但是,如果您想加载材料,则需要在引擎上投入更多时间并加载 obj 文件。
回答by Scar
I recommend to use an Engine (like isgl3d, nineveh, Cocos3D, ...) for creating a 3D game, it will be hard if you use Opengl for a start.
我建议使用引擎(如isgl3d、Nineveh、Cocos3D等)来创建 3D 游戏,如果您开始使用 Opengl 会很困难。
Note: you can search for a list of game engine to choose the suitable one for you game, cause there is a lot of game engine, open-source or paid engine.
注意:您可以搜索游戏引擎列表来选择适合您的游戏,因为有很多游戏引擎,开源或付费引擎。