fix utilizzo 3dm e 3mf

This commit is contained in:
zaccaria.majid
2023-10-23 09:49:49 +02:00
parent 08ee9c9f66
commit 99175b166f
12 changed files with 98 additions and 51 deletions
+10 -2
View File
@@ -21,11 +21,13 @@
let options ={
_dimX : X,
_dimY: Y,
_fileName: "ProjectSlice.3mf",
_fileName: "Ex3.3dm",
_showLimitedGrid: true,
_isOrtographic: true,
_modelsDir: "./src/test3/",
_fileType: '3MF'
_fileType: '3DM',
// _showFrame: true,
// _showGrid: true
}
console.log(options._modelsDir + options._fileName)
@@ -64,6 +66,12 @@
WGL.setCameraType();
}
document.getElementById('ck_print').onclick = function(){
var val = document.getElementById('ck_print').checked;
WGL.showPrintDirection(val);
}
</script>
<script src="webgl-visualizer/draw/webgl_drawVue.js" type="module"></script>
</html>
+4 -4
View File
@@ -10,7 +10,7 @@
"license": "MIT",
"dependencies": {
"vue": "^2.5.11",
"webgl-visualizer": "^1.2.231019-beta.1237"
"webgl-visualizer": "^1.2.231019-beta.1506"
},
"devDependencies": {
"babel-core": "^6.26.0",
@@ -9296,9 +9296,9 @@
}
},
"node_modules/webgl-visualizer": {
"version": "1.2.231019-beta.1237",
"resolved": "https://nexus.steamware.net/repository/npm-group/webgl-visualizer/-/webgl-visualizer-1.2.231019-beta.1237.tgz",
"integrity": "sha512-qjV1loIAgopaMfMr5QHuRH7mIiyHBI3obygjsKiG8CFqGwGETobhUVlEQ6GlgDuZyRTZWrKRVY4Clr7/XW5Y/A==",
"version": "1.2.231019-beta.1506",
"resolved": "https://nexus.steamware.net/repository/npm-group/webgl-visualizer/-/webgl-visualizer-1.2.231019-beta.1506.tgz",
"integrity": "sha512-iIe/E75g6IVmBSLDwSW0qVLVo890SH7U04dqFENds4dzC4ULIbhQ/GjGhW0mhjA9HrvBAgSOfPArVrRGzf7Rzw==",
"license": "ISC"
},
"node_modules/webpack": {
+1 -1
View File
@@ -11,7 +11,7 @@
},
"dependencies": {
"vue": "^2.5.11",
"webgl-visualizer": "^1.2.231019-beta.1237"
"webgl-visualizer": "^1.2.231019-beta.1506"
},
"browserslist": [
"> 1%",
@@ -13,6 +13,7 @@
<button id="btnRef">Resize</button>
<button id="btnResetCam">Reset camera</button>
<input type='button' id='bt_camera' value = "Toggle Camera">
<input type='checkbox' id='ck_print' checked>
</div>
<div id = "WebGL-Export">
</div>
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+82 -44
View File
@@ -12,7 +12,7 @@ var m_divStartDimY = 400;
var fName = "Cubo.3mf";
//var fileType = "3MF";
var fileType = '3MF';
var fileType = '3DM';
var m_nApproxIndex = 5;
@@ -55,18 +55,13 @@ var layer_list = [];
const GLBox3D = new THREE.Box3(); // Box3D globale delle geometrie
//init();
class webgl_original {
async initcall({ _dimX, _dimY, _fileName, _showInfiniteGrid, _fileType, _modelsDir, _approxIndex, _showFrame, _frameLen, _frameFat, _frameType}) {
async initcall({ _dimX, _dimY, _fileName, _showInfiniteGrid, _fileType, _modelsDir}) {
m_divStartDimX = _dimX;
m_divStartDimY = _dimY;
fName = _fileName;
m_bInfGrid = _showInfiniteGrid;
modelsDir = _modelsDir;
fileType = _fileType;
m_nApproxIndex = _approxIndex;
m_bShowFrame = _showFrame;
m_lFrameLen = _frameLen;
m_dFrameFat = _frameFat;
m_bFrameType = _frameType;
//console.log(fName)
setLoaders();
if(fileType.toUpperCase() == '3MF')
@@ -106,7 +101,11 @@ export { webgl_original }
function setLoaders() {
//<input type="range" class="form-range" id="customRange1">
const mother = document.getElementById('WebGL-Export');
let mother = document.getElementById('WebGL-Export');
if(fileType.toUpperCase() == '3DM')
{
mother = document.getElementById('WebGL-Export')
}
const spinContainer = document.createElement('div');
const sliderInput = document.createElement('input');
@@ -192,7 +191,7 @@ function setLoaders() {
cDiv[i].style.backgroundSize = 'contain';
// cDiv[i].style.backgroundColor = '#000';
// cDiv[i].style.backgroundImage = 'url(../node_modules/webgl-visualizer/styles/LogoClassic_NoText.png)'
cDiv[i].style.backgroundImage = 'url(../node_modules/webgl-visualizer/styles/LogoClassic_NoText.png)'
}
}
@@ -213,10 +212,10 @@ function setLoaders() {
function init3mf() {
const manager = new THREE.LoadingManager();
const loader = new ThreeMFLoader(manager);
let startTime = performance.now();
let startTime = performance.now();
return new Promise(() => {
setTimeout(() => {
loader.load(modelsDir + fName, function (object) {
/*loader.load(modelsDir + fName, function (object) {
object.rotation.set(-Math.PI / 2, 0, 0);
object.traverse(function (child) {
child.castShadow = true;
@@ -232,7 +231,19 @@ function init3mf() {
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) ;
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) ;
}
// Adapting Scene to contest
AdaptSeceneToContest() ;
console.log( new Date()) ;
}) ;
}, 0);
});
@@ -356,18 +367,12 @@ function init3dm(){
var Zact ;
var vtCoord = new THREE.Vector4( points_array[v], points_array[v+1], points_array[v+2], 1) ;
vtCoord.applyMatrix4( Mat_GlobToLoc) ;
//if ( v != 0 && v < points_array.length - 3 &&
// (( vtCoord.x - ptPrec.x) * ( vtCoord.x - ptPrec.x) +
// ( vtCoord.y - ptPrec.y) * ( vtCoord.y - ptPrec.y) +
// ( vtCoord.z - ptPrec.z) * ( vtCoord.z - ptPrec.z)) < 10)
// continue ;
if ( v == 0) {
shape.moveTo( vtCoord.x, vtCoord.y) ;
Zact = vtCoord.z ;
}
else
shape.lineTo( vtCoord.x, vtCoord.y) ;
//ptPrec = new THREE.Vector4( vtCoord.x, vtCoord.y, vtCoord.z, 1) ;
}
var cCol = child.material.color.clone() ;
if ( nLayer%2 == 0) {
@@ -455,15 +460,35 @@ function AdaptSeceneToContest() {
scene.background = new THREE.Color( 0xa0a0a0) ;
// Global Box ----------
for ( var i = 0 ; i < layer_list.length ; ++ i) {
const Objbox = new THREE.Box3().setFromObject( layer_list[i]);
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]) ;
scene.add( layer_list[i]) ;
}
const BoxHelper = new THREE.Box3Helper( GLBox3D, 0xffff00 ) ;
}
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) ;
@@ -528,16 +553,41 @@ function AdaptSeceneToContest() {
controls.update() ;
// Orig conversion -----
const points_array = [ new THREE.Vector3( ORIG.x, ORIG.y, ORIG.z)] ;
var ORIG_Geometry = new THREE.BufferGeometry() ;
if(fileType == "3DM"){
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 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 ;
ptORIG.position.y = ORIG.z ;
ptORIG.position.z = - ORIG.y ;
}
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 ;
// SetOrig(ptORIG);
}
// Frame
AddFrame( ptORIG) ;
// Grid
AddGrid( ptORIG) ;
// render
render() ;
// inputs --------------
setCameraZoom( m_bZoom) ;
setCameraPan( m_bPan) ;
@@ -554,18 +604,12 @@ function AdaptSeceneToContest() {
// }) ;
// document.getElementById( 'ck_dir').addEventListener( 'change', function( e) {
// ManageSceneElements( e) ;
// })
// Frame
AddFrame( ptORIG) ;
// Grid
AddGrid( ptORIG) ;
// render
render() ;
// })
}
function render() {
renderer.render( scene, activeCamera) ;
}
function SetOrig( ORIG) {
// qui in qualche modo imposto l'origine, ora impostata secondo il BozHelper
// ---- codice da cambiare
@@ -577,12 +621,6 @@ function SetOrig( ORIG) {
// -----------------------
//scene.add( ORIG) ;
}
function render() {
renderer.render( scene, activeCamera) ;
stats.update() ;
}
function setCameraZoom( bZoom) {
controls.enableZoom = bZoom ;
}