diff --git a/build.js b/build.js index 26bfb6d2..c60180e8 100644 --- a/build.js +++ b/build.js @@ -2,12 +2,14 @@ import * as esbuild from 'esbuild' import { createRequire } from "module"; import commandLineArgs from 'command-line-args' import path from 'path'; +import { writeFileSync } from 'fs'; const pkg = createRequire(import.meta.url)("./package.json"); const options = commandLineArgs([ {name: 'target', type: String}, {name: 'watch', type: Boolean}, {name: 'serve', type: Boolean}, + {name: 'analyze', type: Boolean}, ]) function conditionalImportPlugin(config) { @@ -38,6 +40,7 @@ const config = { bundle: true, minify: false, outfile: './dist/bundle.js', + mainFields: ['module', 'main'], external: [ 'electron', ], @@ -64,5 +67,10 @@ if (options.watch || options.serve) { console.log(`Hosting app at http://${host}:${port}`) } } else { - await esbuild.build(config); + config.minify = true; + if (options.analyze) config.metafile = true; + let result = await esbuild.build(config); + if (options.analyze) { + writeFileSync('./dist/esbuild-metafile.json', JSON.stringify(result.metafile)) + } } diff --git a/index.html b/index.html index d9ce1dbd..c007819e 100644 --- a/index.html +++ b/index.html @@ -48,7 +48,7 @@
diff --git a/js/io/formats/java_block.js b/js/io/formats/java_block.js index 95293f3b..ef7827fe 100644 --- a/js/io/formats/java_block.js +++ b/js/io/formats/java_block.js @@ -344,7 +344,7 @@ var codec = new Codec('java_block', { if (model.elements) { model.elements.forEach(function(obj) { - base_cube = new Cube(obj) + let base_cube = new Cube(obj); if (obj.__comment) base_cube.name = obj.__comment //Faces var faces_without_uv = false; diff --git a/js/modeling/transform_gizmo.js b/js/modeling/transform_gizmo.js index 7877eb81..04268cfa 100644 --- a/js/modeling/transform_gizmo.js +++ b/js/modeling/transform_gizmo.js @@ -94,7 +94,7 @@ //// PLANES - var planeGeometry = new THREE.PlaneBufferGeometry( 50, 50, 2, 2 ); + var planeGeometry = new THREE.PlaneGeometry( 50, 50, 2, 2 ); var planeMaterial = new THREE.MeshBasicMaterial( { visible: false, side: THREE.DoubleSide } ); var planes = { @@ -237,7 +237,7 @@ super(); var arrowGeometry = new THREE.CylinderGeometry( 0, 0.07, 0.2, 12, 1, false ); - let pickerCylinderGeo = new THREE.CylinderBufferGeometry( 0.2, 0, 1, 4, 1, false ); + let pickerCylinderGeo = new THREE.CylinderGeometry( 0.2, 0, 1, 4, 1, false ); var lineXGeometry = new THREE.BufferGeometry(); lineXGeometry.setAttribute( 'position', new THREE.Float32BufferAttribute( [ 0, 0, 0, 1, 0, 0 ], 3 ) ); @@ -319,8 +319,8 @@ var lineZGeometry = new THREE.BufferGeometry(); lineZGeometry.setAttribute( 'position', new THREE.Float32BufferAttribute( [ 0, 0, 0, 0, 0, 1 ], 3 ) ); - let planeGeo = new THREE.PlaneBufferGeometry( 0.3, 0.3 ); - let planePickerGeo = new THREE.PlaneBufferGeometry( 0.4, 0.4 ); + let planeGeo = new THREE.PlaneGeometry( 0.3, 0.3 ); + let planePickerGeo = new THREE.PlaneGeometry( 0.4, 0.4 ); let plane_offset = 0.3; @@ -388,16 +388,16 @@ this.pickerGizmos = { X: [ - [ new THREE.Mesh( new THREE.CylinderBufferGeometry( 0.2, 0, 1, 4, 1, false ), pickerMaterial ), [ 0.6, 0, 0 ], [ 0, 0, - Math.PI / 2 ] ], - [ new THREE.Mesh( new THREE.CylinderBufferGeometry( 0.2, 0, 1, 4, 1, false ), pickerMaterial ), [ -0.6, 0, 0 ], [ 0, 0, Math.PI / 2 ] ] + [ new THREE.Mesh( new THREE.CylinderGeometry( 0.2, 0, 1, 4, 1, false ), pickerMaterial ), [ 0.6, 0, 0 ], [ 0, 0, - Math.PI / 2 ] ], + [ new THREE.Mesh( new THREE.CylinderGeometry( 0.2, 0, 1, 4, 1, false ), pickerMaterial ), [ -0.6, 0, 0 ], [ 0, 0, Math.PI / 2 ] ] ], Y: [ - [ new THREE.Mesh( new THREE.CylinderBufferGeometry( 0.2, 0, 1, 4, 1, false ), pickerMaterial ), [ 0, 0.6, 0 ] ], - [ new THREE.Mesh( new THREE.CylinderBufferGeometry( 0.2, 0, 1, 4, 1, false ), pickerMaterial ), [ 0, -0.6, 0 ], [Math.PI / 1, 0, 0 ] ] + [ new THREE.Mesh( new THREE.CylinderGeometry( 0.2, 0, 1, 4, 1, false ), pickerMaterial ), [ 0, 0.6, 0 ] ], + [ new THREE.Mesh( new THREE.CylinderGeometry( 0.2, 0, 1, 4, 1, false ), pickerMaterial ), [ 0, -0.6, 0 ], [Math.PI / 1, 0, 0 ] ] ], Z: [ - [ new THREE.Mesh( new THREE.CylinderBufferGeometry( 0.2, 0, 1, 4, 1, false ), pickerMaterial ), [ 0, 0, 0.6 ], [ Math.PI / 2, 0, 0 ] ], - [ new THREE.Mesh( new THREE.CylinderBufferGeometry( 0.2, 0, 1, 4, 1, false ), pickerMaterial ), [ 0, 0, -0.6 ], [ - Math.PI / 2, 0, 0 ] ] + [ new THREE.Mesh( new THREE.CylinderGeometry( 0.2, 0, 1, 4, 1, false ), pickerMaterial ), [ 0, 0, 0.6 ], [ Math.PI / 2, 0, 0 ] ], + [ new THREE.Mesh( new THREE.CylinderGeometry( 0.2, 0, 1, 4, 1, false ), pickerMaterial ), [ 0, 0, -0.6 ], [ - Math.PI / 2, 0, 0 ] ] ], XY: [ [ new THREE.Mesh( planePickerGeo, pickerMaterial ), [ plane_offset, plane_offset, 0 ] ] @@ -408,7 +408,7 @@ XZ: [ [ new THREE.Mesh( planePickerGeo, pickerMaterial ), [ plane_offset, 0, plane_offset ], [ - Math.PI / 2, 0, 0 ] ] ], - E: [[ new THREE.Mesh( new THREE.SphereBufferGeometry( 0.2, 0.12, 2, 24 ), pickerMaterial ) ]], + E: [[ new THREE.Mesh( new THREE.SphereGeometry( 0.2, 0.12, 2, 24 ), pickerMaterial ) ]], }; this.pickerGizmos.X[1][0].name = 'NX' this.pickerGizmos.Y[1][0].name = 'NY' @@ -470,15 +470,15 @@ X: [ [ new THREE.Line( new CircleGeometry( 1, 'x', 0.5 ), new GizmoLineMaterial( { color: gizmo_colors.r } ) ) ], - [ new THREE.Mesh( new THREE.OctahedronBufferGeometry( 0.06, 0 ), new GizmoLineMaterial( { color: gizmo_colors.r } ) ), [ 0, 0, 0.98 ], null, [ 1, 4, 1 ] ], + [ new THREE.Mesh( new THREE.OctahedronGeometry( 0.06, 0 ), new GizmoLineMaterial( { color: gizmo_colors.r } ) ), [ 0, 0, 0.98 ], null, [ 1, 4, 1 ] ], ], Y: [ [ new THREE.Line( new CircleGeometry( 1, 'y', 0.5 ), new GizmoLineMaterial( { color: gizmo_colors.g } ) ) ], - [ new THREE.Mesh( new THREE.OctahedronBufferGeometry( 0.06, 0 ), new GizmoLineMaterial( { color: gizmo_colors.g } ) ), [ 0, 0, 0.98 ], null, [ 4, 1, 1 ] ], + [ new THREE.Mesh( new THREE.OctahedronGeometry( 0.06, 0 ), new GizmoLineMaterial( { color: gizmo_colors.g } ) ), [ 0, 0, 0.98 ], null, [ 4, 1, 1 ] ], ], Z: [ [ new THREE.Line( new CircleGeometry( 1, 'z', 0.5 ), new GizmoLineMaterial( { color: gizmo_colors.b } ) ) ], - [ new THREE.Mesh( new THREE.OctahedronBufferGeometry( 0.06, 0 ), new GizmoLineMaterial( { color: gizmo_colors.b } ) ), [ 0.98, 0, 0 ], null, [ 1, 4, 1 ] ], + [ new THREE.Mesh( new THREE.OctahedronGeometry( 0.06, 0 ), new GizmoLineMaterial( { color: gizmo_colors.b } ) ), [ 0.98, 0, 0 ], null, [ 1, 4, 1 ] ], ], E: [ @@ -490,10 +490,10 @@ this.pickerGizmos = { - X: [[ new THREE.Mesh( new THREE.TorusBufferGeometry( 1, 0.12, 4, 12, Math.PI ), pickerMaterial ), [ 0, 0, 0 ], [ 0, - Math.PI / 2, - Math.PI / 2 ] ]], - Y: [[ new THREE.Mesh( new THREE.TorusBufferGeometry( 1, 0.12, 4, 12, Math.PI ), pickerMaterial ), [ 0, 0, 0 ], [ Math.PI / 2, 0, 0 ] ]], - Z: [[ new THREE.Mesh( new THREE.TorusBufferGeometry( 1, 0.12, 4, 12, Math.PI ), pickerMaterial ), [ 0, 0, 0 ], [ 0, 0, - Math.PI / 2 ] ]], - E: [[ new THREE.Mesh( new THREE.TorusBufferGeometry( 1.2, 0.12, 2, 24 ), pickerMaterial ) ]], + X: [[ new THREE.Mesh( new THREE.TorusGeometry( 1, 0.12, 4, 12, Math.PI ), pickerMaterial ), [ 0, 0, 0 ], [ 0, - Math.PI / 2, - Math.PI / 2 ] ]], + Y: [[ new THREE.Mesh( new THREE.TorusGeometry( 1, 0.12, 4, 12, Math.PI ), pickerMaterial ), [ 0, 0, 0 ], [ Math.PI / 2, 0, 0 ] ]], + Z: [[ new THREE.Mesh( new THREE.TorusGeometry( 1, 0.12, 4, 12, Math.PI ), pickerMaterial ), [ 0, 0, 0 ], [ 0, 0, - Math.PI / 2 ] ]], + E: [[ new THREE.Mesh( new THREE.TorusGeometry( 1.2, 0.12, 2, 24 ), pickerMaterial ) ]], }; diff --git a/js/preview/canvas.js b/js/preview/canvas.js index 38cd80c0..f056586c 100644 --- a/js/preview/canvas.js +++ b/js/preview/canvas.js @@ -568,7 +568,7 @@ export const Canvas = { } if (settings.large_box.value === true) { let size = Format.cube_size_limiter?.box_marker_size || [48, 48, 48]; - var geometry_box = new THREE.EdgesGeometry(new THREE.BoxBufferGeometry(...size)); + var geometry_box = new THREE.EdgesGeometry(new THREE.BoxGeometry(...size)); var line_material = new THREE.LineBasicMaterial({color: gizmo_colors.grid}); var large_box = new THREE.LineSegments( geometry_box, line_material); @@ -769,7 +769,7 @@ export const Canvas = { } `, }) - Canvas.brush_outline = new THREE.Mesh(new THREE.PlaneBufferGeometry(1, 1), brush_outline_material); + Canvas.brush_outline = new THREE.Mesh(new THREE.PlaneGeometry(1, 1), brush_outline_material); Canvas.brush_outline.matrixAutoUpdate = false; Canvas.gizmos.push(Canvas.brush_outline); diff --git a/js/preview/preview.js b/js/preview/preview.js index e402a46e..02163cc0 100644 --- a/js/preview/preview.js +++ b/js/preview/preview.js @@ -1,3 +1,5 @@ +import { THREE } from '../../lib/libs'; + window.scene = null; window.main_preview = null; window.MediaPreview = null; diff --git a/js/util/three_custom.js b/js/util/three_custom.js index d7861eb4..061dc7ef 100644 --- a/js/util/three_custom.js +++ b/js/util/three_custom.js @@ -1,3 +1,5 @@ +import { THREE } from "../../lib/libs"; + THREE.BufferGeometry.prototype.setShape = function(from, to) { let {position} = this.attributes; @@ -185,7 +187,7 @@ THREE.AxesHelper = class AxesHelper extends THREE.LineSegments { var geometry = new THREE.BufferGeometry(); geometry.setAttribute( 'position', new THREE.Float32BufferAttribute( vertices, 3 ) ); - var material = new THREE.LineBasicMaterial( { vertexColors: THREE.VertexColors } ); + var material = new THREE.LineBasicMaterial( { vertexColors: true } ); super(geometry, material); this.updateColors(); @@ -200,7 +202,6 @@ THREE.AxesHelper = class AxesHelper extends THREE.LineSegments { } } -//THREE.AxesHelper.prototype = Object.create( THREE.LineSegments.prototype ); THREE.AxesHelper.prototype.constructor = THREE.AxesHelper; THREE.GridHelper = class GridHelper extends THREE.LineSegments { diff --git a/lib/fik.js b/lib/fik.js index 19b5ddd5..3d822a47 100644 --- a/lib/fik.js +++ b/lib/fik.js @@ -2338,7 +2338,7 @@ class Structure3D { let s = 2, r = 2, a1, a2, axe; let size = bone.length; let color = bone.color; - let g = new this.THREE.CylinderBufferGeometry ( 1, 0.5, size, 4 ); + let g = new this.THREE.CylinderGeometry ( 1, 0.5, size, 4 ); g.rotateX( -Math.PI * 0.5 ); g.translate( 0, 0, size*0.5 ); //g.applyMatrix4( new this.THREE.Matrix4().makeRotationX( -Math.PI*0.5 ) ) @@ -2360,7 +2360,7 @@ class Structure3D { if(angle === Math.PI) break; s = 2;//size/4; r = 2;// - extraGeo = new this.THREE.CylinderBufferGeometry ( 0, r, s, 6,1, true ); + extraGeo = new this.THREE.CylinderGeometry ( 0, r, s, 6,1, true ); extraGeo.rotateX( -Math.PI * 0.5 ); extraGeo.translate( 0, 0, s*0.5 ); //extraGeo.applyMatrix4( new this.THREE.Matrix4().makeRotationX( -Math.PI*0.5 ) ) @@ -2374,7 +2374,7 @@ class Structure3D { r = 2; //console.log('global', a1, a2) m2.color.setHex(0xFFFF00); - extraGeo = new this.THREE.CircleBufferGeometry( r, 12, a1, -a1+a2 ); + extraGeo = new this.THREE.CircleGeometry( r, 12, a1, -a1+a2 ); extraGeo.rotateX( -Math.PI * 0.5 ); @@ -2393,7 +2393,7 @@ class Structure3D { r = 2; m2.color.setHex(0x00FFFF); - extraGeo = new this.THREE.CircleBufferGeometry( r, 12, a1, -a1+a2 ); + extraGeo = new this.THREE.CircleGeometry( r, 12, a1, -a1+a2 ); extraGeo.rotateX( -Math.PI * 0.5 ); // extraGeo.applyMatrix4( new this.THREE.Matrix4().makeRotationX( -Math.PI*0.5 ) ); @@ -3591,7 +3591,7 @@ class Structure2D { let size = bone.length; let color = bone.color; //console.log(bone.color) - let g = new this.THREE.CylinderBufferGeometry ( 0.5, 1, size, 4 ); + let g = new this.THREE.CylinderGeometry ( 0.5, 1, size, 4 ); g.translate( 0, size*0.5, 0 ); let m = new this.THREE.MeshStandardMaterial({ color:color, wireframe:false, shadowSide:this.THREE.DoubleSide }); @@ -3606,7 +3606,7 @@ class Structure2D { let s = size/4; let r = 2;// - extraGeo = new this.THREE.CylinderBufferGeometry ( 0, r, s, 6 ); + extraGeo = new this.THREE.CylinderGeometry ( 0, r, s, 6 ); extraGeo.applyMatrix4( new this.THREE.Matrix4().makeRotationX( -Math.PI*0.5 ) ) extraGeo.applyMatrix4( new this.THREE.Matrix4().makeTranslation( 0, 0, s*0.5 ) ); extraMesh = new this.THREE.Mesh( extraGeo, m2 ); diff --git a/package-lock.json b/package-lock.json index caeb99c5..ab490ac4 100644 --- a/package-lock.json +++ b/package-lock.json @@ -21,7 +21,7 @@ "molangjs": "^1.6.5", "peerjs": "^1.5.4", "prismjs": "^1.29.0", - "three": "^0.129.0", + "three": "^0.174.0", "tinycolor2": "^1.6.0", "vue": "^2.7.16", "vue-sortable": "^0.1.3", @@ -2908,12 +2908,6 @@ "integrity": "sha512-xzLEyKB50yqCUPUJkIsrVvoWNfFUbIZI+RspLWt8u+tIW/BetMBZtgV2LY/2o+tYH8dRvQ+eoPf3NdhQCcLE2w==", "license": "MIT" }, - "node_modules/@types/three": { - "version": "0.129.2", - "resolved": "https://registry.npmjs.org/@types/three/-/three-0.129.2.tgz", - "integrity": "sha512-fZDNRtUFnq3baNjDiAzi4QoHYcczWtEdsduH/tpiwk91fbVk8COJiT/iLoN3tIOjLKMySoYsjUfP0VTmUfZKLw==", - "license": "MIT" - }, "node_modules/@types/tinycolor2": { "version": "1.4.6", "resolved": "https://registry.npmjs.org/@types/tinycolor2/-/tinycolor2-1.4.6.tgz", @@ -3457,6 +3451,12 @@ "wintersky": "^1.3.0" } }, + "node_modules/blockbench-types/node_modules/@types/three": { + "version": "0.129.2", + "resolved": "https://registry.npmjs.org/@types/three/-/three-0.129.2.tgz", + "integrity": "sha512-fZDNRtUFnq3baNjDiAzi4QoHYcczWtEdsduH/tpiwk91fbVk8COJiT/iLoN3tIOjLKMySoYsjUfP0VTmUfZKLw==", + "license": "MIT" + }, "node_modules/blockbench-types/node_modules/@vue/compiler-sfc": { "version": "2.7.14", "resolved": "https://registry.npmjs.org/@vue/compiler-sfc/-/compiler-sfc-2.7.14.tgz", @@ -7585,9 +7585,9 @@ } }, "node_modules/three": { - "version": "0.129.0", - "resolved": "https://registry.npmjs.org/three/-/three-0.129.0.tgz", - "integrity": "sha512-wiWio1yVRg2Oj6WEWsTHQo5eSzYpEwSBtPSi3OofNpvFbf26HFfb9kw4FZJNjII4qxzp0b1xLB11+tKkBGB1ZA==", + "version": "0.174.0", + "resolved": "https://registry.npmjs.org/three/-/three-0.174.0.tgz", + "integrity": "sha512-p+WG3W6Ov74alh3geCMkGK9NWuT62ee21cV3jEnun201zodVF4tCE5aZa2U122/mkLRmhJJUQmLLW1BH00uQJQ==", "license": "MIT" }, "node_modules/tiny-typed-emitter": { diff --git a/package.json b/package.json index 8824fd82..667c3117 100644 --- a/package.json +++ b/package.json @@ -122,6 +122,7 @@ "scripts": { "dev": "concurrently --raw \"electron .\" \"node ./build.js --target=electron --watch\" --kill-others --success=first", "serve": "node ./build.js --target=web --serve", + "electron": "electron .", "build-web": "node ./build.js --target=web", "build-electron": "node ./build.js --target=electron", "build-test-portable": "npm run build-electron && electron-builder --windows portable", @@ -131,6 +132,9 @@ "prepublish-beta": "node ./scripts/enable_beta.js && npm run build-web && npm run pwa", "webapp": "git checkout gh-pages && git pull && git merge master && git push && git checkout master" }, + "overrides": { + "three": "^0.174.0" + }, "devDependencies": { "@electron/notarize": "^2.5.0", "command-line-args": "^6.0.1", @@ -154,7 +158,7 @@ "molangjs": "^1.6.5", "peerjs": "^1.5.4", "prismjs": "^1.29.0", - "three": "^0.129.0", + "three": "^0.174.0", "tinycolor2": "^1.6.0", "vue": "^2.7.16", "vue-sortable": "^0.1.3",