From c3d70b4c7682356a34f10308373a4fb598be9c6f Mon Sep 17 00:00:00 2001 From: leo Date: Mon, 23 May 2022 21:22:46 +0200 Subject: [PATCH] README --- README.md | 33 ++++++++++++++++++--- blender_import.py | 74 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 103 insertions(+), 4 deletions(-) create mode 100644 blender_import.py diff --git a/README.md b/README.md index 80e0ee2..f2f010b 100644 --- a/README.md +++ b/README.md @@ -1,16 +1,41 @@ # Intelligent Roundabout Efficient Simulation of Traffic Evolution ![Banner](banner.jpg) -## Installation : - +## Installation : \ ``` git clone https://gitlab.univ-nantes.fr/E208835U/Traffic.git pip install sumolib pip install pyside6 (optionnel pour l'ui) ``` -## Usage : - +## Usage : \ ``` python main.py ``` + +Le programme utilise les fichier .net.xml et .rou.xml générés par [Eclipse SUMo](https://www.eclipse.org/sumo/) + +File>Open>Open Network (pour un ficher *.net.xml)\ +File>Open>Open Vehicles (pour le fichier *.rou.xml associé) + +gamma/delta/T : variables de comportement\ +dt : pas de temps de la simulation\ +fps : vitesse de l'affichage (i/s), delai entre chaque maj de l'affichage (ms)\ +Physics fps : vitesse de la simulation (u/s), delai entre chaque maj de la simulation (ms)\ +Start/Stop : arrêter/redémarrer la simulation\ + + +Raccourcis clavier : \ +``` +Esc/Q : quitter +G : démarrer la simulation +E : Met le delai de maj de la simulation à 0 (vitesse maximum) +D : Met le delai de maj de la simulation à 17 (vitesse normale) +F : Met le delai de maj de la simulation à 500 (vitesse ralentie) +C : Met le pas de simulation à 0.3s (accéléré, au dépent de la qualité) +P : Met le pas de simulation à 1/60 (valeur par défaut) +0-9 : Charge les réseaux prédéfinis +``` + +## Interface python +La simulation peut aussi être executée sans interface (voir [runAllNetworks.py](runAllNetxorks.py) et [blender_import.py](blender_import.py) pour des exemples) diff --git a/blender_import.py b/blender_import.py new file mode 100644 index 0000000..e0d0ace --- /dev/null +++ b/blender_import.py @@ -0,0 +1,74 @@ +import sys, os, bpy, math +from random import randint +directory = os.path.dirname(bpy.data.filepath) +path = "./Traffic" # path to projects files +sys.path.append(path) + +from CarController import CarController +from Map import Map + +m = Map() +cc = CarController(m) + +m.fromPath(path+"/rdpt_polytech_fixed.net.xml") +cc.fromPath(path+"/rdpt_polytech_burst_moy.rou.xml") +cc.prepareRoute() + +def createLane(pts): + crv = bpy.data.curves.new("crv", "CURVE") + crv.dimensions = "3D" + spline = crv.splines.new(type = "POLY") + spline.points.add(len(pts)-1) + for p, np in zip(spline.points, pts): + p.co = list(np) + [0,1] + p.tilt = math.pi/2 + spline.use_endpoint_u = True + crv.extrude = 1 + #crv.bevel_depth = 2 + obj = bpy.data.objects.new("test_curve", crv) + return obj + +def createNet(): + netCollection = bpy.data.collections.new("gen_net") + bpy.context.collection.children.link(netCollection) + for edge in m.net.getEdges(): + for lane in edge.getLanes(): + obj = createLane(lane.getShape()) + netCollection.objects.link(obj) + +coll_names = ["gen_cars","gen_net"] +coll_names = filter(lambda n: n in bpy.data.collections ,coll_names) +gen_coll = [bpy.data.collections[n] for n in coll_names] +print(gen_coll) +bpy.ops.object.delete({"selected_objects": gen_coll}) + +createNet() +ref_car = bpy.data.objects["Car.001"] +carsCollection = bpy.data.collections.new("gen_cars") +bpy.context.collection.children.link(carsCollection) +cars = {} + +for i in range (0,6000): + cc.update() + + bpy.context.scene.frame_set(round(cc.t*96)) + + for ind,car in enumerate(cc.cars): + obj_id = car.id#f"Car.{ind:03d}" + carObj = None + if obj_id in cars: + carObj = cars[obj_id] + else: + randCarInd = randint(1,17) + refCar = bpy.data.objects[f"Car.{randCarInd:03d}"] + carObj = refCar.copy() + carObj.name = obj_id + print(carObj.name, obj_id) + carObj.data = refCar.data.copy() + carObj.animation_data_clear() + carsCollection.objects.link(carObj) + cars[obj_id] = carObj + carObj.location = car.pos + [0] + carObj.rotation_euler = (0,0,car.dir) + carObj.keyframe_insert(data_path = "location") + carObj.keyframe_insert(data_path = "rotation_euler")