@@ -70,6 +70,7 @@ def translate(ctxt, txt):
7070disableCompression = False # Compress object data before sending to JS
7171base = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890!#$%&()*+-:;/=>?@[]^_,.{|}~`" # safe str chars for js in all cases
7272baseFloat = ",.-0123456789"
73+ threejs_version = "0.172.0"
7374
7475
7576def getHTMLTemplate ():
@@ -110,23 +111,31 @@ def getHTMLTemplate():
110111 select { width: 170px; }
111112 </style>
112113 </head>
114+ <script type="importmap">
115+ {
116+ "imports": {
117+ "three": "https://cdn.jsdelivr.net/npm/three@$threejs_version/build/three.module.js",
118+ "three/addons/": "https://cdn.jsdelivr.net/npm/three@$threejs_version/examples/jsm/"
119+ }
120+ }
121+ </script>
113122 <body>
114123 <canvas id="mainCanvas"></canvas>
115124 <canvas id="arrowCanvas"></canvas>
116125 <script type="module">
117126 // Direct from mrdoob: https://www.jsdelivr.com/package/npm/three
118- import * as THREE from 'https://cdn.jsdelivr.net/npm/ three@0.125.0/build/three.module.js';
119- import { OrbitControls } from 'https://cdn.jsdelivr.net/npm/ three@0.125.0/examples/jsm /controls/OrbitControls.js';
120- import { GUI } from 'https://cdn.jsdelivr.net/npm/ three@0.125.0/examples/jsm/ libs/dat. gui.module.js';
121- import { Line2 } from 'https://cdn.jsdelivr.net/npm/ three@0.125.0/examples/jsm /lines/Line2.js';
122- import { LineMaterial } from 'https://cdn.jsdelivr.net/npm/ three@0.125.0/examples/jsm /lines/LineMaterial.js';
123- import { LineGeometry } from 'https://cdn.jsdelivr.net/npm/ three@0.125.0/examples/jsm /lines/LineGeometry.js';
124- import { EdgeSplitModifier } from 'https://cdn.jsdelivr.net/npm/ three@0.125.0/examples/jsm /modifiers/EdgeSplitModifier.js';
127+ import * as THREE from ' three'
128+ import { OrbitControls } from 'three/addons /controls/OrbitControls.js';
129+ import { GUI } from 'three/addons/ libs/lil- gui.module.min .js';
130+ import { Line2 } from 'three/addons /lines/Line2.js';
131+ import { LineMaterial } from 'three/addons /lines/LineMaterial.js';
132+ import { LineGeometry } from 'three/addons /lines/LineGeometry.js';
133+ import { EdgeSplitModifier } from 'three/addons /modifiers/EdgeSplitModifier.js';
125134
126135 const data = $data;
127136
128137 // Z is up for FreeCAD
129- THREE.Object3D.DefaultUp = new THREE.Vector3(0, 0, 1);
138+ THREE.Object3D.DEFAULT_UP = new THREE.Vector3(0, 0, 1);
130139
131140 const defaultWireColor = new THREE.Color('rgb(0,0,0)');
132141 const defaultWireLineWidth = 2; // in pixels
@@ -289,7 +298,6 @@ def getHTMLTemplate():
289298 color: color,
290299 side: THREE.DoubleSide,
291300 vertexColors: false,
292- flatShading: false,
293301 opacity: opacity,
294302 transparent: opacity != 1.0,
295303 fog: false
@@ -366,7 +374,11 @@ def getHTMLTemplate():
366374 }
367375
368376 // ---- GUI Init ----
369- const gui = new GUI({ width: 300 });
377+ const gui = new GUI({ width: 300, closeFolders: true });
378+ const addFolder = GUI.prototype.addFolder;
379+ GUI.prototype.addFolder = function(...args) {
380+ return addFolder.call(this, ...args).close();
381+ }
370382 const guiparams = {
371383 wiretype: 'Normal',
372384 wirewidth: defaultWireLineWidth,
@@ -526,8 +538,7 @@ def getHTMLTemplate():
526538 new THREE.Vector3(0, 0, 1), arrowPos, 60, 0x20207F, 20, 10));
527539 arrowScene.add(new THREE.Mesh(
528540 new THREE.BoxGeometry(40, 40, 40),
529- new THREE.MeshLambertMaterial(
530- { color: 0xaaaaaa, flatShading: false })
541+ new THREE.MeshLambertMaterial({ color: 0xaaaaaa })
531542 ));
532543 arrowScene.add(new THREE.HemisphereLight(0xC7E8FF, 0xFFE3B3, 1.2));
533544
@@ -833,10 +844,10 @@ def export(
833844 data ["baseFloat" ] = baseFloat
834845
835846 html = html .replace ("$data" , json .dumps (data , separators = ("," , ":" ))) # Shape Data
847+ html = html .replace ("$threejs_version" , threejs_version )
836848
837- outfile = pyopen (filename , "w" )
838- outfile .write (html )
839- outfile .close ()
849+ with pyopen (filename , "w" , encoding = "utf-8" ) as outfile :
850+ outfile .write (html )
840851 FreeCAD .Console .PrintMessage (translate ("Arch" , "Successfully written" ) + f" { filename } \n " )
841852
842853
0 commit comments