Skip to content
Snippets Groups Projects
Commit e43fa06b authored by Amanda Ghassaei's avatar Amanda Ghassaei
Browse files

load stapler stls

parent 0d37c0b4
Branches
Tags
No related merge requests found
......@@ -11,8 +11,9 @@ function Assembler(){
this.object3D = new THREE.Object3D();
globals.three.sceneAdd(this.object3D);
var self = this;
this._loadStls(function(){
this._buildAssemblerMeshes(function(){
self._configureAssemblerMovementDependencies();
globals.three.render();
});
}
......@@ -21,8 +22,28 @@ Assembler.prototype._buildStock = function(){
return globals.lattice.makeCellForLatticeType(null);
};
Assembler.prototype._loadStls = function(callback){
Assembler.prototype._buildAssemblerMeshes = function(callback){
var numMeshes = this._getTotalNumMeshes();
if (numMeshes == 0) {
callback();
return;
}
function allLoaded(){
numMeshes -= 1;
return numMeshes <= 0;
}
var self = this;
function doAdd(geometry, name){
self[name] = new THREE.Mesh(geometry, assemblerMaterial);
if (allLoaded()) callback();
}
this._loadSTls(doAdd);
};
Assembler.prototype._getTotalNumMeshes = function(){
return 0;
};
Assembler.prototype._configureAssemblerMovementDependencies = function(){
......
......@@ -17,38 +17,33 @@ StaplerAssembler.prototype._configureAssemblerMovementDependencies = function(){
this.object3D.add(this.substrate);
};
StaplerAssembler.prototype._loadStls = function(callback){
var meshes = [];
var numMeshes = 5;
function allLoaded(){
numMeshes -= 1;
return numMeshes <= 0;
}
StaplerAssembler.prototype._getTotalNumMeshes = function(){
return 5;
};
StaplerAssembler.prototype._loadSTls = function(doAdd){
function geometryScale(geometry){
var unitScale = 1;
geometry.applyMatrix(new THREE.Matrix4().makeScale(unitScale, unitScale, unitScale));
geometry.applyMatrix(new THREE.Matrix4().makeRotationX(Math.PI/2));
return geometry;
}
var material = assemblerMaterial;
var self = this;
function meshPrep(geometry, name){
self[name] = new THREE.Mesh(geometry, material);
if (allLoaded()) callback(meshes);
}
var loader = new THREE.STLLoader();
loader.load("assets/stls/stapler/frame.stl", function(geometry){
meshPrep(geometryScale(geometry), "frame");
doAdd(geometryScale(geometry), "frame");
});
loader.load("assets/stls/stapler/zStage.stl", function(geometry){
meshPrep(geometryScale(geometry), "zAxis");
doAdd(geometryScale(geometry), "zAxis");
});
loader.load("assets/stls/stapler/yStage.stl", function(geometry){
meshPrep(geometryScale(geometry), "yAxis");
doAdd(geometryScale(geometry), "yAxis");
});
loader.load("assets/stls/stapler/xStage.stl", function(geometry){
meshPrep(geometryScale(geometry), "xAxis");
doAdd(geometryScale(geometry), "xAxis");
});
loader.load("assets/stls/stapler/substrate.stl", function(geometry){
meshPrep(geometryScale(geometry), "substrate");
doAdd(geometryScale(geometry), "substrate");
});
};
\ No newline at end of file
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment