User:LABoyd2/Import

import
Imports a file for use in the current OpenSCAD model. OpenSCAD currently supports import of DXF, OFF and STL (both ASCII and Binary) files.

NOTE: The file extension is used to determine which type.

OpenSCAD can export files as STL, OFF, AMF, DXF, SVG, CSG OR PNG(Image). These file types created by OpenSCAD, or others, can be imported as follows: STL, OFF and DXF are imported using import. CSG can be imported using include<> or loaded like an SCAD file PNG can be imported using surface There are open pull requests for SVG and AMF, which require a bit more work/testing. The file suffix is used to determine type.

Parameters


 * &lt;file&gt; : A string containing the path to the STL, OFF or DXF file.
 * &lt;convexity&gt; : An Integer. The convexity parameter specifies the maximum number of front sides (back sides) a ray intersecting the object might penetrate. This parameter is only needed for correctly displaying the object in OpenCSG preview mode and has no effect on the polyhedron rendering.

import("example012.stl", convexity=3); import("D:\\Documents and Settings\\User\\My Documents\\Gear.stl", convexity=3); (Windows users must "escape" the backslashes by writing them doubled.)

Convexity


This image shows a 2D shape with a convexity of 4, as the ray indicated in red crosses the 2D shape a maximum of 4 times. The convexity of a 3D shape would be determined in a similar way. Setting it to 10 should work fine for most cases.

import_dxf
DEPRECATED: Will be removed in future releases. Use import instead.

Read a DXF file and create a 2D shape.

linear_extrude(height = 5, center = true, convexity = 10) import_dxf(file = "example009.dxf", layer = "plate");

import_stl
DEPRECATED: Will be removed in future releases. Use import instead.

Imports an STL file for use in the current OpenSCAD model import_stl("example012.stl", convexity = 5);

Surface
Surface reads Heightmap information from text or image files. Surface can read PNG files.

Parameters


 * file : String. The path to the file containing the heightmap data.


 * center : Boolean. This determines the positioning of the generated object.  If true, object is centered in X- and Y-axis.  Otherwise, the object is placed in the positive quadrant.  Defaults to false.


 * invert : Boolean. Inverts how the color values of imported images are translated into height values. This has no effect when importing text data files. Defaults to false.


 * convexity : Integer. The convexity parameter specifies the maximum number of front sides (back sides) a ray intersecting the object might penetrate. This parameter is only needed for correctly displaying the object in OpenCSG preview mode and has no effect on the final rendering.

Text file format
The format for text based heightmaps is a matrix of numbers that represent the height for a specific point. Rows are mapped to the Y-axis, columns to the X axis. The numbers must be separated by spaces or tabs. Empty lines and lines starting with a # character are ignored.

Images
Currently only PNG images are supported. Alpha channel information of the image is ignored and the height for the pixel is determined by converting the color value to Grayscale using the linear luminance for the sRGB color space (Y = 0.2126R + 0.7152G + 0.0722B). The gray scale values are scaled to be in the range 0 to 100.

Examples
Example 1: //surface.scad surface(file = "surface.dat", center = true, convexity = 5); %translate([0,0,5])cube([10,10,10], center =true);

10 9 8 7 6 5 5 5 5 5 9 8 7 6 6 4 3 2 1 0  8 7 6 6 4 3 2 1 0 0 7 6 6 4 3 2 1 0 0 0 6 6 4 3 2 1 1 0 0 0 6 6 3 2 1 1 1 0 0 0 6 6 2 1 1 1 1 0 0 0 6 6 1 0 0 0 0 0 0 0 3 1 0 0 0 0 0 0 0 0 3 0 0 0 0 0 0 0 0 0
 * 1) surface.dat

Result:



Example 2

// example010.dat generated using octave: // d = (sin(1:0.2:10)' * cos(1:0.2:10)) * 10; // save("example010.dat", "d"); intersection { surface(file = "example010.dat", center = true, convexity = 5); rotate(45, [0, 0, 1]) surface(file = "example010.dat", center = true, convexity = 5); }



Example 3:

// Example 3a scale([1, 1, 0.1]) surface(file = "smiley.png", center = true);

// Example 3b scale([1, 1, 0.1]) surface(file = "smiley.png", center = true, invert = true);