Bläddra i källkod

auto center objects in 3d viewer

Thomas Buck 1 månad sedan
förälder
incheckning
68fc24922d
4 ändrade filer med 47 tillägg och 8 borttagningar
  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 Visa fil

1
+part="all";//[all]
1
 $fa=1/1;
2
 $fa=1/1;
2
 $fs=1/2;
3
 $fs=1/2;
3
 bissl=1/100;
4
 bissl=1/100;
49
   translate([-hd/2-offset-wall/2,height/4-wall,thickness/2])rotate([0,90,0])cylinder(d=hole,h=hd-wall);
50
   translate([-hd/2-offset-wall/2,height/4-wall,thickness/2])rotate([0,90,0])cylinder(d=hole,h=hd-wall);
50
   translate([-hd/2-offset-wall/2,height/2-wall/2,thickness/2])rotate([0,90,0])cylinder(d=hole,h=hd-wall);
51
   translate([-hd/2-offset-wall/2,height/2-wall/2,thickness/2])rotate([0,90,0])cylinder(d=hole,h=hd-wall);
51
   translate([-hd/2-offset-wall/2,height*3/4,thickness/2])rotate([0,90,0])cylinder(d=hole,h=hd-wall);
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 Visa fil

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

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

+ 4
- 0
docs/src/pcb1_pcb.md Visa fil

20
 
20
 
21
 ## DIY Version
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
 You can also view the [DIY layout as PDF](./plot/drumkit.kicad_pcb_diy.pdf).
27
 You can also view the [DIY layout as PDF](./plot/drumkit.kicad_pcb_diy.pdf).
24
 
28
 
25
 <script src="js/svg-pan-zoom.js" charset="UTF-8"></script>
29
 <script src="js/svg-pan-zoom.js" charset="UTF-8"></script>

Laddar…
Avbryt
Spara