blob: dfe3f5e7564eaa0bbc126a77befe775e7ddeffd6 (
plain)
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
|
MX.Box = MX.Object3D.extend({
// this will be called within the contructor
init: function (size, color, borderColor) {
this.type = "Box"
size = size || 100
color = color || 'rgba(0, 255, 122, .1)'
borderColor = borderColor || '#0f3'
// an Object3D's associated DOM node is the "el" property
this.el.classList.add('box')
var angle = MX.rotationUnit === 'deg' ? 90 : (Math.PI / 2)
var top = this.top = new MX.Object3D('.face')
top.rotationX = angle
top.y = size / 2
var bottom = this.bottom = new MX.Object3D('.face')
bottom.rotationX = -angle
bottom.y = -size / 2
var left = this.left = new MX.Object3D('.face')
left.rotationY = -angle
left.x = -size / 2
var right = this.right = new MX.Object3D('.face')
right.rotationY = angle
right.x = size / 2
var front = this.front = new MX.Object3D('.face')
front.z = -size / 2
var back = this.back = new MX.Object3D('.face')
back.rotationY = angle * 2
back.z = size / 2
// adding children, must also be instances of Object3D
this.add(top, bottom, left, right, front, back)
this.children.forEach(function (face) {
face.width = size - 2
face.height = size - 2
face.el.style.backgroundColor = color
face.el.style.border = '1px solid ' + borderColor
})
// this applies the updated CSS style
// required for any change to take effect
// when a parent object's update() is called
// all its children will be updated as well
this.update()
// if this object's children won't move by themselves
this.updateChildren = false
}
// other properties will be mixed into the prototype of the new constructor
})
|