model3d

command module
v0.4.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 1, 2024 License: BSD-2-Clause Imports: 10 Imported by: 0

README

model3d GoDoc Go

This is a collection of tools for programmatically creating, manipulating, and rendering 3D models.

The following image was created completely from models made with model3d, rendered with the render3d sub-package of model3d:

Showcase rendering

See the showcase example for details on how that image was created, and which models it uses (all of which are included in the examples directory).

Examples

If you are eager to get started, you may jump right into the examples directory. Most of these examples produce models which can be 3D printed, although a few are more focused on cool-looking renderings.

Here's a few examples you may want to check out first:

  • vase - a 3D-printable vase. This example gives a really simple picture of how to create a custom model3d.Solid implementation and turn it into a mesh.
  • heart_box - a 3D-printable heart-shaped box. This example incorporates a 2D image (a heart) into a 3D design using the model2d sub-package. It gives an overview of how to inset (i.e. shrink) shapes, and how to build 3D solids out of them.
  • table - a multi-part 3D printable bedside table. This example shows how to compose simple solids into more complex solids. It also shows how to use the toolbox3d sub-package to print parts with built-in screws and screw-holes.
  • cornell_box - a classic ray tracing demo. This example shows how to construct 3D scenes and objects and render them with the render3d sub-package.

Creating models as Solids

There are four ways to represent objects in model3d. These are Solid, Collider, Mesh, and SDF. The GoDoc has more information on these representations, so let's focus on the Solid.

A Solid represents an object as a boolean function, where the function returns true for points inside the object. In particular, a Solid is a simple interface:

type Solid interface {
	Min() Coord3D
	Max() Coord3D
	Contains(p Coord3D) bool
}

Due to their simple and flexible representation, Solids are easy to implement, compose, and derive from other shapes. The model3d package includes several APIs for composing solids, such as JoinedSolid and SubtractedSolid. It also includes several pre-built solids, such as Sphere, Cylinder, and Rect.

Once you have a Solid that you want to render or print, you can convert it into a triangle mesh using marching cubes. Here's an example of creating a sphere 3D model out of a Solid:

solid := &model3d.Sphere{Radius: 1.0}
mesh := model3d.MarchingCubesSearch(solid, 0.01, 8)
mesh.SaveGroupedSTL("output.stl")

The resulting .stl file output.stl can be loaded into external applications, sent to a 3D printer, etc.

Rendering models

The render3d sub-package provides a variety of ways to render a 3D model. For the easiest API, use render3d.SaveRandomGrid, which renders a model from a variety of random angles (but assuming the z-axis is the axis of gravity), and saves the renderings to a file. It can take *model3d.Mesh, model3d.Collider, and render3d.Object arguments, and automatically adds colors/textures if needed.

Here's an example when using this API to render a dog-bone-shaped box:

Rendering of a bone box

That rendering was created with this one line of code:

render3d.SaveRandomGrid("rendering_box.png", mesh, 3, 3, 300, nil)

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis
cli
inch_to_mm
Command inch_to_mm converts an STL file from using inches to using millimeters.
Command inch_to_mm converts an STL file from using inches to using millimeters.
off_to_stl
Command off_to_stl converts OFF files to STL files.
Command off_to_stl converts OFF files to STL files.
pan_pointcloud
Command pan_pointcloud inputs a colored point cloud from a PLY file, and render a pan around it.
Command pan_pointcloud inputs a colored point cloud from a PLY file, and render a pan around it.
ply_to_obj
Command ply_to_obj loads a colored mesh from a PLY file and exports it as a textured OBJ file.
Command ply_to_obj loads a colored mesh from a PLY file and exports it as a textured OBJ file.
render_stl
Command render_stl renders a 3D model in an STL file to a PNG file from several randomized angles.
Command render_stl renders a 3D model in an STL file to a PNG file from several randomized angles.
examples
experiments/convex_globe
This is an experiment to see if a convex polytope can somewhat model the shape of the earth.
This is an experiment to see if a convex polytope can somewhat model the shape of the earth.
experiments/fix_mask
Command fix_mask improves the WASP_MYFACE_MASK to be printed with many fewer support structures.
Command fix_mask improves the WASP_MYFACE_MASK to be printed with many fewer support structures.
Package model2d provides various tools for loading, manipulating, saving, and using 2D shapes.
Package model2d provides various tools for loading, manipulating, saving, and using 2D shapes.
Package model3d provides a set of APIs for creating, manipulating, and storing 3D models.
Package model3d provides a set of APIs for creating, manipulating, and storing 3D models.
Package render3d provides various APIs for creating and rendering visual scenes.
Package render3d provides various APIs for creating and rendering visual scenes.
Package toolbox3d provides a collection of parts for building practical 3D models for 3D prints.
Package toolbox3d provides a collection of parts for building practical 3D models for 3D prints.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL