-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscene3dElement.sj
73 lines (61 loc) · 1.73 KB
/
scene3dElement.sj
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
light(
pos : vec3(1.0f, 1.0f, 1.0f)
diffuseColor : color(0.5f, 0.5f, 0.0f, 1.0f)
specColor : color(1.0f, 1.0f, 1.0f, 1.0f)
) { this }
model_hasAlpha(m : '#model) {
m.hasAlpha
}
scene3dElement #element (
children : array!heap #model()
camera := vec3(0.0f, 0.0f, -5.0f)
lookAt := vec3(0.0f, 0.0f, 0.0f)
up := vec3(0.0f, 1.0f, 0.0f)
fieldOfView := 90.0f
zNear := 1.0f
zFar := 100.0f
light := light()
projection := mat4()
view := mat4()
world := mat4_identity()
_rect := rect()
getSize(maxSize : 'size) {
size(maxSize.w, maxSize.h)
}
getRect()'rect { _rect }
setRect(rect_ : 'rect)'void {
if _rect != rect_ {
_rect = rect_
projection = mat4_perspective(fieldOfView, _rect.h as f32 / _rect.w as f32, zNear, zFar)
view = mat4_lookAtLH(camera, lookAt, up)
}
void
}
render(scene : 'scene2d)'void {
for i : 0 to children.count {
child : children[i]
child.update(_rect, projection, view, world, light)
}
glEnable(glFeature.GL_DEPTH_TEST)
glPushViewport(_rect, scene.windowRect)
a : list!heap #model()
for i : 0 to children.count {
child : children[i]
child.renderOrQueue(a)
}
a.sortcb(model_zsort)
for i : 0 toReverse a.count {
child : a[i]
child.render()
}
glPopViewport(_rect, scene.windowRect)
glDisable(glFeature.GL_DEPTH_TEST)
}
fireMouseEvent(mouseEvent : 'mouseEvent)'bool {
for i : 0 to children.count {
child : children[i]
child.fireMouseEvent(mouseEvent)
}
true
}
) { this }