ok anche 3mf
This commit is contained in:
@@ -21,12 +21,12 @@
|
||||
let options ={
|
||||
_dimX : X,
|
||||
_dimY: Y,
|
||||
_fileName: "Ex3.3dm",
|
||||
_fileName: "Test3MF2.3mf",
|
||||
_showInfiniteGrid: true,
|
||||
_showGrid: false,
|
||||
_isOrtographic: true,
|
||||
_modelsDir: "./src/test3/",
|
||||
_fileType: '3DM',
|
||||
_fileType: '3MF',
|
||||
_showFrame: true,
|
||||
_frameType: 2,
|
||||
_frameLen: 1500, //mm
|
||||
|
||||
+309
-332
@@ -26,7 +26,7 @@ var m_nCameraStartPos = 8 ;
|
||||
var m_bIsOrtographic = true ;
|
||||
// *** index blender ***
|
||||
var m_nStartL = 0;
|
||||
var m_nEndL = 0;
|
||||
var m_nEndL = 1000000;
|
||||
|
||||
// *** frame settings ***
|
||||
var m_bShowFrame = true ;
|
||||
@@ -216,28 +216,11 @@ function setLoaders() {
|
||||
}
|
||||
|
||||
function init3mf() {
|
||||
const manager = new THREE.LoadingManager();
|
||||
const loader = new ThreeMFLoader(manager);
|
||||
const manager = new THREE.LoadingManager() ;
|
||||
const loader = new ThreeMFLoader( manager) ;
|
||||
let startTime = performance.now();
|
||||
return new Promise(() => {
|
||||
setTimeout(() => {
|
||||
/*loader.load(modelsDir + fName, function (object) {
|
||||
object.rotation.set(-Math.PI / 2, 0, 0);
|
||||
object.traverse(function (child) {
|
||||
child.castShadow = true;
|
||||
});
|
||||
for (var i = 0; i < object.children.length; ++i) {
|
||||
var child = object.children[i];
|
||||
child.rotation.set(-Math.PI / 2, 0, 0);
|
||||
layer_list.push(child);
|
||||
}
|
||||
//console.log(layer_list);
|
||||
AdaptSeceneToContest();
|
||||
// Adapting Scene to contest
|
||||
let endTime = performance.now();
|
||||
let timeElapsed = endTime - startTime;
|
||||
console.log('init3mf in : ' + timeElapsed)
|
||||
});*/
|
||||
loader.load( modelsDir + fName, function ( object) {
|
||||
object.rotation.set( -Math.PI / 2, 0, 0) ;
|
||||
console.log( object) ;
|
||||
@@ -248,6 +231,9 @@ function init3mf() {
|
||||
}
|
||||
// Adapting Scene to contest
|
||||
AdaptSeceneToContest() ;
|
||||
let endTime = performance.now();
|
||||
let timeElapsed = endTime - startTime;
|
||||
console.log('init3mf in : ' + timeElapsed)
|
||||
console.log( new Date()) ;
|
||||
}) ;
|
||||
}, 0);
|
||||
@@ -472,176 +458,156 @@ function refreshElement(nStart, nEnd) {
|
||||
}
|
||||
else if (fileType == "3MF"){
|
||||
|
||||
for (var i = 0; i < layer_list.length; ++i) {
|
||||
if (parseInt(layer_list[i].children[0].nLayer) >= parseInt(nStart) &&
|
||||
parseInt(layer_list[i].children[0].nLayer) <= parseInt(nEnd)) {
|
||||
layer_list[i].visible = true;
|
||||
}
|
||||
else {
|
||||
layer_list[i].visible = false;
|
||||
for ( var i = 0 ; i < layer_list.length ; ++ i) {
|
||||
if ( parseInt( layer_list[i].children[0].nLayer) >= nStart &&
|
||||
parseInt( layer_list[i].children[0].nLayer) <= nEnd) {
|
||||
if ( layer_list[i].children[0].isArrow)
|
||||
layer_list[i].visible = m_bShowDir ;
|
||||
else
|
||||
layer_list[i].visible = true ;
|
||||
}
|
||||
else {
|
||||
layer_list[i].visible = false ;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
render();
|
||||
}
|
||||
|
||||
// Utility functions
|
||||
function onWindowResize() {
|
||||
}
|
||||
function AdaptSeceneToContest() {
|
||||
|
||||
scene = new THREE.Scene();
|
||||
scene.background = new THREE.Color( 0xa0a0a0) ;
|
||||
|
||||
// Global Box ----------
|
||||
if(fileType == "3DM"){
|
||||
scene.background = new THREE.Color( 0xa0a0a0) ;
|
||||
|
||||
// Global Box ----------
|
||||
if(fileType == "3DM"){
|
||||
|
||||
for ( var i = 0 ; i < layer_list.length ; ++ i) {
|
||||
const Objbox = new THREE.Box3().setFromObject( layer_list[i]);
|
||||
GLBox3D.union( Objbox) ;
|
||||
layer_list[i].material.side = THREE.DoubleSide ;
|
||||
layer_list[i].castShadow = true
|
||||
if ( ! layer_list[i].isArrow || m_bShowPrintDir)
|
||||
scene.add( layer_list[i]) ;
|
||||
}
|
||||
for ( var i = 0 ; i < layer_list.length ; ++ i) {
|
||||
const Objbox = new THREE.Box3().setFromObject( layer_list[i]);
|
||||
GLBox3D.union( Objbox) ;
|
||||
layer_list[i].material.side = THREE.DoubleSide ;
|
||||
layer_list[i].castShadow = true
|
||||
if ( ! layer_list[i].isArrow || m_bShowPrintDir)
|
||||
scene.add( layer_list[i]) ;
|
||||
}
|
||||
}
|
||||
else if(fileType == "3MF"){
|
||||
for ( var i = 0 ; i < layer_list.length ; ++ i) {
|
||||
if ( layer_list[i].children[0].type == 'Mesh') {
|
||||
const Objbox = new THREE.Box3().setFromObject( layer_list[i]);
|
||||
GLBox3D.union( Objbox) ;
|
||||
layer_list[i].children[0].material.side = THREE.DoubleSide ;
|
||||
if ( typeof layer_list[i].children[0].nLayer !== "undefined") {
|
||||
if ( parseInt( layer_list[i].children[0].nLayer)%2 == 0)
|
||||
layer_list[i].children[0].material.color.lerp( new THREE.Color( 0x000000 ), 0.25) ;
|
||||
layer_list[i].children[0].isArrow = ( layer_list[i].children[0].name == 'Arrow')
|
||||
scene.add( layer_list[i]) ;
|
||||
}
|
||||
}
|
||||
else if(fileType == "3MF"){
|
||||
for ( var i = 0 ; i < layer_list.length ; ++ i) {
|
||||
if ( layer_list[i].children[0].type == 'Mesh') {
|
||||
const Objbox = new THREE.Box3().setFromObject( layer_list[i]);
|
||||
GLBox3D.union( Objbox) ;
|
||||
layer_list[i].children[0].material.side = THREE.DoubleSide ;
|
||||
if ( typeof layer_list[i].children[0].nLayer !== "undefined") {
|
||||
if ( parseInt( layer_list[i].children[0].nLayer)%2 == 0)
|
||||
layer_list[i].children[0].material.color.lerp( new THREE.Color( 0x000000 ), 0.25) ;
|
||||
layer_list[i].children[0].isArrow = ( layer_list[i].children[0].name == 'Arrow')
|
||||
scene.add( layer_list[i]) ;
|
||||
}
|
||||
}
|
||||
else if ( layer_list[i].type == 'Vector3')
|
||||
ORIG = layer_list[i].children[0].clone() ;
|
||||
}
|
||||
}
|
||||
// const BoxHelper = new THREE.Box3Helper( GLBox3D, 0xffff00 ) ;
|
||||
const vtCenter = new THREE.Vector3( 0, 0, 0) ;
|
||||
GLBox3D.getCenter( vtCenter) ;
|
||||
const vtPosition = vtCenter.clone().multiplyScalar( 5) ;
|
||||
const vtBoxDim = new THREE.Vector3( 0, 0, 0) ;
|
||||
//GLBox3D.getSize( vtBoxDim) ;
|
||||
//scene.add( BoxHelper);
|
||||
else if ( layer_list[i].type == 'Vector3')
|
||||
ORIG = layer_list[i].children[0].clone() ;
|
||||
}
|
||||
}
|
||||
const vtCenter = new THREE.Vector3( 0, 0, 0) ;
|
||||
GLBox3D.getCenter( vtCenter) ;
|
||||
const vtPosition = vtCenter.clone().multiplyScalar( 5) ;
|
||||
const vtBoxDim = new THREE.Vector3( 0, 0, 0) ;
|
||||
|
||||
|
||||
// orthographic and perspective camera ------
|
||||
perspectiveCamera = new THREE.PerspectiveCamera( 35, window.innerWidth / window.innerHeight, 10, 300000 ) ;
|
||||
orthographicCamera = new THREE.OrthographicCamera( window.innerWidth / - 2, window.innerWidth / 2,
|
||||
window.innerHeight / 2, window.innerHeight / - 2,
|
||||
-300000, 300000) ;
|
||||
if ( ! m_bIsOrtographic)
|
||||
activeCamera = perspectiveCamera ;
|
||||
else
|
||||
activeCamera = orthographicCamera ;
|
||||
activeCamera.position.set( 2 * vtBoxDim.x, 2 * vtBoxDim.y, 2 * vtBoxDim.z) ;
|
||||
activeCamera.lookAt( vtCenter.x, vtCenter.y, vtCenter.z) ;
|
||||
scene.add( activeCamera) ;
|
||||
|
||||
// Hemisphere light --------
|
||||
const hemiLight = new THREE.HemisphereLight( 0xffffff, 0x8d8d8d );
|
||||
hemiLight.position.set( vtCenter.x, vtCenter.y + 2 * vtBoxDim.y, vtCenter.z);
|
||||
scene.add( hemiLight );
|
||||
//var HemisphereLightHelper = new THREE.Mesh( new THREE.SphereGeometry( 15, 30, 15),
|
||||
// new THREE.MeshToonMaterial({ color: 0xffffff, emissive: 0x404040 }));
|
||||
//HemisphereLightHelper.position.set( vtCenter.x, vtCenter.y + 2 * vtBoxDim.y, vtCenter.z);
|
||||
//scene.add( HemisphereLightHelper) ;
|
||||
|
||||
// direction light --------
|
||||
const dirLight = new THREE.DirectionalLight( 0xffffff );
|
||||
dirLight.position.set( vtPosition.x, vtPosition.y, vtPosition.z);
|
||||
dirLight.castShadow = true;
|
||||
dirLight.shadow.camera.top = 50;
|
||||
dirLight.shadow.camera.bottom = - 25;
|
||||
dirLight.shadow.camera.left = - 25;
|
||||
dirLight.shadow.camera.right = 25;
|
||||
dirLight.shadow.camera.near = 0.1;
|
||||
dirLight.shadow.camera.far = 200;
|
||||
dirLight.shadow.mapSize.set( 1024, 1024 );
|
||||
scene.add( dirLight );
|
||||
//const DirLighthelper = new THREE.DirectionalLightHelper( dirLight, 100 );
|
||||
//scene.add( DirLighthelper );
|
||||
|
||||
// render settings ---------
|
||||
renderer = new THREE.WebGLRenderer( { antialias: true });
|
||||
renderer.setPixelRatio( window.devicePixelRatio );
|
||||
var container = document.getElementById( 'WebGL-Export') ;
|
||||
container.style.height = m_divStartDimY + "px";
|
||||
container.style.width = m_divStartDimX + "px";
|
||||
document.body.appendChild( container );
|
||||
renderer.setSize( m_divStartDimX, m_divStartDimY) ;
|
||||
renderer.shadowMap.enabled = true;
|
||||
renderer.shadowMap.type = THREE.PCFSoftShadowMap ;
|
||||
container.appendChild( renderer.domElement) ;
|
||||
var cont = document.getElementById('spinContainer');
|
||||
container.removeChild(cont);
|
||||
// orthographic and perspective camera ------
|
||||
perspectiveCamera = new THREE.PerspectiveCamera( 35, window.innerWidth / window.innerHeight, 10, 300000 ) ;
|
||||
orthographicCamera = new THREE.OrthographicCamera( window.innerWidth / - 2, window.innerWidth / 2,
|
||||
window.innerHeight / 2, window.innerHeight / - 2,
|
||||
-300000, 300000) ;
|
||||
if ( ! m_bIsOrtographic)
|
||||
activeCamera = perspectiveCamera ;
|
||||
else
|
||||
activeCamera = orthographicCamera ;
|
||||
activeCamera.position.set( 2 * vtBoxDim.x, 2 * vtBoxDim.y, 2 * vtBoxDim.z) ;
|
||||
activeCamera.lookAt( vtCenter.x, vtCenter.y, vtCenter.z) ;
|
||||
scene.add( activeCamera) ;
|
||||
|
||||
// Hemisphere light --------
|
||||
const hemiLight = new THREE.HemisphereLight( 0xffffff, 0x8d8d8d );
|
||||
hemiLight.position.set( vtCenter.x, vtCenter.y + 2 * vtBoxDim.y, vtCenter.z);
|
||||
scene.add( hemiLight );
|
||||
|
||||
// direction light --------
|
||||
const dirLight = new THREE.DirectionalLight( 0xffffff );
|
||||
dirLight.position.set( vtPosition.x, vtPosition.y, vtPosition.z);
|
||||
dirLight.castShadow = true;
|
||||
dirLight.shadow.camera.top = 50;
|
||||
dirLight.shadow.camera.bottom = - 25;
|
||||
dirLight.shadow.camera.left = - 25;
|
||||
dirLight.shadow.camera.right = 25;
|
||||
dirLight.shadow.camera.near = 0.1;
|
||||
dirLight.shadow.camera.far = 200;
|
||||
dirLight.shadow.mapSize.set( 1024, 1024 );
|
||||
scene.add( dirLight );
|
||||
|
||||
// render settings ---------
|
||||
renderer = new THREE.WebGLRenderer( { antialias: true });
|
||||
renderer.setPixelRatio( window.devicePixelRatio );
|
||||
var container = document.getElementById( 'WebGL-Export') ;
|
||||
container.style.height = m_divStartDimY + "px";
|
||||
container.style.width = m_divStartDimX + "px";
|
||||
document.body.appendChild( container );
|
||||
renderer.setSize( m_divStartDimX, m_divStartDimY) ;
|
||||
renderer.shadowMap.enabled = true;
|
||||
renderer.shadowMap.type = THREE.PCFSoftShadowMap ;
|
||||
container.appendChild( renderer.domElement) ;
|
||||
var cont = document.getElementById('spinContainer');
|
||||
container.removeChild(cont);
|
||||
|
||||
// orbit controls -------
|
||||
controls = new OrbitControls( activeCamera, renderer.domElement );
|
||||
controls.addEventListener( 'change', render );
|
||||
controls.update() ;
|
||||
// orbit controls -------
|
||||
controls = new OrbitControls( activeCamera, renderer.domElement );
|
||||
controls.addEventListener( 'change', render );
|
||||
controls.update() ;
|
||||
|
||||
// Orig conversion -----
|
||||
if(fileType == "3DM"){
|
||||
// Orig conversion -----
|
||||
if(fileType == "3DM"){
|
||||
|
||||
const points_array = [ new THREE.Vector3( ORIG.x, ORIG.y, ORIG.z)] ;
|
||||
var ORIG_Geometry = new THREE.BufferGeometry() ;
|
||||
ORIG_Geometry.setFromPoints( points_array) ;
|
||||
var ORIG_Material = new THREE.PointsMaterial({ size: 5, sizeAttenuation : true, color : new THREE.Color( 0x000000)}) ;
|
||||
var ptORIG = new THREE.Points( ORIG_Geometry, ORIG_Material) ;
|
||||
ptORIG.position.x = ORIG.x ;
|
||||
ptORIG.position.y = ORIG.y ;
|
||||
ptORIG.position.z = ORIG.z ;
|
||||
|
||||
}
|
||||
else if(fileType == "3MF"){
|
||||
const points_array = [ new THREE.Vector3( ORIG.x, ORIG.y, ORIG.z)] ;
|
||||
var ORIG_Geometry = new THREE.BufferGeometry() ;
|
||||
ORIG_Geometry.setFromPoints( points_array) ;
|
||||
var ORIG_Material = new THREE.PointsMaterial({ size: 5, sizeAttenuation : true, color : new THREE.Color( 0x000000)}) ;
|
||||
var ptORIG = new THREE.Points( ORIG_Geometry, ORIG_Material) ;
|
||||
ptORIG.position.x = ORIG.x ;
|
||||
ptORIG.position.y = ORIG.y ;
|
||||
ptORIG.position.z = ORIG.z ;
|
||||
|
||||
}
|
||||
else if(fileType == "3MF"){
|
||||
|
||||
const points_array = [ new THREE.Vector3( 0, 0, 0)] ;
|
||||
var ORIG_Geometry = new THREE.BufferGeometry() ;
|
||||
ORIG_Geometry.setFromPoints( points_array) ;
|
||||
var ORIG_Material = new THREE.PointsMaterial({ size: 5, sizeAttenuation : true, color : new THREE.Color( 0x000000)});
|
||||
var ptORIG = new THREE.Points( ORIG_Geometry, ORIG_Material) ;
|
||||
ptORIG.position.x = ORIG.x ;
|
||||
ptORIG.position.y = ORIG.z ;
|
||||
ptORIG.position.z = - ORIG.y ;
|
||||
const points_array = [ new THREE.Vector3( 0, 0, 0)] ;
|
||||
var ORIG_Geometry = new THREE.BufferGeometry() ;
|
||||
ORIG_Geometry.setFromPoints( points_array) ;
|
||||
var ORIG_Material = new THREE.PointsMaterial({ size: 5, sizeAttenuation : true, color : new THREE.Color( 0x000000)});
|
||||
var ptORIG = new THREE.Points( ORIG_Geometry, ORIG_Material) ;
|
||||
ptORIG.position.x = ORIG.x ;
|
||||
ptORIG.position.y = ORIG.z ;
|
||||
ptORIG.position.z = - ORIG.y ;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// SetOrig(ptORIG);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// inputs --------------
|
||||
setCameraZoom( m_bZoom) ;
|
||||
setCameraPan( m_bPan) ;
|
||||
setCameraRot( m_bRot) ;
|
||||
SetCameraPos( m_nCameraStartPos, ORIG) ;
|
||||
// document.getElementById('bt_refresh').addEventListener('click', function( e){
|
||||
// ManageSceneElements( e) ;
|
||||
// }) ;
|
||||
// document.getElementById( 'bt_resetPos').addEventListener( 'click', function() {
|
||||
// SetCameraPos( m_nCameraStartPos, ORIG) ;
|
||||
// }) ;
|
||||
// document.getElementById( 'bt_camera').addEventListener( 'click', function() {
|
||||
// toggleCamera( perspectiveCamera, orthographicCamera) ;
|
||||
// }) ;
|
||||
// document.getElementById( 'ck_dir').addEventListener( 'change', function( e) {
|
||||
// ManageSceneElements( e) ;
|
||||
// })
|
||||
|
||||
// Frame
|
||||
AddFrame( ptORIG) ;
|
||||
|
||||
// Grid
|
||||
AddGrid( ptORIG) ;
|
||||
|
||||
// render
|
||||
render() ;
|
||||
// inputs --------------
|
||||
setCameraZoom( m_bZoom) ;
|
||||
setCameraPan( m_bPan) ;
|
||||
setCameraRot( m_bRot) ;
|
||||
SetCameraPos( m_nCameraStartPos, ORIG) ;
|
||||
|
||||
// Frame
|
||||
AddFrame( ptORIG) ;
|
||||
|
||||
// Grid
|
||||
AddGrid( ptORIG) ;
|
||||
|
||||
// render
|
||||
render() ;
|
||||
}
|
||||
|
||||
|
||||
function render() {
|
||||
renderer.render( scene, activeCamera) ;
|
||||
}
|
||||
@@ -669,182 +635,193 @@ function setCameraRot( bRot) {
|
||||
}
|
||||
function SetCameraPos( nPos, ptORIG) {
|
||||
var nTraslFactor = 20 ;
|
||||
var x ; var y ; var z ;
|
||||
y = GLBox3D.max.y ; // fixed
|
||||
switch( nPos) {
|
||||
case 0 :
|
||||
x = GLBox3D.min.x ;
|
||||
z = 0.5 * ( GLBox3D.min.z + GLBox3D.max.z) ;
|
||||
break ;
|
||||
case 1 :
|
||||
x = GLBox3D.min.x ;
|
||||
z = GLBox3D.max.z ;
|
||||
break ;
|
||||
case 2 :
|
||||
x = 0.5 * ( GLBox3D.min.x + GLBox3D.max.x) ;
|
||||
z = GLBox3D.max.z ;
|
||||
break ;
|
||||
case 3 :
|
||||
x = GLBox3D.max.x ;
|
||||
z = GLBox3D.max.z ;
|
||||
break ;
|
||||
case 4 :
|
||||
x = GLBox3D.max.x ;
|
||||
z = 0.5 * ( GLBox3D.min.z + GLBox3D.max.z) ;
|
||||
break ;
|
||||
case 5 :
|
||||
x = GLBox3D.max.x ;
|
||||
z = GLBox3D.min.z ;
|
||||
break ;
|
||||
case 6 :
|
||||
x = 0.5 * ( GLBox3D.min.x + GLBox3D.max.x) ;
|
||||
z = GLBox3D.min.z ;
|
||||
break ;
|
||||
case 7 :
|
||||
x = GLBox3D.min.x ;
|
||||
z = GLBox3D.min.z ;
|
||||
break ;
|
||||
case 8 : // optimal
|
||||
x = ( ORIG.x + 1.0 * Math.abs( GLBox3D.max.x - GLBox3D.min.x)) ;
|
||||
z = ( ORIG.z + 1.0 * Math.abs( GLBox3D.max.z - GLBox3D.min.z)) ;
|
||||
break ;
|
||||
default :
|
||||
return ;
|
||||
}
|
||||
|
||||
var vtPos = new THREE.Vector3( x, y, z) ;
|
||||
const vtCenter = new THREE.Vector3( 0, 0, 0) ; GLBox3D.getCenter( vtCenter) ;
|
||||
var vtDirOut = new THREE.Vector3( vtPos.x - vtCenter.x, vtPos.y - vtCenter.y, vtPos.z - vtCenter.z) ;
|
||||
vtDirOut.x *= nTraslFactor ; vtDirOut.y *= nTraslFactor ; vtDirOut.z *= nTraslFactor ;
|
||||
activeCamera.position.set( x + vtDirOut.x, y + vtDirOut.y, z + vtDirOut.z) ;
|
||||
controls.target.set( vtCenter.x, vtCenter.y, vtCenter.z) ;
|
||||
controls.minZoom = 0.25 ;
|
||||
controls.maxDistance = 1.1 * activeCamera.position.distanceTo( controls.target) ;
|
||||
controls.update() ;
|
||||
}
|
||||
function setFog() {
|
||||
//var dNear = Math.abs( Math.max( 0.5 * activeCamera.position.distanceTo( controls.target), Math.max( Math.max( GLBox3D.max.x, GLBox3D.max.y), GLBox3D.max.z))) ;
|
||||
//var dFar = dNear * 5 ;
|
||||
//scene.fog = new THREE.Fog( 0xa0a0a0, dNear, dFar) ;
|
||||
var x ; var y ; var z ;
|
||||
y = GLBox3D.max.y ; // fixed
|
||||
switch( nPos) {
|
||||
case 0 :
|
||||
x = GLBox3D.min.x ;
|
||||
z = 0.5 * ( GLBox3D.min.z + GLBox3D.max.z) ;
|
||||
break ;
|
||||
case 1 :
|
||||
x = GLBox3D.min.x ;
|
||||
z = GLBox3D.max.z ;
|
||||
break ;
|
||||
case 2 :
|
||||
x = 0.5 * ( GLBox3D.min.x + GLBox3D.max.x) ;
|
||||
z = GLBox3D.max.z ;
|
||||
break ;
|
||||
case 3 :
|
||||
x = GLBox3D.max.x ;
|
||||
z = GLBox3D.max.z ;
|
||||
break ;
|
||||
case 4 :
|
||||
x = GLBox3D.max.x ;
|
||||
z = 0.5 * ( GLBox3D.min.z + GLBox3D.max.z) ;
|
||||
break ;
|
||||
case 5 :
|
||||
x = GLBox3D.max.x ;
|
||||
z = GLBox3D.min.z ;
|
||||
break ;
|
||||
case 6 :
|
||||
x = 0.5 * ( GLBox3D.min.x + GLBox3D.max.x) ;
|
||||
z = GLBox3D.min.z ;
|
||||
break ;
|
||||
case 7 :
|
||||
x = GLBox3D.min.x ;
|
||||
z = GLBox3D.min.z ;
|
||||
break ;
|
||||
case 8 : // optimal
|
||||
x = ( ORIG.x + 1.0 * Math.abs( GLBox3D.max.x - GLBox3D.min.x)) ;
|
||||
z = ( ORIG.z + 1.0 * Math.abs( GLBox3D.max.z - GLBox3D.min.z)) ;
|
||||
break ;
|
||||
default :
|
||||
return ;
|
||||
}
|
||||
|
||||
var vtPos = new THREE.Vector3( x, y, z) ;
|
||||
const vtCenter = new THREE.Vector3( 0, 0, 0) ; GLBox3D.getCenter( vtCenter) ;
|
||||
var vtDirOut = new THREE.Vector3( vtPos.x - vtCenter.x, vtPos.y - vtCenter.y, vtPos.z - vtCenter.z) ;
|
||||
vtDirOut.x *= nTraslFactor ; vtDirOut.y *= nTraslFactor ; vtDirOut.z *= nTraslFactor ;
|
||||
activeCamera.position.set( x + vtDirOut.x, y + vtDirOut.y, z + vtDirOut.z) ;
|
||||
controls.target.set( vtCenter.x, vtCenter.y, vtCenter.z) ;
|
||||
controls.minZoom = 0.25 ;
|
||||
controls.maxDistance = 1.1 * activeCamera.position.distanceTo( controls.target) ;
|
||||
controls.update() ;
|
||||
}
|
||||
|
||||
function toggleCamera( perspectiveCamera, orthographicCamera) {
|
||||
var cameraPosition = activeCamera.position.clone() ;
|
||||
var cameraMatrix = activeCamera.matrix.clone() ;
|
||||
var ControlsTarget = controls.target.clone() ;
|
||||
var ControlsPosition = controls.position0.clone() ;
|
||||
var cameraMatrix = activeCamera.matrix.clone() ;
|
||||
var ControlsTarget = controls.target.clone() ;
|
||||
var ControlsPosition = controls.position0.clone() ;
|
||||
|
||||
if ( m_bIsOrtographic == true) {
|
||||
m_bIsOrtographic = false ;
|
||||
activeCamera = perspectiveCamera ;
|
||||
activeCamera.position.copy( cameraPosition) ;
|
||||
activeCamera.matrix.copy( cameraMatrix) ;
|
||||
} else {
|
||||
m_bIsOrtographic = true ;
|
||||
activeCamera = orthographicCamera ;
|
||||
activeCamera.position.copy( cameraPosition) ;
|
||||
activeCamera.matrix.copy( cameraMatrix) ;
|
||||
}
|
||||
|
||||
activeCamera.updateProjectionMatrix() ;
|
||||
controls.object = activeCamera ;
|
||||
controls.target = ControlsTarget ;
|
||||
controls.position0 = ControlsPosition ;
|
||||
controls.update() ;
|
||||
render() ;
|
||||
if ( m_bIsOrtographic == true) {
|
||||
m_bIsOrtographic = false ;
|
||||
activeCamera = perspectiveCamera ;
|
||||
activeCamera.position.copy( cameraPosition) ;
|
||||
activeCamera.matrix.copy( cameraMatrix) ;
|
||||
} else {
|
||||
m_bIsOrtographic = true ;
|
||||
activeCamera = orthographicCamera ;
|
||||
activeCamera.position.copy( cameraPosition) ;
|
||||
activeCamera.matrix.copy( cameraMatrix) ;
|
||||
}
|
||||
|
||||
activeCamera.updateProjectionMatrix() ;
|
||||
controls.object = activeCamera ;
|
||||
controls.target = ControlsTarget ;
|
||||
controls.position0 = ControlsPosition ;
|
||||
controls.update() ;
|
||||
render() ;
|
||||
}
|
||||
function AddFrame( ptORIG) {
|
||||
|
||||
if ( ! m_bShowFrame)
|
||||
return ;
|
||||
return ;
|
||||
|
||||
if ( m_bFrameType == 0) {
|
||||
const axesHelper = new THREE.AxesHelper( m_lFrameLen) ;
|
||||
axesHelper.rotation.set( -Math.PI/2, 0 , 0) ;
|
||||
axesHelper.position.set( ptORIG.position.x, ptORIG.position.y, ptORIG.position.z) ;
|
||||
scene.add( axesHelper ) ;
|
||||
}
|
||||
else if ( m_bFrameType == 1) {
|
||||
var vtDirs = [ new THREE.Vector3( 1, 0, 0), new THREE.Vector3( 0, 0, -1), new THREE.Vector3( 0, 1, 0)] ;
|
||||
var vtCols = [ new THREE.Color( 0xff0000), new THREE.Color( 0x00ff00), new THREE.Color( 0x0000ff)] ;
|
||||
var vtORIG = new THREE.Vector3( ptORIG.position.x, ptORIG.position.y, ptORIG.position.z) ;
|
||||
for ( var i = 0 ; i < 3 ; ++ i) {
|
||||
const arrowHelper = new THREE.ArrowHelper( vtDirs[i], vtORIG, m_lFrameLen, vtCols[i]) ;
|
||||
scene.add( arrowHelper ) ;
|
||||
}
|
||||
}
|
||||
else if ( m_bFrameType == 2) {
|
||||
var vtCols = [ new THREE.Color( 0x0000ff), new THREE.Color( 0xff0000), new THREE.Color( 0x00ff00)] ;
|
||||
for ( var i = 0 ; i < 3 ; ++ i) {
|
||||
// cylinder ----
|
||||
const fr_geometry_cyl = new THREE.CylinderGeometry( m_dFrameFat, m_dFrameFat, 0.8 * m_lFrameLen, 32) ;
|
||||
const fr_material = new THREE.MeshBasicMaterial({color: vtCols[i]}) ;
|
||||
const fr_cylinder = new THREE.Mesh( fr_geometry_cyl, fr_material) ;
|
||||
fr_cylinder.position.set( ptORIG.position.x, ptORIG.position.y, ptORIG.position.z) ;
|
||||
if ( i == 1)
|
||||
fr_cylinder.rotation.set( 0, 0, -Math.PI/2) ;
|
||||
if ( i == 2)
|
||||
fr_cylinder.rotation.set( -Math.PI/2, 0, 0) ;
|
||||
scene.add( fr_cylinder) ;
|
||||
fr_cylinder.translateY( 0.4 * m_lFrameLen) ;
|
||||
// pyramid
|
||||
const fr_geometry_cone = new THREE.CylinderGeometry( 0, 2 * m_dFrameFat, 0.2 * m_lFrameLen, 32) ;
|
||||
const fr_cone = new THREE.Mesh( fr_geometry_cone, fr_material) ;
|
||||
fr_cone.position.set( ptORIG.position.x, ptORIG.position.y, ptORIG.position.z) ;
|
||||
if ( i == 1)
|
||||
fr_cone.rotation.set( 0, 0, -Math.PI/2) ;
|
||||
if ( i == 2)
|
||||
fr_cone.rotation.set( -Math.PI/2, 0, 0) ;
|
||||
scene.add( fr_cone) ;
|
||||
fr_cone.translateY( 0.9 * m_lFrameLen) ;
|
||||
}
|
||||
// Origin
|
||||
const fr_orig_geometry = new THREE.SphereGeometry( 2 * m_dFrameFat, 32, 16) ;
|
||||
const fr_orig_material = new THREE.MeshBasicMaterial( {color: 0x00000}) ;
|
||||
const fr_sphere = new THREE.Mesh( fr_orig_geometry, fr_orig_material) ;
|
||||
fr_sphere.position.set( ptORIG.position.x, ptORIG.position.y, ptORIG.position.z) ;
|
||||
scene.add( fr_sphere) ;
|
||||
}
|
||||
else
|
||||
console.log( 'Frame type not defined') ;
|
||||
if ( m_bFrameType == 0) {
|
||||
const axesHelper = new THREE.AxesHelper( m_lFrameLen) ;
|
||||
axesHelper.rotation.set( -Math.PI/2, 0 , 0) ;
|
||||
axesHelper.position.set( ptORIG.position.x, ptORIG.position.y, ptORIG.position.z) ;
|
||||
scene.add( axesHelper ) ;
|
||||
}
|
||||
else if ( m_bFrameType == 1) {
|
||||
var vtDirs = [ new THREE.Vector3( 1, 0, 0), new THREE.Vector3( 0, 0, -1), new THREE.Vector3( 0, 1, 0)] ;
|
||||
var vtCols = [ new THREE.Color( 0xff0000), new THREE.Color( 0x00ff00), new THREE.Color( 0x0000ff)] ;
|
||||
var vtORIG = new THREE.Vector3( ptORIG.position.x, ptORIG.position.y, ptORIG.position.z) ;
|
||||
for ( var i = 0 ; i < 3 ; ++ i) {
|
||||
const arrowHelper = new THREE.ArrowHelper( vtDirs[i], vtORIG, m_lFrameLen, vtCols[i]) ;
|
||||
scene.add( arrowHelper ) ;
|
||||
}
|
||||
}
|
||||
else if ( m_bFrameType == 2) {
|
||||
var vtCols = [ new THREE.Color( 0x0000ff), new THREE.Color( 0xff0000), new THREE.Color( 0x00ff00)] ;
|
||||
for ( var i = 0 ; i < 3 ; ++ i) {
|
||||
// cylinder ----
|
||||
const fr_geometry_cyl = new THREE.CylinderGeometry( m_dFrameFat, m_dFrameFat, 0.8 * m_lFrameLen, 32) ;
|
||||
const fr_material = new THREE.MeshBasicMaterial({color: vtCols[i]}) ;
|
||||
const fr_cylinder = new THREE.Mesh( fr_geometry_cyl, fr_material) ;
|
||||
fr_cylinder.position.set( ptORIG.position.x, ptORIG.position.y, ptORIG.position.z) ;
|
||||
if ( i == 1)
|
||||
fr_cylinder.rotation.set( 0, 0, -Math.PI/2) ;
|
||||
if ( i == 2)
|
||||
fr_cylinder.rotation.set( -Math.PI/2, 0, 0) ;
|
||||
scene.add( fr_cylinder) ;
|
||||
fr_cylinder.translateY( 0.4 * m_lFrameLen) ;
|
||||
// pyramid
|
||||
const fr_geometry_cone = new THREE.CylinderGeometry( 0, 2 * m_dFrameFat, 0.2 * m_lFrameLen, 32) ;
|
||||
const fr_cone = new THREE.Mesh( fr_geometry_cone, fr_material) ;
|
||||
fr_cone.position.set( ptORIG.position.x, ptORIG.position.y, ptORIG.position.z) ;
|
||||
if ( i == 1)
|
||||
fr_cone.rotation.set( 0, 0, -Math.PI/2) ;
|
||||
if ( i == 2)
|
||||
fr_cone.rotation.set( -Math.PI/2, 0, 0) ;
|
||||
scene.add( fr_cone) ;
|
||||
fr_cone.translateY( 0.9 * m_lFrameLen) ;
|
||||
}
|
||||
// Origin
|
||||
const fr_orig_geometry = new THREE.SphereGeometry( 2 * m_dFrameFat, 32, 16) ;
|
||||
const fr_orig_material = new THREE.MeshBasicMaterial( {color: 0x00000}) ;
|
||||
const fr_sphere = new THREE.Mesh( fr_orig_geometry, fr_orig_material) ;
|
||||
fr_sphere.position.set( ptORIG.position.x, ptORIG.position.y, ptORIG.position.z) ;
|
||||
scene.add( fr_sphere) ;
|
||||
}
|
||||
else
|
||||
console.log( 'Frame type not defined') ;
|
||||
}
|
||||
function AddGrid( ptORIG) {
|
||||
|
||||
if ( ! m_bShowGrid)
|
||||
return ;
|
||||
return ;
|
||||
|
||||
const size = 1000000 ;
|
||||
const divisions = 10000 ;
|
||||
if ( m_bInfGrid) {
|
||||
const gridHelper = new THREE.GridHelper( size, divisions) ;
|
||||
gridHelper.position.set( ptORIG.position.x, ptORIG.position.y, ptORIG.position.z) ;
|
||||
gridHelper.material.transparent = true ;
|
||||
gridHelper.material.opacity = 0.25 ;
|
||||
setFog() ;
|
||||
scene.add( gridHelper) ;
|
||||
}
|
||||
else {
|
||||
var dDimX = Math.abs( GLBox3D.max.x - GLBox3D.min.x) ;
|
||||
var dDimY = Math.abs( GLBox3D.max.y - GLBox3D.min.y) ;
|
||||
var dDimZ = Math.abs( GLBox3D.max.z - GLBox3D.min.z) ;
|
||||
var dDim = 1.5 * Math.sqrt( dDimX * dDimX + dDimY * dDimY + dDimZ * dDimZ) ;
|
||||
const gridHelper = new THREE.GridHelper( dDim, Math.ceil( 0.1 * dDim)) ;
|
||||
gridHelper.position.set( ptORIG.position.x + 0.5 * dDim , ptORIG.position.y, ptORIG.position.z - 0.5 * dDim) ;
|
||||
gridHelper.material.transparent = true ;
|
||||
gridHelper.material.opacity = 0.45 ;
|
||||
scene.add( gridHelper) ;
|
||||
}
|
||||
const size = 1000000 ;
|
||||
const divisions = 10000 ;
|
||||
if ( m_bInfGrid) {
|
||||
const gridHelper = new THREE.GridHelper( size, divisions) ;
|
||||
gridHelper.position.set( ptORIG.position.x, ptORIG.position.y, ptORIG.position.z) ;
|
||||
gridHelper.material.transparent = true ;
|
||||
gridHelper.material.opacity = 0.25 ;
|
||||
setFog() ;
|
||||
scene.add( gridHelper) ;
|
||||
}
|
||||
else {
|
||||
var dDimX = Math.abs( GLBox3D.max.x - GLBox3D.min.x) ;
|
||||
var dDimY = Math.abs( GLBox3D.max.y - GLBox3D.min.y) ;
|
||||
var dDimZ = Math.abs( GLBox3D.max.z - GLBox3D.min.z) ;
|
||||
var dDim = 1.5 * Math.sqrt( dDimX * dDimX + dDimY * dDimY + dDimZ * dDimZ) ;
|
||||
const gridHelper = new THREE.GridHelper( dDim, Math.ceil( 0.1 * dDim)) ;
|
||||
gridHelper.position.set( ptORIG.position.x + 0.5 * dDim , ptORIG.position.y, ptORIG.position.z - 0.5 * dDim) ;
|
||||
gridHelper.material.transparent = true ;
|
||||
gridHelper.material.opacity = 0.45 ;
|
||||
scene.add( gridHelper) ;
|
||||
}
|
||||
}
|
||||
|
||||
function ShowPrintDir(showDir){
|
||||
console.log(showDir);
|
||||
m_bShowDir = showDir;
|
||||
for ( var i = 0 ; i < layer_list.length ; ++ i) {
|
||||
if ( layer_list[i].isArrow) {
|
||||
if ( layer_list[i].nLayer >= m_nStartL &&
|
||||
layer_list[i].nLayer <= m_nEndL)
|
||||
layer_list[i].visible = showDir ;
|
||||
else
|
||||
layer_list[i].visible = false ;
|
||||
}
|
||||
if(fileType == "3DM"){
|
||||
|
||||
for ( var i = 0 ; i < layer_list.length ; ++ i) {
|
||||
if ( layer_list[i].isArrow) {
|
||||
if ( layer_list[i].nLayer >= m_nStartL &&
|
||||
layer_list[i].nLayer <= m_nEndL)
|
||||
layer_list[i].visible = m_bShowDir ;
|
||||
else
|
||||
layer_list[i].visible = false ;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(fileType == "3MF"){
|
||||
for ( var i = 0 ; i < layer_list.length ; ++ i) {
|
||||
if ( layer_list[i].children[0].isArrow) {
|
||||
if ( parseInt( layer_list[i].children[0].nLayer) >= m_nStartL &&
|
||||
parseInt( layer_list[i].children[0].nLayer) <= m_nEndL)
|
||||
layer_list[i].visible = m_bShowDir ;
|
||||
else
|
||||
layer_list[i].visible = false ;
|
||||
}
|
||||
}
|
||||
}
|
||||
render() ;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user