Java Examples for org.j3d.renderer.java3d.loaders.STLLoader
The following java examples will help you to understand the usage of org.j3d.renderer.java3d.loaders.STLLoader. These source code samples are taken from different open source projects.
Example 1
| Project: reprap-host-software-master File: STLObject.java View source code |
/**
* Actually load the stl file and set its attributes
* @param location
* @param att
* @return
*/
private BranchGroup loadSingleSTL(String location, Attributes att) {
BranchGroup result = null;
STLLoader loader = new STLLoader();
Scene scene;
try {
scene = loader.load(location);
if (scene != null) {
result = scene.getSceneGroup();
result.setCapability(Node.ALLOW_BOUNDS_READ);
result.setCapability(Group.ALLOW_CHILDREN_READ);
att.setPart(result);
result.setUserData(att);
stl.addChild(result);
// Recursively add its attribute
Hashtable namedObjects = scene.getNamedObjects();
java.util.Enumeration enumValues = namedObjects.elements();
if (enumValues != null) {
while (enumValues.hasMoreElements()) {
Shape3D value = (Shape3D) enumValues.nextElement();
bbox = (BoundingBox) value.getBounds();
value.setCapability(Shape3D.ALLOW_APPEARANCE_WRITE);
GeometryArray g = (GeometryArray) value.getGeometry();
g.setCapability(GeometryArray.ALLOW_COORDINATE_WRITE);
recursiveSetUserData(value, att);
}
}
}
} catch (Exception e) {
System.err.println("loadSingelSTL(): Exception loading STL file from: " + location);
e.printStackTrace();
}
return result;
}Example 2
| Project: host-master File: STLObject.java View source code |
/**
* Actually load the stl file and set its attributes. Offset decides where to put it relative to
* the origin. If lastPicked is null, the file is loaded as a new independent STLObject; if not
* it is added to lastPicked and subsequently is subjected to all the same transforms, so they retain
* their relative positions. This is how multi-material objects are loaded.
*
* @param location
* @param att
* @param offset
* @param lastPicked
* @return
*/
private Contents loadSingleSTL(String location, Attributes att, Vector3d offset, STLObject lastPicked) {
BranchGroup bgResult = null;
CSG3D csgResult = null;
STLLoader loader = new STLLoader();
//StlFile loader = new StlFile();
Scene scene;
double volume = 0;
try {
//location=location.substring(5);
//System.out.println(location);
scene = loader.load(location);
CSGReader csgr = new CSGReader(location);
if (csgr.csgAvailable())
csgResult = csgr.csg();
if (scene != null) {
bgResult = scene.getSceneGroup();
bgResult.setCapability(Node.ALLOW_BOUNDS_READ);
bgResult.setCapability(Group.ALLOW_CHILDREN_READ);
bgResult.setCapability(Shape3D.ALLOW_APPEARANCE_WRITE);
// Recursively add its attribute
Hashtable<?, ?> namedObjects = scene.getNamedObjects();
java.util.Enumeration<?> enumValues = namedObjects.elements();
if (enumValues != null) {
while (enumValues.hasMoreElements()) {
Object tt = enumValues.nextElement();
if (tt instanceof Shape3D) {
Shape3D value = (Shape3D) tt;
volume += s3dVolume(value);
bbox = (BoundingBox) value.getBounds();
value.setCapability(Shape3D.ALLOW_APPEARANCE_WRITE);
GeometryArray g = (GeometryArray) value.getGeometry();
g.setCapability(GeometryArray.ALLOW_COORDINATE_WRITE);
recursiveSetUserData(value, att);
}
}
}
att.setPart(bgResult);
bgResult.setUserData(att);
Offsets off;
if (lastPicked != null) {
// Add this object to lastPicked
csgResult = setOffset(bgResult, csgResult, lastPicked.rootOffset);
lastPicked.stl.addChild(bgResult);
lastPicked.setAppearance(lastPicked.getAppearance());
lastPicked.updateBox(bbox);
} else {
// New independent object.
stl.addChild(bgResult);
off = getOffsets(bgResult, offset);
rootOffset = off.centreToOrigin;
csgResult = setOffset(stl, csgResult, rootOffset);
Transform3D temp_t = new Transform3D();
temp_t.set(off.bottomLeftShift);
trans.setTransform(temp_t);
restoreAppearance();
}
}
} catch (Exception e) {
Debug.e("loadSingelSTL(): Exception loading STL file from: " + location);
e.printStackTrace();
}
return new Contents(location, bgResult, csgResult, att, volume);
}