This repository contains the specification for the V3D file format, a compact 3D graphics file format for Bezier curves, Bezier patches, Bezier triangles, and triangle groups, all with optional vertex-dependent colors.
A reference Python module pyv3d
for reading in V3D is included in the module
directory, along with an example of its usage in the example
directory.
To build and install pyv3d
:
pip3 install build
cd module
python3 -m build
pip3 install --user dist/pyv3d-1.0-py3-none-any.whl
The authors of the V3D file format are John C. Bowman [email protected] and Supakorn "Jamie" Rassameemasmuang [email protected]
TYPExN
means an object of type TYPE
repeated N
times, where TYPE
can be:
UINT
: Unsigned 32-bit integer;BOOL
: Unsigned 32-bit integer, denoting False if the value is0
and True otherwise;REAL
: A double or single floating point value, depending on the double precision flag, as described in the next section;FLOAT
: A single precision 32-bit IEEE 754 Floating point value;PAIR
: An alias forREALx2
;TRIPLE
: An alias forREALx3
;RGB
:An alias for FLOATx3
, where the elements respectively correspond to red, green, and blue channels between0.0
to1.0
;RGBA
:An alias for FLOATx4
, where the elements respectively correspond to red, green, blue, and alpha channels between0.0
to1.0
;WORD
: A 4-byte word.
V3D files are gzipped XDR files. The uncompressed data stream of a V3D file must begin with the following entries, in order:
UINT
: V3D version number;BOOL
: Double precision flag. If this flag is set to True (False), allTRIPLE
andREAL
values are treated as double (single) precision IEEE 754 floating point values.
After that, a V3D File contains an arbitrary sequence of objects in the format:
UINT
: Type number of the object;- Content of the object, depending on the type.
See V3D types for the list of V3D objects and their corresponding type numbers.
The center index
is used for implementing billboard labels that always face the viewer. If the index is positive, it points into an array of center positions; if it is zero, there is no associated center position and the labels are embedded into the 3D scene.
The material index
points into an array Material
of materials.
A V3D Header is a special type of object that starts with a UINT
number indicating the number of header entries, followed by a sequence of header entries.
Each header entry consists of
UINT
: Header key;UINT
: Lengthn
of the content measured in units of 4-byte words. For example,n=2
for a header containing one double-precision number;WORDxn
: The header content of lengthn
words of types that depend on the header key.
See V3D header types for the list of V3D headers and their corresponding keys.
The content following the type number is described for each of the following types.
Each center position is a point in 3D space about which a billboard surface should rotate so as to always face the camera.
UINT
: Numbern
of center positions;TRIPLExn
: Center positions.
V3D materials are specified by their metallic-roughness physical-based rendering properties, where shininess=1-roughness
:
RGBA
: Diffuse (base) color of the material;RGBA
: Emissive color of the material;RGBA
: Specular color (used to weight the reflectance of nonmetals);FLOATx3
: Parametersshininess, metallic, fresnel0
. Here,fresnel0
measures how much a dielectric surface reflects incoming light when viewed perpendicular to the surface.
Each Bezier patch contains a set of 16 control points
where
-
TRIPLEx16
: Control points$p_{i,j}$ stored in entry$4i+j$ ; -
UINT
: Center index; -
UINT
: Material index.
Each Bezier triangle contains
-
TRIPLEx10
: Control points$p_{i,j,3-i-j}$ stored in entry$(i+j)(i+j+1)/2+j$ ; -
UINT
: Center index; -
UINT
: Material index.
Each Bezier patch with per-vertex color contains
TRIPLEx16
: Control points;UINT
: Center index;UINT
: Material index;RGBAx4
: The colors assigned to the four vertices, bilinearly interpolated over the surface.
Each Bezier triangle with per-vertex color contains
TRIPLEx10
: Control points;UINT
: Center index;UINT
: Material index;RGBAx3
: The colors assigned to the three vertices, bilinearly interpolated over the surface.
Each rectangle contains
TRIPLEx4
: Vertices;UINT
: Center index;UINT
: Material index.
Each triangle contains
TRIPLEx3
: Vertices;UINT
: Center index;UINT
: Material index.
Each rectangle with per-vertex color contains
TRIPLEx4
: Vertices;UINT
: Center index;UINT
: Material index;RGBAx4
: The colors assigned to the four vertices, bilinearly interpolated over the surface.
Each triangle with per-vertex color contains
TRIPLEx3
: Vertices of the specified triangle;UINT
: Center index;UINT
: Material index;RGBAx3
: The colors assigned to the three vertices, bilinearly interpolated over the surface.
A triangle group is a collection of triangles specified by arrays of positions, normals, optional colors, and index triplets identifying the entries in the position, normal, and optional color arrays assigned to the three vertices of each triangle in the group. If more than one normal or color is specified for a vertex, the last one is used.
The indices of every triangle group begins with 0
, which means programs that read in V3D Files need to take note of the offset (number of position/normal entries) for formats that does not support segmentation of vertex entries, such as Wavefront *.obj
file. Moreover, in certain formats like *.obj
where indices start with 1
, programs converting V3D to those formats need to add 1
to the output indices.
Each triangle group contains:
UINT
: Number of indices. Denote this asnI
;UINT
: Number of vertex position array entries. Denote this asnP
;TRIPLExnP
: Vertex position array;UINT
: Number of vertex normal array entries. Denote this asnN
;TRIPLExnN
: Vertex normal array;BOOL
Whether or not explicit normal indices are present. Call thisexplicitNI
;UINT
: Number of vertex color array entries. Denote this asnC
.
RGBAxnC
: Vertex color array;BOOL
Whether or not explicit color indices are present. Call thisexplicitCI
.
Then, the triangle group contains nI
entries of the form:
UINTx3
: Vertex position array indices specifying the position of each of the three vertices.The next entry only appears if
explicitNI=true
(ifexplicitNI=false
, the normal indices are assumed to be identical to the position indices):
UINTx3
: Vertex normal array index triplets specifying the normal of each of the three vertices.The next entry only appears if
nC > 0
andexplicitCI=true
(ifexplicitCI=false
, the color indices are assumed to be identical to the position indices):
UINTx3
: Vertex color array index triplets specifying the color of each of the three vertices.
Like the previous objects, a triangle group ends with
UINT
: Center index;UINT
: Material index.
A sphere is specified by:
TRIPLE
: Center of the sphere;REAL
: Radius of the sphere;UINT
: Center index;UINT
: Material index.
A hemisphere is the half sphere specified by a base sphere and (polar, azimuthal) direction in radians specifying the normal vector of the plane that partitions the sphere, with the hemisphere chosen on the same side as the normal vector:
TRIPLE
: Center of the sphere;REAL
: Radius of the sphere;UINT
: Center index;UINT
: Material index;REAL
: Polar angle;REAL
: Azimuthal angle.
A disk is a planar filled circle specified by the center point, radius, and (polar, azimuthal) direction in radians of the surface normal:
TRIPLE
: Center of the disk;REAL
: Radius of the disk;UINT
: Center index;UINT
: Material index;REAL
: Polar angle;REAL
: Azimuthal angle.
A cylinder is specified by the center and radius of a bottom disk, with normal vector aligned in the (polar, azimuthal) direction in radians, and the extrusion height of the cylinder along the normal vector to the disk:
TRIPLE
: Center of the disk;REAL
: Radius of the disk;REAL
: Height of the cylinder;UINT
: Center index;UINT
: Material index;REAL
Polar angle;REAL
Azimuthal angle.
A tube is a deformed cylinder, without end faces, whose center line follows a Bezier curve:
TRIPLEx4
: Four control points specifying the Bezier curve that forms the central "core" of the tube;REAL
: Width of the tube;UINT
: Center index;UINT
: Material index;BOOL
: Whether or not the center curve should be drawn. This is called the "core" flag in Asymptote.
A Bezier curve is specified by four control points
A Bezier curve is specified by:
-
TRIPLEx4
The control points$z_0, c_0, c_1, z_1$ ; -
UINT
: Center index; -
UINT
: Material index.
A line segment is specified by:
-
TRIPLEx2
The endpoints$z_0, z_1$ ; -
UINT
: Center index; -
UINT
: Material index.
A pixel
is a single point in 3D space drawn with a specified width measured in screen pixels:
TRIPLE
: The position of the pixel;REAL
: The width of the pixel;UINT
: Material index.
This specification is released under Version 2.0 of the Apache License, see the LICENSE file for details.