2019-11-24 18:15:44 +00:00
|
|
|
## A Brief Tour of dyna3
|
|
|
|
|
|
|
|
When you load dyna3, you should initially see a three-dimensional coordinate system with labeled axes.
|
|
|
|
```javascript
|
|
|
|
|
|
|
|
import {threeLoaded, three as J3} from './externals.js'
|
|
|
|
|
2019-12-12 07:44:33 +00:00
|
|
|
LTx = { dashed: true, plain: false }
|
|
|
|
|
|
|
|
buildAxis = (to, color, tx) ->
|
|
|
|
geom = new J3.Geometry()
|
|
|
|
if tx then mat = new J3.LineDashedMaterial(
|
|
|
|
{linewidth: 3, color, dashSize: 0.5, gapSize: 0.5})
|
|
|
|
else mat = new J3.LineBasicMaterial {linewidth:3, color}
|
|
|
|
geom.vertices.push(new J3.Vector3(0,0,0))
|
|
|
|
geom.vertices.push to.clone()
|
|
|
|
axis = new J3.Line geom, mat, J3.LineSegments
|
|
|
|
axis.computeLineDistances()
|
|
|
|
axis
|
|
|
|
|
|
|
|
axes = (length) ->
|
|
|
|
ax = new J3.Object3D()
|
|
|
|
dirs = [ new J3.Vector3(length, 0, 0),
|
|
|
|
new J3.Vector3(0, length, 0),
|
|
|
|
new J3.Vector3(0, 0, length) ]
|
|
|
|
cols = [ 0xFF0000, 0x00FF00, 0x0000FF ]
|
|
|
|
for i in [0, 1, 2]
|
|
|
|
ax.add buildAxis dirs[i], cols[i], LTx.plain
|
|
|
|
dirs[i].multiplyScalar(-1)
|
|
|
|
ax.add buildAxis dirs[i], cols[i], LTx.dashed
|
|
|
|
ax
|
|
|
|
|
2019-12-11 17:07:43 +00:00
|
|
|
main = ->
|
2019-12-09 04:22:52 +00:00
|
|
|
renderer = new J3.WebGLRenderer()
|
|
|
|
rwd = window.innerWidth
|
|
|
|
rht = window.innerHeight
|
2019-12-11 17:07:43 +00:00
|
|
|
renderer.setSize rwd, rht
|
2019-12-12 07:44:33 +00:00
|
|
|
renderer.setClearColor 0xeeeeee, 1.0
|
2019-12-09 04:22:52 +00:00
|
|
|
document.body.appendChild renderer.domElement
|
2019-11-24 18:15:44 +00:00
|
|
|
|
2019-12-09 04:22:52 +00:00
|
|
|
scene = new J3.Scene()
|
2019-12-11 17:07:43 +00:00
|
|
|
geometry = new J3.SphereBufferGeometry 1,5,5
|
2019-12-09 17:08:05 +00:00
|
|
|
material = new J3.MeshBasicMaterial {color: 0xff00ff}
|
2019-12-11 17:07:43 +00:00
|
|
|
ball = new J3.Mesh geometry, material
|
2019-12-09 04:22:52 +00:00
|
|
|
scene.add ball
|
2019-12-12 07:44:33 +00:00
|
|
|
scene.add axes 10
|
2019-11-24 18:15:44 +00:00
|
|
|
|
2019-12-11 17:07:43 +00:00
|
|
|
camera = new J3.PerspectiveCamera 75, rwd/rht, 0.1, 1000
|
2019-12-09 04:22:52 +00:00
|
|
|
camera.position.z = 5
|
2019-11-24 18:15:44 +00:00
|
|
|
|
2019-12-11 17:07:43 +00:00
|
|
|
renderer.render scene, camera
|
2019-11-24 18:15:44 +00:00
|
|
|
|
2019-12-11 17:07:43 +00:00
|
|
|
threeLoaded.then main
|
2019-11-24 18:15:44 +00:00
|
|
|
```
|