455. Rindu yang Terbalas

Malam itu Abi datang ke kamar Al. Lelaki yang sudah hampir tiga hari enggan keluar dari kamar, masih belum bisa menerima kenyataan jika ia benar-benar ditinggalkan. Lampu kamar dibiarkan mati, Abi…

Smartphone

独家优惠奖金 100% 高达 1 BTC + 180 免费旋转




Wavefront OBJ Files

The Ray Tracer Challenge — by Jamis Buck (89 / 108)

👈 Triangles | TOC | Smooth Triangles 👉

The Wavefront OBJ file format is a common format for storing and sharing 3D graphics data. Like the PPM image format that you implemented way back in Chapter 2, Drawing on a Canvas, the OBJ format is plain text, which means you can view, edit, and even create these files in any text editor, though it’s much easier to model something in a 3D modeling tool and then export it to OBJ.

The OBJ format consists of statements, each of which occupies a single line. Each statement is prefaced with a command, followed by a space-delimited list of arguments. For example, the following OBJ file defines three vertices (v), and a triangle (f, for “face”) that references those vertices.

There are quite a few other statement types as well, but you only need to recognize a handful of them in your ray tracer. You’ll implement this parser in six steps:

Let me reiterate that you’ll be using Group instances to represent these groups of triangles. While this technique is straightforward to explain, it’s unfortunately not the most optimal way to represent this kind of data. If you’re interested in optimizing your ray tracer, you might investigate a structure called a triangle mesh, which can be stored and processed a bit more efficiently.

For now, though, groups of triangles will be fine. Let’s get started!

The parser should silently ignore any unrecognized statements.

Since your parser will only handle a subset of the OBJ format, you need to make sure it doesn’t choke when given a model that contains statements you haven’t implemented yet. The following test introduces a function…

Add a comment

Related posts:

Appendix 1 Using Cucumber with Other Platforms

Your customers want rock-solid, bug-free software that does exactly what they expect it to do. Yet they can't always articulate their ideas clearly enough for you to turn them into code. You need Cucumber: a testing, communication, and requirements tool-all rolled into one. All the code in this book is updated for Cucumber 2.4,