Child of #630.
Allow adding and moving static meshes to the scene. We need to expose the available items as blueprints in the API so the user can spawn them as actors.
+1
This is a much needed feature that I currently need for my research. It would be great if it would be possible to generate different scene's programmatically with some small changes between these scene's. Certainly looking forward for 0.9.1!
I've currently been working on this myself. I got it to work which can be found here https://github.com/ThierryDeruyttere/carla-simulator-mac . With an explanation of how to spawn new meshes here: https://github.com/ThierryDeruyttere/carla-simulator-mac/blob/master/Docs/spawning_meshes.md.
The way I have done it is by adding a new factory that creates MacchinaMapGenerators (Our project is called Macchina hence the name, but this is in fact just a copy from the ACityMapGenerator class with some small changes). I then created a MeshHolder actor in LibCarla with a function "set_scene" that can be used in python to set a certain scene. This "set_scene" function accepts a json dict in a string of the form {"map": [{"obj": objNr, "x", xcoord, "y": ycoord", "angle": angle}, ...] }. This way you can add multiple objects in one go. The objects are then added by the MacchinaMapGenerator class. A couple of example scene's i've been able to generate can be seen below



Spawning objects by using python is then as follows:
import sys
import os
import math
sys.path.append(
'PythonAPI/dist/carla-0.9.0-py2.7-macosx-10.13-intel.egg')
from macchina.macchina import Macchina
from macchina.meshtag import MeshTag
from carla import *
client = Client("localhost", 2000)
world = client.get_world()
spectator = world.get_spectator()
HALF_PI = math.pi/2
PI = math.pi
# x,y,z and angle are the position and angle of the spawning point in the world
macchina = Macchina(client, x=0, y=0, z=2, angle=0)
# Spawn a roadpart
x=0
y=0
macchina.addObject(MeshTag.RoadTwoLanes_LaneLeft, x, y, HALF_PI)
# Spawn the things
macchina.spawn()
# Set camera to see the things you've spawned
LOC = Location(x=-2, y=-4, z=3)
transform = Transform(LOC, Rotation(yaw=90))
spectator.set_transform(transform)
the macchina class is as follows:
import json
import sys
from carla import *
class Macchina:
def __init__(self, client, x, y, z, angle=0):
self.scene = {"map": []}
self.client = client
# Spawn generator
world = client.get_world()
bp = world.get_blueprint_library()
msh = bp.find("meshholder.mesh")
msh_loc = Location(x=x, y=y, z=z)
transform = Transform(msh_loc, Rotation(yaw=angle))
self.generator = world.spawn_actor(msh, transform)
def addObject(self, objectTag, x, y, angle=0):
self.scene["map"].append({"obj": int(objectTag), "x": x, "y": y, "angle": angle})
def spawn(self):
self.generator.set_scene(json.dumps(self.scene))
I don't know if this was how you guys had it in mind so that's why I'm not creating a pull request but if anyone needs to add scene while waiting on 0.9.1 you could use my code.
My current problem is that I can't seem to get semantic maps of the objects that are spawned which I'm still working on.
Unfortunately we'll have to delay this to 0.9.2, sorry about that.
Hi,
This is relatively an old post. So I am wondering if there is a built in function in carla 0.9.9 that allows one to add their own static objects from fbx files and then spawn it using python. I couldn't find anything in the docs. Please direct me if there is something similar that exists in carla 0.9.9.
Thanks
Most helpful comment
Hi,
This is relatively an old post. So I am wondering if there is a built in function in carla 0.9.9 that allows one to add their own static objects from fbx files and then spawn it using python. I couldn't find anything in the docs. Please direct me if there is something similar that exists in carla 0.9.9.
Thanks