/
main.py
133 lines (105 loc) · 4.31 KB
/
main.py
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
import bpy
import sys
from mathutils import Vector
#from ..nodes import main
from .. icon_load import cicon
from . import agents
from . import position
from . import ground
class ShowPositionGraphics(bpy.types.Operator):
"""Show the positional graphics"""
bl_idname = "scene.cm_show_position_graphics"
bl_label = "Show Diagram"
bl_options = {'REGISTER', 'UNDO'}
def execute(self, context):
print("Showing the graphics!")
return {'FINISHED'}
class RunSimulation(bpy.types.Operator):
"""Run CrowdMaster simulation"""
bl_idname = "scene.cm_run_simulation"
bl_label = "Run Simulation"
bl_options = {'REGISTER', 'UNDO'}
def execute(self, context):
scene = context.scene
groupObjs = bpy.data.groups[scene.agentGroup].objects
halfAgents = scene.agentNumber // 2
for object in groupObjs:
if scene.groundObject == object.name:
self.report({'ERROR'}, "The ground object must not be in the same group as the agent!")
bpy.context.scene.objects.active.select = False
if scene.positionType == "formation":
if scene.formationPositionType == "array":
for a in range(halfAgents):
obj1 = bpy.data.objects[groupObjs[1].name]
ground = bpy.data.objects[scene.groundObject]
offset_x = (obj1.dimensions.x + scene.formationArrayX)
obj1.select = True
obj1 = obj1.copy()
if scene.positionMode == "vector":
location = Vector((scene.positionVector[0], scene.positionVector[1], ground.location.z))
elif scene.positionMode == "object":
objStart = bpy.data.objects[scene.positionObject]
location = Vector((objStart.location.x, objStart.location.y, ground.location.z))
obj1.location = location
scene.objects.link(obj1)
location.x -= offset_x
return {'FINISHED'}
class CrowdMasterUIMain(bpy.types.Panel):
bl_space_type = "VIEW_3D"
bl_region_type = "TOOLS"
bl_context = "objectmode"
bl_category = "CrowdMaster"
bl_label = "Main"
def draw(self, context):
layout = self.layout
scene = context.scene
row = layout.row()
row.prop_search(scene, "agentGroup", bpy.data, "groups")
row = layout.row()
row.prop_search(scene, "groundObject", scene, "objects")
row = layout.row()
row.prop(scene, "agentNumber")
row = layout.row()
row.scale_y = 1.2
if (scene.agentGroup == "") or (scene.groundObject == ""):
row.enabled = False
row.operator("scene.cm_run_simulation", icon_value=cicon('run_sim'))
class CrowdMasterUIPosition(bpy.types.Panel):
bl_space_type = "VIEW_3D"
bl_region_type = "TOOLS"
bl_context = "objectmode"
bl_category = "CrowdMaster"
bl_label = "Position"
@classmethod
def poll(self, context):
try:
scene = context.scene
return (scene.agentGroup)
except (AttributeError, KeyError, TypeError):
return False
def draw(self, context):
layout = self.layout
scene = context.scene
row = layout.row()
row.prop(scene, "positionMode")
if scene.positionMode == "vector":
row = layout.row()
row.prop(scene, "positionVector")
elif scene.positionMode == "object":
row = layout.row()
row.prop_search(scene, "positionObject", scene, "objects")
row = layout.row()
row.separator()
row = layout.row()
row.prop(scene, "positionType")
if scene.positionType == "random":
row = layout.row()
row.prop(scene, "randomPositionRadius")
if scene.positionType == "formation":
row = layout.row()
row.prop(scene, "formationPositionType")
if scene.formationPositionType == "array":
row = layout.row()
row.prop(scene, "formationArrayX")
row = layout.row()
row.prop(scene, "formationArrayY")