Skip to content
Snippets Groups Projects
main.js 32.3 KiB
Newer Older
Amira Abdel-Rahman's avatar
Amira Abdel-Rahman committed
		camera.updateProjectionMatrix();
		three1.renderer.setSize( three1.getWidth(), three1.getHeight() );
	}
	
}
////////////////

threejs.prototype.colorEdges=function() {
	
	for(var ii=0;ii<this.setup.edges.length;ii++){
		var element=this.setup.edges[ii];
		//this.colorEdge(element.stress,element.id);
		this.colorEdge(element.stress,'d'+element.id);
	}
};

threejs.prototype.colorEdge=function(val,name) {
	
	var colors = [];
	var val=map(val,this.setup.viz.minStress,this.setup.viz.maxStress,1.0,0.0);
	var divisions = Math.round( 2 * 2 );
	var colorss = new Float32Array( (divisions+1) * 3 );
	var count=0;

	for ( var i = 0, l = divisions; i <= l; i ++ ) {
		color=interpolateLinearly(val, this.setup.viz.colorMaps[this.setup.viz.colorMap]);
		colors.push( color[0], color[1], color[2]);
		colorss[count]=color[0]
		colorss[count+1]=color[1]
		colorss[count+2]=color[2]
		count+=3
	}
	var edge = this.scene.getObjectByName(name);
	if(this.thinLines){
		edge.geometry.setAttribute( 'color',new THREE.BufferAttribute( colorss, 3 ) );
		color=interpolateLinearly(val, this.setup.viz.colorMaps[this.setup.viz.colorMap]);
		edge.geometry.colorsNeedUpdate = true; 
		edge.material.needsUpdate=true;
	}else{
		edge.geometry.setColors( colors );

	}
	

};

threejs.prototype.drawConstraintBoundingBoxes=function() {
	let supports=this.setup.supports;
	let loads=this.setup.loads;
	let mat=this.setup.materials;
	let disps=this.setup.fixedDisplacements;
	if (supports ) {
		for (var i=0;i< supports.length;i++) {
			let s=supports[i][0];
			this.drawBox1(s.min,s.max,color4);
		}
	}
	if (loads ) {
		for (var i=0;i< loads.length;i++) {
			let l=loads[i][0];
			this.drawBox1(l.min,l.max,color7);
		}
		
	}
	if (disps ) {
		for (var i=0;i< disps.length;i++) {
			let l=disps[i][0];
			this.drawBox1(l.min,l.max,color7);
		}
		
	}
	if (mat ) {
		
		for (var i=0;i< mat.length;i++) {
			let l=mat[i][0];
			// console.log(l)
			this.drawBox1(l.min,l.max,color5);
		}
		
	}
	
};

threejs.prototype.drawBox=function(min,max,color) {
	var box = new THREE.Box3(new THREE.Vector3(min[0],min[1],min[2]),new THREE.Vector3(max[0],max[1],max[2]));
	var helper = new THREE.Box3Helper( box, color );
	this.scene.add( helper );
	// todo add name??
};

threejs.prototype.drawBox1=function(min,max,color) {
	var box = new THREE.Box3(new THREE.Vector3(min.x,min.y,min.z),new THREE.Vector3(max.x,max.y,max.z));
	var helper = new THREE.Box3Helper( box, color );
	this.scene.add( helper );
	// todo add name??
};
/////////////////gui////////////////
function guiCreate (three){
	

	var f1 = gui.addFolder('Displacement Animation '+three.containerName);
	f1.add(three.setup.animation, 'showDisplacement');
	f1.add(three.setup.animation, 'exaggeration', 0, 1000);
	f1.add(three.setup.animation, 'speed', 0, 10);

	var f2 = gui.addFolder('Stresses Visualization '+three.containerName);
	f2.add(three.setup.viz, 'minStress', -1000, 0).listen();
	f2.add(three.setup.viz, 'maxStress', 0, 1000).listen();
	f2.add(three.setup.viz, 'colorMap', {coolwarm:0, YlGnBu:1, winter:2,jet:3});

	// gui.add(setup, 'solve');

	for (j in f2.__controllers) f2.__controllers[j].onChange (updateColors.bind(this)); //todo check three
	for (j in f1.__controllers) f1.__controllers[j].onChange (renderLast.bind(this)); //todo check three
	
}

//todo remove this
function updateColors(){
	three.colorEdges();
	if(typeof three1 !== 'undefined'){
		three1.colorEdges();
	}
}

function renderLast(){
	three.renderLast();
	if(typeof three1 !== 'undefined'){
		three1.renderLast();
	}
	
}