[Editor] Paste object on click place

101 views
Skip to first unread message

Владимир Побединский

unread,
Nov 16, 2013, 4:25:47 AM11/16/13
to urh...@googlegroups.com
May be good idea to realize this: We copy object from scene (as Edit - Copy) and select Edit - Click to paste and where we are clicked - there object will be pasted. May be normal aligned.

Paweł Mogiła

unread,
Nov 16, 2013, 11:46:25 AM11/16/13
to urh...@googlegroups.com
Very good idea, I wanted to implement that but unfortunately Urho raycast doesn't return hit normal vector. This could be great way for rapid spawn of environment objects like bushes, or trees.

Lasse Öörni

unread,
Nov 16, 2013, 1:58:34 PM11/16/13
to urh...@googlegroups.com
Calculating normal from the mesh triangle that was hit should be doable. I think that is even what is preferable (instead of a smoothed normal.)

Владимир Побединский

unread,
Nov 17, 2013, 12:31:49 AM11/17/13
to urh...@googlegroups.com
Paweł Mogiła написал:
Very good idea, I wanted to implement that but unfortunately Urho raycast doesn't return hit normal vector. This could be great way for rapid spawn of environment objects like bushes, or trees.

If node contain CollisionShape, PhysicsWorld::RaycastSingle can return normal in PhysicsRaycastResult.

Владимир Побединский

unread,
Nov 17, 2013, 2:58:06 AM11/17/13
to urh...@googlegroups.com
I change some editor behavior. Paste on mouse cursor position in 3D.

Add this to EditorView.as

Vector3 GetMouse3DPosition()
{  
   
IntVector2 pos = ui.cursorPosition;
   
Ray cameraRay = camera.GetScreenRay(float(pos.x) / graphics.width, float(pos.y) / graphics.height);
   
Vector3 res = cameraNode.position + cameraRay.direction * Vector3(0, 0, newNodeDistance);

   
if (ui.HasModalElement())
       
return res;

   
if (IsGizmoSelected())
       
return res;

   
if (editorScene.physicsWorld != null)
   
{
       
if (!runUpdate)
            editorScene
.physicsWorld.UpdateCollisions();

       
PhysicsRaycastResult result = editorScene.physicsWorld.RaycastSingle(cameraRay, camera.farClip);
       
       
if (result.body !is null)
            res
= result.position;
   
}
   
else
   
{
       
if (editorScene.octree is null)
           
return res;

       
RayQueryResult result = editorScene.octree.RaycastSingle(cameraRay, RAY_TRIANGLE, camera.farClip,
            pickModeDrawableFlags
[pickMode], 0x7fffffff);

       
if (result.drawable !is null)
             res
= cameraNode.position + cameraNode.worldRotation * Vector3(0, 0, result.distance);
   
}

   
return res;
}

Add this to EditorScene.as at line 492

newNode.position = GetMouse3DPosition();

I my scene with physics it work good. =)

Chris Friesen

unread,
Nov 17, 2013, 3:25:20 AM11/17/13
to urh...@googlegroups.com
I will try putting this in my resource browser work.  There is a drag n drop to create models/prefabs and this might essentially be better then what i have.

Raster Ron

unread,
Nov 21, 2013, 11:42:19 PM11/21/13
to urh...@googlegroups.com

Yes, this is nice code. Thanks for sharing.
Reply all
Reply to author
Forward
0 new messages