BlenderImport(3pm) | User Contributed Perl Documentation | BlenderImport(3pm) |
XRacer::BlenderImport - Import files exported by xracer-blenderexport.py
use XRacer::BlenderImport; $world = parse XRacer::BlenderImport [ $filename ]; $index = $world->add_vertex ($vertex); $verticesref = $world->get_vertices; %layerinfo = $world->get_layer_info; @objects = $world->get_meshes_in_layer ($layer);
The "XRacer::BlenderImport" module contains functions for importing special XRacer-specific Blender files into Perl scripts. These Blender files have been previously exported by the "xracer-blenderexport.py" Python script for Blender.
The "XRacer::BlenderImport" module parses the "blender.export" file, cleans it up (removing multiple vertices, for example) and presents an internal world representation. The world is divided into layers (corresponding to the layers in the original Blender image), and in each of these layers is a set of meshes.
Vertices are stored in a global list, so that common vertices are only stored once. A vertex structure looks like this:
$vertex = { coords => [ $x, $y, $z, 0 ], texcoords => [ $u, $v ], normal => [ $nx, $ny, $nz, 0 ], colour => [ $r, $g, $b, $a ] };
The fields are (in order): the coordinates of the vertex, the texture coordinates, the normal vector at this point and the colour of the vertex.
Faces are stored simply as a list of vertex indices (relative to the global list of vertices). A face looks like this:
$face = { vertices => [ $index0, $index1, $index2, ... ] }
Faces have at least three vertices, and maybe more.
A mesh is a list of faces and additional information, such as the name of the mesh (object). A mesh structure looks like this:
$mesh = { name => $name, layer => $layer, faces => \@faces, material => [ $red, $green, $blue ], has_colours => $has_colours, has_texcoords => $has_texcoords, has_material => $has_material };
The fields are: the name of the mesh (or object), the layer on which the object exists, the list of faces, the material and then three flags which are passed to us from Blender: did the user supply vertex colours? did the user supply texture coordinates? and did the user supply a material?
For example, if the world contained 3 objects on layer 1, 1 object on layer 2 and 4 objects on layer 5, then the hash returned would be equivalent to:
%layerinfo = ( 1 => 3, 2 => 1, 5 => 4 );
Richard W.M. Jones, <rich@annexia.org>
XRacer is copyright (C) 1999-2000 Richard W.M. Jones (rich@annexia.org) and other contributors listed in the AUTHORS file.
2020-12-29 | perl v5.32.0 |