Browse Source

auto center objects in 3d viewer

Thomas Buck 7 months ago
parent
commit
68fc24922d
4 changed files with 47 additions and 8 deletions
  1. 2
    1
      3dprint/beam.scad
  2. 26
    0
      docs/src/3dprint.md
  3. 15
    7
      docs/src/js/3d.js
  4. 4
    0
      docs/src/pcb1_pcb.md

+ 2
- 1
3dprint/beam.scad View File

@@ -1,3 +1,4 @@
1
+part="all";//[all]
1 2
 $fa=1/1;
2 3
 $fs=1/2;
3 4
 bissl=1/100;
@@ -49,4 +50,4 @@ difference() {
49 50
   translate([-hd/2-offset-wall/2,height/4-wall,thickness/2])rotate([0,90,0])cylinder(d=hole,h=hd-wall);
50 51
   translate([-hd/2-offset-wall/2,height/2-wall/2,thickness/2])rotate([0,90,0])cylinder(d=hole,h=hd-wall);
51 52
   translate([-hd/2-offset-wall/2,height*3/4,thickness/2])rotate([0,90,0])cylinder(d=hole,h=hd-wall);
52
-}
53
+}

+ 26
- 0
docs/src/3dprint.md View File

@@ -2,42 +2,68 @@
2 2
 
3 3
 **TODO** work in progress
4 4
 
5
+## Beam
6
+
7
+{{#include inc_beam_all.stl.md}}
8
+
9
+[Direct link to this file](./stl/beam_all.stl).
10
+
5 11
 ## Actuator All
6 12
 
7 13
 {{#include inc_actuator_all.stl.md}}
8 14
 
15
+[Direct link to this file](./stl/actuator_all.stl).
16
+
9 17
 ## Actuator Cap
10 18
 
11 19
 {{#include inc_actuator_cap.stl.md}}
12 20
 
21
+[Direct link to this file](./stl/actuator_cap.stl).
22
+
13 23
 ## Actuator Hammer
14 24
 
15 25
 {{#include inc_actuator_hammer.stl.md}}
16 26
 
27
+[Direct link to this file](./stl/actuator_hammer.stl).
28
+
17 29
 ## Actuator Spool
18 30
 
19 31
 {{#include inc_actuator_spool.stl.md}}
20 32
 
33
+[Direct link to this file](./stl/actuator_spool.stl).
34
+
21 35
 ## Tamb Mount All Visualize
22 36
 
23 37
 {{#include inc_tamb_mount_all_visualize.stl.md}}
24 38
 
39
+[Direct link to this file](./stl/tamb_mount_all_visualize.stl).
40
+
25 41
 ## Tamb Mount Inner
26 42
 
27 43
 {{#include inc_tamb_mount_inner.stl.md}}
28 44
 
45
+[Direct link to this file](./stl/tamb_mount_inner.stl).
46
+
29 47
 ## Tamb Mount Outer
30 48
 
31 49
 {{#include inc_tamb_mount_outer.stl.md}}
32 50
 
51
+[Direct link to this file](./stl/tamb_mount_outer.stl).
52
+
33 53
 ## Enclosure Bottom
34 54
 
35 55
 {{#include inc_enclosure_bottom.stl.md}}
36 56
 
57
+[Direct link to this file](./stl/enclosure_bottom.stl).
58
+
37 59
 ## Enclosure Top
38 60
 
39 61
 {{#include inc_enclosure_top.stl.md}}
40 62
 
63
+[Direct link to this file](./stl/enclosure_top.stl).
64
+
41 65
 ## Enclosure Faceplate
42 66
 
43 67
 {{#include inc_enclosure_faceplate.stl.md}}
68
+
69
+[Direct link to this file](./stl/enclosure_faceplate.stl).

+ 15
- 7
docs/src/js/3d.js View File

@@ -10,10 +10,13 @@ import { STLLoader } from 'three/addons/loaders/STLLoader.js'
10 10
 import { VRMLLoader } from 'three/addons/loaders/VRMLLoader.js';
11 11
 
12 12
 // https://wejn.org/2020/12/cracking-the-threejs-object-fitting-nut/
13
-function fitCameraToCenteredObject(camera, object, offset, orbitControls, yOffset) {
13
+function fitCameraToObject(camera, object, offset, orbitControls, yOffset) {
14 14
     const boundingBox = new THREE.Box3();
15 15
     boundingBox.setFromObject( object );
16 16
 
17
+    var middle = new THREE.Vector3();
18
+    boundingBox.getCenter(middle);
19
+
17 20
     var size = new THREE.Vector3();
18 21
     boundingBox.getSize(size);
19 22
 
@@ -61,7 +64,8 @@ function fitCameraToCenteredObject(camera, object, offset, orbitControls, yOffse
61 64
     // offset the camera, if desired (to avoid filling the whole canvas)
62 65
     if( offset !== undefined && offset !== 0 ) cameraZ *= offset;
63 66
 
64
-    camera.position.set( 0, yOffset * cameraZ, cameraZ );
67
+    camera.target = middle;
68
+    camera.position.set( middle.x, middle.y + yOffset * cameraZ, middle.z + cameraZ );
65 69
 
66 70
     // set the far plane of the camera so that it easily encompasses the whole object
67 71
     const minZ = boundingBox.min.z;
@@ -72,7 +76,7 @@ function fitCameraToCenteredObject(camera, object, offset, orbitControls, yOffse
72 76
 
73 77
     if ( orbitControls !== undefined ) {
74 78
         // set camera to rotate around the center
75
-        orbitControls.target = new THREE.Vector3(0, 0, 0);
79
+        orbitControls.target = middle;
76 80
 
77 81
         // prevent camera from zooming out far enough to create far plane cutoff
78 82
         orbitControls.maxDistance = cameraToFarEdge * 2;
@@ -84,7 +88,7 @@ export function init_3d(path, container, status, div_width, div_height) {
84 88
     const height = div_height;
85 89
 
86 90
     const scene = new THREE.Scene();
87
-    scene.add(new THREE.AxesHelper(1));
91
+    //scene.add(new THREE.AxesHelper(1));
88 92
 
89 93
     const camera = new THREE.PerspectiveCamera(75, width / height, 0.1, 1000);
90 94
 
@@ -117,8 +121,10 @@ export function init_3d(path, container, status, div_width, div_height) {
117 121
             path,
118 122
             function (geometry) {
119 123
                 const mesh = new THREE.Mesh(geometry, material);
124
+                mesh.rotation.setFromVector3(new THREE.Vector3(-Math.PI / 2, 0, 0));
120 125
                 scene.add(mesh);
121
-                fitCameraToCenteredObject(camera, scene, 0, controls, 0);
126
+                fitCameraToObject(camera, scene, 0, controls, 0);
127
+                controls.update();
122 128
             },
123 129
             (xhr) => {
124 130
                 const s = (xhr.loaded / xhr.total) * 100 + '% loaded';
@@ -139,7 +145,8 @@ export function init_3d(path, container, status, div_width, div_height) {
139 145
             path,
140 146
             function (object) {
141 147
                 scene.add(object);
142
-                fitCameraToCenteredObject(camera, scene, 0, controls, 0);
148
+                fitCameraToObject(camera, scene, 0, controls, 0);
149
+                controls.update();
143 150
             },
144 151
             (xhr) => {
145 152
                 const s = (xhr.loaded / xhr.total) * 100 + '% loaded';
@@ -195,7 +202,8 @@ export function init_3d(path, container, status, div_width, div_height) {
195 202
     btn_rst.type = "button";
196 203
     btn_rst.value = "Reset Camera";
197 204
     btn_rst.addEventListener('click', function() {
198
-        fitCameraToCenteredObject(camera, scene, 0, controls, 0);
205
+        fitCameraToObject(camera, scene, 0, controls, 0);
206
+        controls.update();
199 207
     });
200 208
 
201 209
     const div_rst = document.createElement("div");

+ 4
- 0
docs/src/pcb1_pcb.md View File

@@ -20,6 +20,10 @@ You can also view the [2D PCB layout as PDF](./plot/drumkit.kicad_pcb.pdf).
20 20
 
21 21
 ## DIY Version
22 22
 
23
+The DIY version is suitable for etching at home, it only needs the bottom copper layer.
24
+Be aware that there is one track on the top layer, for a safety diode that was added later.
25
+This connection should be done with a wire by hand.
26
+
23 27
 You can also view the [DIY layout as PDF](./plot/drumkit.kicad_pcb_diy.pdf).
24 28
 
25 29
 <script src="js/svg-pan-zoom.js" charset="UTF-8"></script>

Loading…
Cancel
Save