ios 想在 iPhone 上显示 3D 模型:如何开始?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/413919/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 15:30:07  来源:igfitidea点击:

Want to display a 3D model on the iPhone: how to get started?

iphoneiosopengl-es

提问by JeremyReimer

I want to display and rotate a single 3D model, preferably textured, on the iPhone. Doesn't have to zoom in and out, or have a background, or anything.

我想在 iPhone 上显示和旋转单个 3D 模型,最好是带纹理的。不必放大和缩小,或有背景,或任何东西。

I have the following:

我有以下几点:

  • an iPhone
  • a MacBook
  • the iPhone SDK
  • Blender
  • 一部 iPhone
  • 一台 MacBook
  • iPhone SDK
  • 搅拌机

My knowledge base:

我的知识库:

  • I can make 3D models in various 3D programs (I'm most comfortable with 3D Studio Max, which I once took a course on, but I've used others)
  • General knowledge of procedural programming from years ago (QuickBasic - I'm old!)
  • Beginner's knowledge of object-oriented programming from going through simple Java and C# tutorials (Head Start C# book and my wife's intro to OOP course that used Java)
  • I have managed to display a 3D textured model and spin it using a tutorial in C# I got off the net (I didn't just copy and paste, I understand basically how it works) and the XNA game development library, using Visual Studio on Windows.
  • 我可以在各种 3D 程序中制作 3D 模型(我最熟悉 3D Studio Max,我曾经上过一门课程,但我也用过其他的)
  • 多年前程序化编程的一般知识(QuickBasic - 我老了!)
  • 通过简单的 Java 和 C# 教程(Head Start C# 书籍和我妻子使用 Java 的 OOP 课程介绍)了解面向对象编程的初学者知识
  • 我设法显示了一个 3D 纹理模型并使用 C# 中的教程旋转它我离开了网络(我不只是复制和粘贴,我基本上了解它是如何工作的)和 XNA 游戏开发库,使用 Visual Studio视窗。

What I do not know:

我不知道的是:

  • Much about Objective C
  • Anything about OpenGL or OpenGL ES, which the iPhone apparently uses
  • Anything about XCode
  • 关于目标 C
  • 任何有关 OpenGL 或 OpenGL ES 的信息,iPhone 显然使用了它们
  • 关于 XCode 的任何事情

My main problem is that I don't know where to start! All the iPhone books I found seem to be about creating GUI applications, not OpenGL apps. I found an OpenGL book but I don't know how much, if any, applies to iPhone development. And I find the Objective C syntax somewhat confusing, with the weird nested method naming, things like "id" that don't make sense, and the scary thought that I have to do manual memory management.

我的主要问题是我不知道从哪里开始!我找到的所有 iPhone 书籍似乎都是关于创建 GUI 应用程序,而不是 OpenGL 应用程序。我找到了一本 OpenGL 的书,但我不知道有多少适用于 iPhone 开发。而且我发现 Objective C 语法有些混乱,有奇怪的嵌套方法命名,像“id”这样没有意义的东西,以及我必须手动进行内存管理的可怕想法。

Where is the best place to start? I couldn't find any tutorials for this sort of thing, but maybe my Google-Fu is weak. Or maybe I should start with learning Objective C? I know of books like Aaron Hillgrass', but I've also read that they are outdated and much of the sample code doesn't work on the iPhone SDK, plus it seems geared towards the Model-View-Controller paradigm which doesn't seem that suited for 3D apps.

最好的起点是哪里?我找不到此类事情的任何教程,但也许我的 Google-Fu 很弱。或者我应该从学习 Objective C 开始?我知道像 Aaron Hillgrass 这样的书,但我也读过它们已经过时了,而且大部分示例代码在 iPhone SDK 上不起作用,而且它似乎面向模型-视图-控制器范式,它不适用似乎适合 3D 应用程序。

Basically I'm confused about what my first steps should be.

基本上我对我的第一步应该是什么感到困惑。

采纳答案by frankodwyer

You should probably start with some simpler iphone apps/tutorials, just to get your footing on obj-c and xcode etc.

您可能应该从一些更简单的 iphone 应用程序/教程开始,以便在 obj-c 和 xcode 等方面立足。

For that, I recommend the pragmatic programmer's iphone book, which has enough information to get started (I started with no knowledge of xcode, obj-c, iphone or mac and got to a working app fairly fast, using mainly this). However I should add that I come from a fairly good background in C/C++ and Java.

为此,我推荐实用程序员的 iphone 书,它有足够的入门信息(我开始时对 xcode、obj-c、iphone 或 mac 一无所知,并且很快就找到了一个可以运行的应用程序,主要使用这个)。但是我应该补充一点,我来自 C/C++ 和 Java 的相当好的背景。

For your particular project, perhaps take a look at thisanswer which refers to an open source 3D app that you can look at and get tips from.

对于您的特定项目,也许可以看看这个答案,它指的是一个开源 3D 应用程序,您可以查看并从中获取提示。

回答by Brad Larson

Once again, if I may plug my own work, I have written a postabout the things I've learned from developing an OpenGL ES application on the iPhone. That application, Molecules(referred to by frankodwyer), is open source and I have a writeupon some of the other tricky issues I ran into while developing it. The application generates 3-D models and lets you rotate and scale them with your fingers, which sounds close to your needs. You can download the code, compile it, and run it on your desktop in a matter of a few minutes. If you join the iPhone Developer Program, you can install it on your device.

再一次,如果我可以插入我自己的工作,我已经写了一篇关于我从在 iPhone 上开发 OpenGL ES 应用程序中学到的东西的文章。那个应用程序Molecules(由 frankodwyer 称为)是开源的,我有一篇关于我在开发它时遇到的其他一些棘手问题的文章。该应用程序生成 3-D 模型,让您可以用手指旋转和缩放它们,这听起来很接近您的需要。您可以在几分钟内下载代码、编译它并在桌面上运行它。如果您加入 iPhone 开发者计划,则可以在您的设备上安装它。

When it comes to object loading, Bill Dudneyis working on a Wavefront OBJ loader for the iPhonethat might be able to take in your Blender files, should they be exportable in that format. I haven't done much texture work on the iPhone yet, but it sounds like his example has that working now.

在对象加载方面,Bill Dudney正在开发适用于 iPhoneWavefront OBJ 加载器,如果它们可以以该格式导出,它可能能够接收您的 Blender 文件。我还没有在 iPhone 上做过很多纹理工作,但听起来他的例子现在已经可以工作了。

Overall, I find that learning by example and by jumping into development of some small, targeted applications (that you may never release) are what works for me. Try tweaking the examples listed above and see what happens. You should be able to read through the Objective-C code in those examples and start to get a feel for what they're doing.

总体而言,我发现通过示例学习和开发一些小的、有针对性的应用程序(你可能永远不会发布)对我有用。尝试调整上面列出的示例,看看会发生什么。您应该能够通读这些示例中的 Objective-C 代码并开始了解它们在做什么。

Even though Hillegass's book (the third edition just came out and is up-to-date) focuses on the Mac, the Cocoa fundamentals he teaches are still relevant for the iPhone. The MVC design pattern serves you just as well on the iPhone as the Mac. I actually deviated from that pattern in a few places within Molecules, and I regret that decision because those sections of the application became a mess. The book is an easy read and well worth your time.

尽管 Hillegass 的书(第三版刚刚出版并且是最新的)专注于 Mac,但他教授的 Cocoa 基础知识仍然适用于 iPhone。MVC 设计模式在 iPhone 和 Mac 上同样适用。实际上,我在 Molecules 中的一些地方偏离了这种模式,我对这个决定感到遗憾,因为应用程序的那些部分变得一团糟。这本书很容易阅读,值得您花时间阅读。

回答by Krishnabhadra

This is an ancient thread and I am terribly late. But still I am going to post my 2 pence here.

这是一个古老的线程,我迟到了。但我仍然要在这里张贴我的 2 便士。

A Sneak Preview

先睹为快

Before I get in to the beast, this is my setup.

在我进入野兽之前,这是我的设置。

I use

我用

  1. Blenderto create 3D models. (You can use Maya or 3D Max, I will tell you how to export the model for Blender, same works for 3D Max and Maya).
  2. Cocos3Dgame engine.
  3. PVRGeoPOD blender extensionfrom Imagination Technology to convert blender model to format that Cocos3D understand. You can see that the link downloads an installer file which in turns downloads the entire SDK. I can't see an easy way to download the blender extension alone.
  1. Blender创建 3D 模型。(您可以使用 Maya 或 3D Max,我会告诉您如何为 Blender 导出模型,3D Max 和 Maya 也是如此)。
  2. Cocos3D游戏引擎。
  3. 来自 Imagination Technology 的PVRGeoPOD 搅拌机扩展,将搅拌机模型转换为 Cocos3D 理解的格式。您可以看到该链接下载了一个安装程序文件,该文件依次下载了整个 SDK。我看不到单独下载搅拌机扩展的简单方法。

So if you are not intending to use Cocos3D, you can skip this answerand run for your money.

因此,如果您不打算使用 Cocos3D,您可以跳过这个答案并为您的钱而跑。

Initial Setup

最初设定

  1. Installblender.

    I am not going to embarrass you by going in to details.

  2. DownloadCocos3D..

    When I type this, the current version is 0.7.2.

  3. DownloadCocos2D.

    Cocos3D is written on top of popular Cocos2D, a popular 2D game framework. Important think to note here is that, Cocos2D 2.x version is already there and stable. But Cocos3D works with Cocos2d 1.x version only.

    When you unzip the source you downloaded you will find a README file inside and it specifically says,

    PLEASE NOTE THAT cocos3d 0.7.2 IS NOT COMPATIBLE WITH cocos2d 2.x. BE SURE TO DOWNLOAD cocos2d 1.x FOR USE WITH cocos3d.(emphasis mine)

    The README file clearly tells the installation procedure. After installation, you will get a nice Cocos3D project template in XCode.

  4. Add PVRGeoPOD extension to Blender.

    This requires some explanation. When you run the PVRGeoPOD installer, a screen shows what and what features need to be installed. I only selected

    • PVRGeoPOD- To convert my models in my .blend file to .POD format that Cocos3D understands

    • PVRShaman- you can view the model inside .POD using this tool.

    enter image description here

    You can install other tools in the list, but I only used these two.

    Now after the installation process (which may take some time), you need to add the PVRGeoPOD AddOn to blender. You can find the PVRGeoPOD.UserManual.PDFfile in the just installed folder, which also contains below information.

    • Find Blender Add-On folder, you can open blender python console and run command bpy.utils.script_paths("addons")to see the path to this folder.
    • Find the blender add-on files inside the PVRGeoPOD folder, in your installation path. When you see files like libPVRGeoPOD.dyliband PVRGeoPODScript.pyand 2 QTfiles, stop there as this is the location. Copy these 4 files and paste them in blender add on folder.
    • Now open blender, choose Preferences, find Add-Ontab, search and find PVRGeoPOD extension and enable it by clicking the checkbox on the right.
    • Now Quit and restart blender, if needed, and select file->export and see if there is an option called PVRGeoPOD(.pod/.h/.cpp), if yes,you are successful.

    Now you can create models in blender, and export these models as .POD files which Cocos3D understands.

    If you are using other 3D designing tools like Maya, 3D Max, this PVRGeoPOD extension can be added to them also. Just see the PDF I mentioned above.

  1. 安装搅拌机

    我不会因为详细说明而使您难堪。

  2. 下载Cocos3D。.

    当我输入这个时,当前版本是 0.7.2。

  3. 下载Cocos2D。

    Cocos3D 是在流行的 Cocos2D 之上编写的,这是一种流行的 2D 游戏框架。这里需要注意的重要一点是,Cocos2D 2.x 版本已经存在并且稳定。但是 Cocos3D 仅适用于 Cocos2d 1.x 版本。

    当你解压你下载的源代码时,你会在里面找到一个 README 文件,它特别说明,

    请注意cocos3d 0.7.2 与 cocos2d 2.x 不兼容。请务必下载 cocos2d 1.x 以与 cocos3d 一起使用。(重点是我的)

    README 文件清楚地说明了安装过程。安装后,您将在 XCode 中获得一个不错的 Cocos3D 项目模板。

  4. 将 PVRGeoPOD 扩展添加到 Blender。

    这需要一些解释。当您运行 PVRGeoPOD 安装程序时,屏幕会显示需要安装的内容和功能。我只选了

    • PVRGeoPOD- 将我的 .blend 文件中的模型转换为 Cocos3D 理解的 .POD 格式

    • PVRShaman- 您可以使用此工具查看 .POD 中的模型。

    在此处输入图片说明

    你可以安装列表中的其他工具,但我只使用了这两个。

    现在在安装过程之后(可能需要一些时间),您需要将 PVRGeoPOD AddOn 添加到搅拌机。您可以在刚刚安装的文件夹中找到 PVRGeoPOD.UserManual.PDF文件,其中还包含以下信息。

    • 找到 Blender Add-On 文件夹,您可以打开 Blender python 控制台并运行命令bpy.utils.script_paths("addons")来查看该文件夹的路径。
    • 在安装路径中的 PVRGeoPOD 文件夹中找到搅拌机附加文件。当您看到libPVRGeoPOD.dylibPVRGeoPODScript.py以及 2 个 QTfiles 之类的文件时,请 停在那里,因为这是位置。复制这 4 个文件并将它们粘贴到搅拌机添加文件夹中。
    • 现在打开搅拌机,选择Preferences,找到Add-On选项卡,搜索并找到 PVRGeoPOD 扩展并通过单击右侧的复选框启用它。
    • 如果需要,现在退出并重新启动搅拌机,然后选择 file->export 并查看是否有一个名为PVRGeoPOD(.pod/.h/.cpp)的选项,如果是,您就成功了。

    现在您可以在搅拌机中创建模型,并将这些模型导出为 Cocos3D 理解的 .POD 文件。

    如果您正在使用其他 3D 设计工具,如 Maya、3D Max,也可以将这个 PVRGeoPOD 扩展添加到它们中。看看我上面提到的PDF。

Using in project

项目中使用

  1. Step by step procedure is given below.

    Create your model in blender (.blend) and export it as .POD file. When you export I normally select following options

    • Primitive Type - Indexed Triangle List
    • Material tab - Check Export Material Option

    and rest I left it as default.

  2. Create a new project in XCode, choose Cocos3D template.
  3. Add the .POD files to your project. If yours a textured model, add that texture to your project also.
  4. The template project itself contains a HelloWorld.PODfile, you can replace that line with your .POD file so that your model will be visible.

    [self addContentFromPODFile: @"YourPODFileName.pod"];
    
  1. 下面给出了分步过程。

    在搅拌机 (.blend) 中创建模型并将其导出为 .POD 文件。导出时我通常选择以下选项

    • 原始类型 - 索引三角形列表
    • 材料选项卡 - 检查导出材料选项

    其余我将其保留为默认值。

  2. 在 XCode 中新建一个项目,选择 Cocos3D 模板。
  3. 将 .POD 文件添加到您的项目中。如果您是纹理模型,请将该纹理也添加到您的项目中。
  4. 模板项目本身包含一个HelloWorld.POD文件,您可以用您的 .POD 文件替换该行,以便您的模型可见。

    [self addContentFromPODFile: @"YourPODFileName.pod"];
    

Now you have your first 3D model visible in iOS device.

现在您在 iOS 设备中可以看到您的第一个 3D 模型。

回答by epatel

Shameless plug

无耻的插头

I have made a small AC3Drenderer for the iPhone. Link>>

我为 iPhone制作了一个小的AC3D渲染器。链接>>

Feel free to try it out, a demo lib for the iPhone simulator is available. Please note that the OpenGLES performance on the iPhone is not the same as in the Simulator.

随意尝试一下,可以使用 iPhone 模拟器的演示库。请注意,iPhone 上的 OpenGLES 性能与模拟器中的性能不同。

It uses a optimization stage and build tristrips and builds final vertexarrays to be able to run on the iPhone.

它使用优化阶段并构建 tristrips 并构建最终的 vertexarrays 以便能够在 iPhone 上运行。

Watch a quickstarthow to use it

观看如何使用它的快速入门

回答by Lesswire

This post is quite old and I think there exists now a better resource to do what you want. I am also quite a beginner, but after making some research I found this linke the most useful:

这篇文章已经很老了,我认为现在有更好的资源来做你想做的事。我也是一个初学者,但在进行了一些研究后,我发现这个链接最有用:

http://38leinad.wordpress.com/2011/10/19/practical-blender-with-glkit-part-1-introducing-glkit/

http://38leinad.wordpress.com/2011/10/19/practical-blender-with-glkit-part-1-introducing-glkit/

It explain glkit which should make easier to handle OpenGL and it also includes a nice tutorial how to interact with Blender.

它解释了 glkit 应该更容易处理 OpenGL,它还包括一个很好的教程如何与 Blender 交互。

回答by Airsource Ltd

For anything on iOS 8 or later, the answer is SceneKit. SceneKit will render Collada (DAE) files. Any decent modelling package (eg Cheetah, Blender) should export a DAE file - it's a documented portable format in XML (though xCode compiles them into binary format to save space).

对于 iOS 8 或更高版本上的任何内容,答案是 SceneKit。SceneKit 将渲染 Collada (DAE) 文件。任何体面的建模包(例如 Cheetah、Blender)都应该导出 DAE 文件 - 它是 XML 中记录的可移植格式(尽管 xCode 将它们编译为二进制格式以节省空间)。

回答by Simon Temlett

I'm having a play with iPhone development for a bit of fun and bought Beginning iPhone Development by Dave Mark and Jeff LaMarche (ISBN13: 978-1-4302-1626-1) and am enjoying working through the chapters. I have a Win32 Delphi background with a bit of .NET and so Objective C is very new to me.

我正在玩 iPhone 开发以获得一些乐趣,并购买了 Dave Mark 和 Jeff LaMarche 的《Beginning iPhone Development》(ISBN13:978-1-4302-1626-1),并且很喜欢阅读这些章节。我有一个 Win32 Delphi 背景和一些 .NET,所以 Objective C 对我来说很新。

One of the chapters is on OpenGL and Quartz which may be of interest to you. I've haven't got that far yet so I can't really comment on how useful it will be for yourself but the writing style is very accessible and it's paced well (for me anyway).

其中一章是关于 OpenGL 和 Quartz 的,您可能会感兴趣。我还没有那么远,所以我不能真正评论它对自己有多大用处,但写作风格非常容易理解,而且节奏很好(无论如何对我来说)。

The initial chapters explain exactly how to get up an running with a good introduction to Xcode and InterfaceBuilder.

最初的章节通过对 Xcode 和 InterfaceBuilder 的良好介绍,准确地解释了如何开始运行。

回答by Simon Temlett

2 good 3d sdks for iphone:

2 个不错的 iPhone 3d sdks:

sio2interactive and oolong.

sio2interactive 和乌龙茶。

The sio2interactive has great video and src tutorials on their site. It will help with blender and model export and render - gets you to right to game development. The src is all in c for sio2 and the code is commented very well. It is a great place to begin learning 3d and opengles. Blender to sio2 export is WYSIWYG.

sio2interactive 在他们的网站上有很棒的视频和 src 教程。它将有助于搅拌机和模型导出和渲染 - 让您有权进行游戏开发。sio2 的 src 全部在 c 中,代码注释得很好。这是开始学习 3d 和 opengles 的好地方。Blender 到 sio2 导出是所见即所得。

Doing all this from scratch and you will have to know how to export and import the models yourself. So both great libs for someone getting started.

从头开始做这一切,你将不得不知道如何自己导出和导入模型。因此,对于入门的人来说,这两个库都是很棒的。

回答by Jyswee

Use Emcore3D - (https://github.com/Things3D/Emcore3D)

使用 Emcore3D - ( https://github.com/Things3D/Emcore3D)

Simply define paths to the obj, mt and textures.

只需定义 obj、mt 和纹理的路径。

T3DModelPathInfo *newModelPath = [T3DModelPathInfo createModelPathInfoWithModelName:@"model.obj" material:@"model.mtl" path:@"/3DModels/"];

T3DModelPathInfo *newModelPath = [T3DModelPathInfo createModelPathInfoWithModelName:@"model.obj" material:@"model.mtl" path:@"/3DModels/"];

After that you create a T3DObject with the T3DModelPathInfo and add it to the T3DRenderController.

之后,您使用 T3DModelPathInfo 创建一个 T3DObject 并将其添加到 T3DRenderController。

T3DObject *newObject = [T3DObject initWithModelPathObject:newModelPath]; [renderVC addT3DObject:newObject];

T3DObject *newObject = [T3DObject initWithModelPathObject:newModelPath]; [renderVC addT3DObject:newObject];

ps: Disclosure that I am part of the Emcore3D team

ps:披露我是 Emcore3D 团队的一员