View Full Version : 3D world editor

04-27-2012, 04:08 AM

Im creating a 3D world editor with Vizard. I want to add a model, place it and be able to replace the models. The user can navigate through the world with wasd and click a model and replace it. So far so good, but i'm experiencing some problems with the object placement.

This is the code for a model to follow the mouse-cursor:

# draw model on mouse position
line = viz.MainWindow.screenToWorld(viz.mouse.getPosition ())
x,y,z = line.endFromDistance(6)
y = 0

It works but it is still hard to navigate objects in the world. Is there a better way to let models follow the mouse and put them in the 3D world?


05-01-2012, 07:52 AM
You could try using a viztracker.MouseTracker. Here's a simple example:

import viz
import viztracker
import vizact

gallery = viz.addChild('gallery.osgb')
ball = viz.addChild('soccerball.osgb')

#Move the object with mouse movements and mousewheel
mousetracker = viztracker.MouseTracker()
link = viz.link(mousetracker,ball)

#Disable the link and place the object with a mousepress
vizact.onmousedown(viz.MOUSEBUTTON_LEFT, link.disable)


05-03-2012, 03:25 AM
Thanks for your reply. I implemented the mousetracker and it is working better. When the user clicks the mouse i put the model on x,y=0,z so that the model is placed on the ground. I tried to catch a mouse_move event and set the position of the model to the ground so that the user can't move the object in the air or through the ground.

def onMouseMove(self,e):
x,y,z = self.model.getPosition()

But this wont have any effect. Is it possible to adjust the mousetracker so that the models stick to the ground plane?

EDIT: I try to get some collision with the mousetracker model but I dont know how, can someone give me some hints? Thanks