Kdtree-model-import

From Manta

NOTE: This part of the repository has been deprecated and the DynBVH has replaced the kd-tree as the primary acceleration structure.

See Triangle Scene Viewer for instructions to load .obj or .ply files.

The kd-tree code and Fox GUI, associated with the original 2006 work with SGI & Boeing has been moved to: https://code.sci.utah.edu/svn/people/abe/code/Manta-Fox/ See: Build instructions for Manta-Fox

Table of contents

Importing Models into Manta

This page describes how to convert a model into the .v3c1* format used for the Boeing 777 demo dataset.

This page does not describe how to import general models into other acceleration structures.

File Formats

.v3c1 is a collection of simple binary file formats used by Manta. The binary files are always assumed to be in little-endian byte order and are automatically converted by the loader to the native byte order.

Required files.
file.v3c1 Triangle file each triangle is 9 floats for vertices followed by a three float color. This may be generated manually or using bin/v3c1_tools.
file.v3c1.kd Direct binary serialization of kdtree using struct format in KDTree.h
file.v3c1.id Unsigned integer offsets used by kdtree.
Optional files.
file.v3c1.tex2 2D texture coordinates, 6 floats for each face.
file.v3c1.nor Per vertex normals, 9 floats for each face.
file.v3c1.grp Offsets into the name file for each face.
file.v3c1.nam Null terminated strings for each group name.

The repository contains a utility, bin/v3c1_tools, for creating and managing .v3c1 files.

v3c1_tools

The bin/v3c1_tools program started out as a simple program to convert the Double Eagle tanker dataset to the v3c1 binary triangle format in order to run a kdtree builder on the data. Since then it has balloned into doing much more.

Command line Options

As of r931 the options are:

bin/v3c1_tools 
Usage: v3c1_tools -vn3 -in <tanker paths...> -out <outfile.v3c1>
       v3c1_tools -obj -in <file1.obj ...>  [-out <outfile.v3c1>]
          Related options: (might not work with other conversions)
          -scale <x> <y> <z>  -- Scale the model before writting
          -normals            -- Output a vertex normal file.
          -flip               -- Use glm to reverse winding direction.
          -vertex_normals <d> -- Use glm to compute vertex normals using
                                 the specified angle threshold (in degrees)
          -texcoords          -- Output a vertex texture file.
          -loud               -- Print per group info.
       v3c1_tools -m   -in <file1.m ...>  -color <r> <g> <b> [-out <outfile.v3c1>]
          Hughes Hoppe .m file format conversion.

       v3c1_tools -info <infile.v3c1 ...>
          Computes bounds and number of triangles, colors.
       v3c1_tools -clip <px> <py> <pz> <nx> <ny> <nz>
          Apply a clipping plane to the input files given a point and normal.
       v3c1_tools -scale <x> <y> <z>
          Scale the input v3c1 file and write to the output file.

          Outfile optional uses group names otherwise.

These options can be divided into two categories, those for converting meshes to .v3c1 triangle soups and those for maniuplating .v3c1 files.

Nate Robin's GLM (heavily modified) is used to load .obj files.

Usual workflow

Most small models can be converted to .v3c1 from .obj using the utility and then kdtrees can be generated for them. Special scripts or small Performer programs were written for special cases like the Boeing 777 dataset.

Converting a .obj file

For this example I'll use a variation on my favorite model, my toy truck (http://www.sci.utah.edu/%7Eabe/cs6620-raytracing/project11/index.html).

This is an .obj file which I exported from Blender along with a .mtl file.

ls -l
total 16848
-rwxr-xr-x  1 abe sci     1456 2006-02-16 00:41 defender-final-truck.mtl
-rwxr-xr-x  1 abe sci 17228419 2006-02-16 00:41 defender-final-truck.obj

The simplest way to just get the data in a form that you can load it is to convert only the mesh itself:

v3c1_tools -obj -in defender-final-truck.obj -out defender-final-truck.v3c1
Bounds: -7.96389 -8.57825 0.0496373  4.5816 5.04275 10.3117

Building the kdtree

Unfortunately, the only kdtree building tool for manta isn't in the repository. It can be downloaded in binary form for ia64 and em64t.

There are both single processor and parallel build programs available.

kdbuild.seq defender-final-truck.v3c1 0.99
Reading in defender-final-truck.v3c1 (59792 triangles). . .0.01 secs
checking for NaNs...OK!
Building kdtree:
ChildParentCostRatio=0.99 MaxSizeToSlowSplit=59792 FracOfParentVolToSplit=0.10
BuildTree time  15.01 secs
NumNodes        1778116
MaxDepth        91
NumLeaves       474082
NumTrisInLeaves 1141200
MaxInLeaf       50
MinInLeaf       1
AvgInLeaf       2.4
Creating [defender-final-truck.v3c1.kd]
         [defender-final-truck.v3c1.idx]

It is possible to build a better kd tree for this model by manipulating the command line parameters.

Then run the model using:

 bin/dm_demo -np 4 -scene "lib/libscene_boeing777.so( -file defender-final-truck.v3c1 )" -camera auto
Using 4 workers plus one gui thread.
Cannot open file: defender-final-truck.v3c1.nor
Using per triangle normals
Cannot open file: defender-final-truck.v3c1.tex2
Not using texture coordinates.
Time to input triangles: 0.007125 seconds. 
Total file size:         2.73706 MB. 
IO Performance:          384.149 MB/second.
Please wait...
Time to read kdtree: 0.028485 seconds.
Model bounds: min: -7.9639 -8.57825 0.0496323  max: 4.58161 5.04276 10.3117 
Total time to read in indices: 0.006319
start loading grp defender-final-truck.v3c1.grp
WARNING: cannot open .grp file; picking disabled
Total load time: 0.00126427 minutes.

Auto camera: pinhole( -eye -1.69114 19.4037 5.18069  -lookat -1.69114 -1.76775 5.18069  -up 0 0 1  -fov 60 )
Building transparent tree.
model rendered in manta
model rendered in manta