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

发布于 2024-11-26 04:54:08 字数 1034 浏览 0 评论 0原文

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

我有以下设备:

  • iPhone
  • MacBook
  • iPhone SDK
  • Blender

我的知识库:

  • 我可以在各种 3D 程序中制作 3D 模型(我最喜欢使用 3D Studio Max,我曾经参加过该课程,但我用过其他)
  • 多年前的过程编程常识(QuickBasic - 我老了!)
  • 初学者通过简单的 Java 和 C# 教程获得的面向对象编程知识(Head Start C# 书和我妻子的介绍)使用 Java 的 OOP 课程)
  • 我已经成功地显示了 3D 纹理模型并使用我从网上下载的 C# 教程旋转它(我不只是复制和粘贴,我基本上了解它是如何工作的)和 XNA 游戏开发库,在 Windows 上使用 Visual Studio。

我不知道的内容:

  • 关于 Objective C 的很多
  • 内容 关于 iPhone 显然使用的 OpenGL 或 OpenGL ES 的任何内容
  • 关于 XCode 的任何内容

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

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

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

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.

I have the following:

  • an iPhone
  • a MacBook
  • the iPhone SDK
  • Blender

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.

What I do not know:

  • Much about Objective C
  • Anything about OpenGL or OpenGL ES, which the iPhone apparently uses
  • Anything about 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.

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.

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

尹雨沫 2024-12-03 04:54:08

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

在对象加载方面,Bill Dudney 正在研究 适用于 iPhone 的 Wavefront OBJ 加载器 可能能够在您的 Blender 中使用文件,是否可以以该格式导出。我还没有在 iPhone 上做太多纹理工作,但听起来他的例子现在已经可以工作了。

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

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

Once again, if I may plug my own work, I have written a post about 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 writeup on 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.

When it comes to object loading, Bill Dudney is working on a Wavefront OBJ loader for the iPhone that 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.

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.

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.

谷夏 2024-12-03 04:54:08

你可能应该从一些更简单的 iphone 应用程序/教程开始,只是为了让你在 obj-c 和 xcode 等方面站稳脚跟。

为此,我推荐实用程序员的 iphone 书,它有足够的信息来入门(我开始时对 obj-c 和 xcode 等一无所知) xcode、obj-c、iphone 或 mac,并且主要使用这个,相当快地获得了一个工作应用程序)。不过我应该补充一点,我有相当好的 C/C++ 和 Java 背景。

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

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

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.

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

莫相离 2024-12-03 04:54:08

这是一条古老的线索,而我却迟到了。但我还是要把我的 2 便士贴在这里。

先睹为快

在我深入了解这头野兽之前,这是我的设置。

我使用

  1. Blender 创建 3D 模型。 (你可以使用Maya或3D Max,我
    将告诉您如何导出 Blender 模型,同样适用于 3D
    麦克斯和玛雅)。
  2. Cocos3D 游戏引擎。
  3. PVRGeoPOD 搅拌机扩展,从 Imagination Technology 到
    将 Blender 模型转换为 Cocos3D 可以理解的格式。你可以看到
    该链接会下载一个安装程序文件,该文件又会下载
    整个SDK。我看不到下载搅拌机的简单方法
    单独扩展。

因此,如果您不打算使用Cocos3D,您可以跳过这个答案并开始赚钱。

初始设置

  1. 安装blender

    我不会详细介绍让您难堪。

  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 个 QT 文件,停在那里,因为这是位置。复制这4个文件并粘贴到
      搅拌机添加文件夹。
    • 现在打开搅拌机,选择首选项,找到附加组件选项卡,搜索并找到 PVRGeoPOD 扩展程序,然后单击启用它
      右侧的复选框。
    • 如果需要,现在退出并重新启动搅拌机,然后选择文件 -> 导出并查看是否有名为PVRGeoPOD(.pod/.h/.cpp)的选项
      如果是,那么你就成功了。

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

    如果您使用其他 3D 设计工具,例如 Maya、3D Max,则此
    PVRGeoPOD 扩展也可以添加到其中。只需查看 PDF 我
    上面提到过。

在项目中使用

  1. 下面给出了分步过程。

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

    • 基本类型 - 索引三角形列表
    • “材质”选项卡 - 检查“导出材质”选项

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

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

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

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

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

A Sneak Preview

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

I use

  1. Blender to 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. Cocos3D game engine.
  3. PVRGeoPOD blender extension from 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.

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

Initial Setup

  1. Install blender.

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

  2. Download Cocos3D..

    When I type this, the current version is 0.7.2.

  3. Download Cocos2D.

    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.PDF file 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.dylib and PVRGeoPODScript.py and 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-On tab, 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.

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.POD file, you
    can replace that line with your .POD file so that your model will be
    visible.

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

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

半城柳色半声笛 2024-12-03 04:54:08

我正在尝试 iPhone 开发,并购买了 Dave Mark 和 Jeff LaMarche 编写的《Beginning iPhone Development》(ISBN13:978-1-4302-1626-1),并且很享受阅读这些章节的过程。我有 Win32 Delphi 背景和一点 .NET,所以 Objective C 对我来说非常陌生。

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

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

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.

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).

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

懷念過去 2024-12-03 04:54:08

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

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).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文