24/7 Customer Service (800) 927-7671

Learn ShapeJS: Light Switch Cover

by • April 3, 2016 • No Comments

This post you can learn of how to load triangle meshes into ShapeJS and a method to preserve
functional areas in your turn it into. Our goal this week is to turn it into a lightswich cover which
is customized with a user image. I begin
ed this system
by finding common measurements of light switches and considering
of how to 3D version it. I rapidly
got into wanting a script which
may handle n toggles, various hole types, phone and audio connectors, it got complex swift! So I discovered a few may already
3D versioned versions in various version repositories and became lazy. The final form of this script takes a 3D triangle version as its base object and and so overlays the user image. Let’s begin
with a photo of the final object to get us inspired:

To know how we load 3D versions into ShapeJS it helps to know the internal representation we use. All datasources in ShapeJS calculate a signed distance function. This is zero on the surface of the object, negative within and positive outside. The function for loading a 3D version of your code is called loadModelDistance. It takes the file name, a voxelSize and the maximum distance to calculate. The voxel dimensions controls the resolution we load the version and how swift it loads. For tiny versions I use 0.1mm, but for a fewthing larger like this version I use 0.2mm. For the distance, you want to use a distance out to the maximum place your edit the version. For our light switch cover we can be embossing our image up of 1mm so I calculate the distance function to 1.2mm. Think of a cloud surrounding your version, you require
this cloud to intersect anything you can doing to the version such as adding or subtracting material. You don’t require
to be super accurate of this, but the farther out you calculate it, the longer the calculation takes.

Let’s begin
by only loading the version itself.>



var params = [

{

name: "version",

label: "Model",

desc: "3D Model of light switch",

type: "uri",

defaultVal:"http://www.shapeways.com/rrstatic/javascript/shapejs/examples/versions/Light_Switch_Plate1.stl"

}

];

function main(args) {

var base = loadModelDistance(args.version, 0.1 * MM, 1.2 * MM);

var bounds = base.getBounds();

return new Scene(base, bounds);

}

For the basic light switch cover it looks like this:

Today we assist loading STL and X3D files. The X3D files already ignore the color information and only load the geometry. When you load the version it can return an object with a bounds property. You can use which
bounds property to set your scene bounds.

From there we can begin
adding in the user images. The way I thought of this was to reuse the Image3D datasource. This loads an image and makes 3D geometry out of it. In this case we are going to extrude it up by 1mm. One problem with this concept is it can block the functional areas of our version. In this case we require
to preserve
the two screw holes and the square light switch rocker area. To do this we are going to version the preserve
ed areas and and so subtract those of the pattern. The makeImage method takes our user image and the makePattern method subtracts out a box and two holes to preserve
the turn it into.



function makeImage(path, w, h, d) {

var img = new Image3D(path, w, h, d);

img.setBlurWidth(0.2 * MM);

img.setImagePlace(Image3D.IMAGE_PLACE_TOP);

img.setCenter(0, 0, 3.5 * MM);

img.setUseGrayscale(false);

return img;

}

function makePattern(path) {

var box = new Box(12.5 * MM, 25.5 * MM, 15 * MM);

var hole1 = new Cylinder(new Vector3d(0, -30.674 * MM, 0), new Vector3d(0, -30.674 * MM, 25 * MM), 5.5 * MM);

var hole2 = new Cylinder(new Vector3d(0, 29.805 * MM, 0), new Vector3d(0, 29.805 * MM, 25 * MM), 5.5 * MM);

var img = makeImage(path, 64.16 * MM, 106.185 * MM, 1 * MM);

var holes = new Union();

holes.add(box);

holes.add(hole1);

holes.add(hole2);

return new Subtraction(img, holes);

}

You can run the full example here: Light Switch Cover Example

I ponder
this turn it into came quite
great. I in addition
tried it in our Blue material:

One variant I tried was to cut the pattern completely through the original version instead of embossing it. Looking at the 3D version itself I quite
like this advantageous, plus is was much cheaper. That said I discovered out rapidly
which
looking within an electrical box is not the prettiest of things. Seems the original turn it intoers had the right thought of covering which
stuff up!

Couple of notes of this project. This current script embossed 1mm of material on top of an existing version. The version itself is somewhat darn sturdy
printed in plastic, so I feel like adding additional material is not necessary. Perhaps engraving the turn it into may work well and cost less. The 2nd note is of costs. I looked around on Etsy and Amazon to get an thought of whether this concept may work. Typically 3D printed items are additional expensive and so their weight generated cousins. On Amazon I discovered single light switch covers ranging of 0.25 for a quite basic version to $20 for a fancy version. On Etsy they range of $5 to $32. This turn it into costs around $18 already. I’d say which
puts this in the ball park of a great concept which
may compete on price and allow the user to turn it into whatever turn it into they want. This method is in addition
applicable to other objects you’d like to put turn it intos on such as a phone case. Take a base 3D version of the case, version the functional areas in the case you want to preserve
such as the camera and controls and there you go. Instant phone case creator!

shapeJS

Latest posts
test

by admin • March 5, 2017