How to use the STLLoader function from three

Find comprehensive JavaScript three.STLLoader code examples handpicked from public code repositorys.

23
24
25
26
27
28
29
30
31
constructor() {
  this.gltfLoader = new THREE.GLTFLoader()
  this.gltfLoader.setDRACOLoader(new THREE.DRACOLoader())
  this.objLoader = new THREE.OBJLoader()
  this.fbxLoader = new THREE.FBXLoader()
  this.stlLoader = new THREE.STLLoader()
  this.gltfExporter = new THREE.GLTFExporter()
  this.usdzExporter = new USDZExporter()
}
fork icon3
star icon4
watch icon2

15
16
17
18
19
20
21
22
23
24
config.visible = typeof (config.visible) !== 'undefined' ? config.visible : true;
config.color = typeof (config.color) !== 'undefined' ? config.color : 255;
config.wireframe = typeof (config.wireframe) !== 'undefined' ? config.wireframe : false;
config.flat_shading = typeof (config.flat_shading) !== 'undefined' ? config.flat_shading : true;

var loader = new THREE.STLLoader(),
    modelMatrix = new THREE.Matrix4(),
    MaterialConstructor = config.wireframe ? THREE.MeshBasicMaterial : THREE.MeshPhongMaterial,
    material = new MaterialConstructor({
        color: config.color,
fork icon117
star icon0
watch icon1

10
11
12
13
14
15
16
17
18
19
*  Binary decoding supports "Magics" color format (http://en.wikipedia.org/wiki/STL_(file_format)#Color_in_binary_STL).
*  There is perhaps some question as to how valid it is to always assume little-endian-ness.
*  ASCII decoding assumes file is UTF-8. Seems to work for the examples...
*
* Usage:
*  var loader = new THREE.STLLoader();
*  loader.load( './models/stl/slotted_disk.stl', function ( geometry ) {
*    scene.add( new THREE.Mesh( geometry ) );
*  });
*
fork icon2
star icon13
watch icon1

43
44
45
46
47
48
49
50
51
52
},

stl: async function(file,objectColor){

    let promise = new Promise(function(resolve, reject) {
        let loaderSTL = new THREE.STLLoader();
        loaderSTL.load( file, function ( geometry ) {
            let clr = (objectColor == undefined) ? 0x1258c9 : objectColor;
            let material = new THREE.MeshPhongMaterial( { color: clr } );
            let mesh = new THREE.Mesh( geometry, material );
fork icon2
star icon4
watch icon1

12
13
14
15
16
17
18
19
20
21
*  Binary decoding supports "Magics" color format (http://en.wikipedia.org/wiki/STL_(file_format)#Color_in_binary_STL).
*  There is perhaps some question as to how valid it is to always assume little-endian-ness.
*  ASCII decoding assumes file is UTF-8. Seems to work for the examples...
*
* Usage:
*  let loader = new THREE.STLLoader();
*  loader.load( './models/stl/slotted_disk.stl', function ( geometry ) {
*    scene.add( new THREE.Mesh( geometry ) );
*  });
*
fork icon0
star icon2
watch icon1

61
62
63
64
65
66
67
68
69
70
// one unit is 10 cm
const worldScale = 1 / 100


// add object
new three.STLLoader().load('assets/models/test.stl', geometry => {
  const material = new THREE.MeshStandardMaterial({ color: 'darkslategrey', specular: 0x111111, shininess: 200 })
  const obj = new three.Mesh(geometry, material)      
  obj.scale.y = worldScale
  obj.scale.x = worldScale
fork icon0
star icon2
watch icon0

+ 3 other calls in file

61
62
63
64
65
66
67
68
69
70
var plate = new THREE.Mesh(plateGeometry, plateMaterial);


/** Load Custom Object **/
/*var model;
var loader = new THREE.STLLoader();
loader.load('yodabust.stl', loadHandler);
function loadHandler(geometry) {
  model = new THREE.Mesh( geometry, cubeMaterial );
  model.position.set(-9.0, -8.4, -2.0);
fork icon0
star icon0
watch icon5

Other functions in three

Sorted by popularity

function icon

three.Vector3 is the most popular function in three (22341 examples)