Repository navigation
Expand file tree
/
Copy pathmodel.py
More file actions
88 lines (67 loc) · 2.52 KB
/
Copy pathmodel.py
File metadata and controls
88 lines (67 loc) · 2.52 KB
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
from abc import ABC, abstractmethod # Abstract Base Class
from OpenGL.GL import GL_STATIC_DRAW, GL_TRUE, glUniformMatrix4fv, glGetUniformLocation
import glfw
import grafica.basic_shapes as bs
import grafica.scene_graph as sg
import grafica.transformations as tr
import grafica.easy_shaders as es
import grafica.gpu_shape as gs
import random
count_cube = 0
def create_gpu(shape, pipeline):
gpu = es.GPUShape().initBuffers()
pipeline.setupVAO(gpu)
gpu.fillBuffers(shape.vertices, shape.indices, GL_STATIC_DRAW)
return gpu
class Cube(object):
def __init__(self, pipeline):
global count_cube
self.nodeNumber = count_cube
shape = bs.createColorNormalsCube(0.5,0.5,0.5) # WithNormal
gpuCube = create_gpu(shape, pipeline)
basic_cube = sg.SceneGraphNode('basic_cube')
basic_cube.childs += [gpuCube]
cube = sg.SceneGraphNode('cube_' + str(self.nodeNumber)) # the nodenumber will help to have a hierarchy
cube.childs += [basic_cube] # leaf can not have child nodes
self.model = cube
def clear(self):
self.model.clear()
class AllModel(object):
def __init__(self, cube):
# we start with a basic cube
self.model = cube.model #first_cube
def addRandomChild(self, pipeline, node_name):
"""
Add a random newCube to the node_name node
"""
global count_cube
count_cube += 1
node = sg.findNode(self.model, node_name)
if node == None:
print("No node founded to add child (addChild function)")
return
newCube = Cube(pipeline)
posy = random.uniform(-0.5,0.5)
posz = random.uniform(-0.5,0.5)
newCube.model.transform = tr.translate(0.3, posy, posz)
node.childs += [newCube.model]
def addChildV2(self, pipeline, node_name, newCube):
"""
Add newCube as a child node to node_name node
"""
global count_cube
count_cube += 1
node = sg.findNode(self.model, node_name)
if node == None:
print("No node founded to add child (addChild function)")
return
node.childs += [newCube.model]
def draw(self, pipeline, transform, node_name):
node = sg.findNode(self.model, node_name)
if node == None:
print("No node founded to add child (draw function)")
return
node.transform = transform
sg.drawSceneGraphNode(self.model, pipeline, "model")
def clear(self):
self.model.clear()