Three.js - how to detect what shape was selected? after drag

前端 未结 1 1154
礼貌的吻别
礼貌的吻别 2020-12-06 03:37

I made a canvas with shapes in it...the shapes are draggable. Everything seems to work fine...But now I\'m trying to figure out how can I detect what shape was selected/drag

相关标签:
1条回答
  • 2020-12-06 04:05

    I found pretty simple solution...but I guess that's the way it always works :-) All you have to do for the detection is 2 things: First of all add another variable: var thisObject; After that you have to go to the onMouseDown() function. Right after the SELECTED = intersects[0].object; you have to write this thing:

     for(var i=0; i<objects.length; i++)
        { 
           if(SELECTED.position.x == objects[i].position.x)
                  thisObject = i; 
        }
    

    ...Now thisObject holds the index of the current shape (that was selected/dragged) in objects array...yeah that simple :-)

    0 讨论(0)
提交回复
热议问题