Skip to content

Latest commit

 

History

History
60 lines (37 loc) · 2.08 KB

README.md

File metadata and controls

60 lines (37 loc) · 2.08 KB

wf2fmem

Wavefront .obj (3D model) to FPGA memory init file converter for use with Verilog $readmemh(). Written in Python 3.

Turns triangular and quad faces into 8-bit line coordinates suitable for simple 3D drawing with an FPGA.

Example projects using this tool:

  • Simple 3D - coming soon to Project F blog.

Licensed under the MIT License. See the LICENSE file for details.

Usage

wf2fmem.py model_file size offset
  • model_file - source model file name
  • size - maximum size in pixels for output (16-255)
  • offset - offset from screen edge in pixels for output. size+offset must be 255 or less.

Example:

wf2fmem.py test/icosphere.obj 220 8

Converts the icosphere model file with a maximum pixel dimensions of 220 and an offset of 8 pixels from the edge of the screen.

For advice on working with Verilog .mem files, see Initialize Memory in Verilog.

Output Format

The output consist of a 48-bit hex string per model line, for example 41D39782D3AC.

You can turn this into 8-bit coordinates like this:

{x0,y0,z0,x1,y1,z1} <= data;

The output will contain duplicates, as most lines are part of more than one face.

You can fix this with the UN*X sort and uniq commands. For example:

wf2fmem.py test/icosphere.obj 220 8 | sort | uniq > test/icosphere.mem

Test Models

  • cube - a hand-crafted cube created by the author (8 vertices and 6 faces)
  • icosphere - icosphere exported from Blender (42 vertices and 80 faces)
  • monkey - Monkey exported from Blender (507 vertices and 500 faces)
  • teapot - Utah Teapot from University of Utah (3241 vertices and 3464 faces)

References