-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtutorial0.html
98 lines (89 loc) · 2.68 KB
/
tutorial0.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
<title>JSCAD Design - Tutorial 0</title>
<script src="https://unpkg.com/vue@2.7.8"></script>
<script src="https://unpkg.com/vuex@2.5.0"></script>
<style>
.viewer{
width: 8cm;
height: 8cm;
margin: 0;
outline: 1px solid black;
background-color: transparent;
}
</style>
</head>
<body>
<script src="https://unpkg.com/@jscad/modeling@alpha/dist/jscad-modeling.min.js" ID="JSCAD LIBRARY"></script>
<script src="./dist/jscad-vue-components.js" ID="LIBRARY"></script>
<script src="./tutorial0.js" ID="DESIGN"></script>
<div id="app">
<div>
<jscad-viewer></jscad-viewer>
</div>
<div>
<p>Geometries: {{ count }}</p>
</div>
</div>
<script>
/**
* This is Part 0 of working with JSCAD designs.
* Why Part 0 (not 1)? Because JSCAD designs can be quite complex.
* This is a very simple application, loading a JSCAD design from a static file (tutorial0.js),
* which by the way is NOT JSCAD compliant.
*
* This tutorial loads the JSCAD design when the page loads. See script DESIGN above.
* And therefore requires the JSCAD modeling library to be loaded beforehand. See script JSCAD LIBRARY above.
* The sequence of scripts is VERY important.
*
* Finally, the design is executed (YUP! The design is actually JavaScript!), which produces some solids.
* See EXECUTION below.
*
* This works but there are some issues.
* - This tutorial requires a single file which contains a single design. JSCAD projects are not possible.
* - This tutorial uses a non-JSCAD compliant design (See the notes inside tutorial0.js)
* - This tutorial has a very specific sequence of scripts.
*/
// global registration of viewer component
Vue.component(jscadVueComponents.viewerComponent.name, jscadVueComponents.viewerComponent.properties)
// global store with minimum state for viewer component
const store = new Vuex.Store({
state: {
count: 0,
solids: []
},
getters: {
getSolids: (state) => {
return state.solids
}
},
mutations: {
// @param {State} state
// @param {Array} solids
setSolids (state, solids) {
solids.forEach((solid, i) => {
Vue.set(state.solids, i, solid)
})
// trigger callback to viewer component
state.count = solids.length
}
}
})
// initiate the Vue based application, which includes the jscad-viewer
let app = new Vue({
el: '#app',
store,
computed: {
count () {
return store.state.count
}
}
})
const solids = main() // EXECUTION
// set the solids, which updates the viewer as well
store.commit("setSolids", solids)
</script>
</body>
</html>