I have it sorta working, but it only selects 1 object at the same time, without regards to switching to the correct selected / unselected color, or multi-object movement.
Please forgive me if I did not explain good enough. If you ask me, however, I will try to go into as much detail in it as possible.
So anyway, this code uses the MP3D (Alpha) plugin (the commands are mostly the same except for a few added ones and different parameters) as Purebasic.
Here's a link to the MP3D (Alpha) engine:
viewtopic.php?f=27&t=43601&hilit=MP3D
NOTE: If you wish to test anything to do with this plugin, you must go to "Compiler Options", and then in the blank box where it says: "Library Subsystem", type: "dx9" without the quotes.
And now without further delay, the code:
LevelEditor.pb:
Code: Select all
Structure MasterStructure
nwid.i
enid.i
msid.i
mtid.i
txid.i
mnme.s
xpos.f
ypos.f
zpos.f
xrot.f
yrot.f
zrot.f
xscl.f
yscl.f
zscl.f
EndStructure
Structure Entities Extends MasterStructure
EndStructure
Global max_structures = 1
Dim Entities.MasterStructure(max_structures)
Structure SelectedMasterStructure
nwid.i
enid.i
msid.i
mtid.i
txid.i
mnme.s
xpos.f
ypos.f
zpos.f
xrot.f
yrot.f
zrot.f
xscl.f
yscl.f
zscl.f
EndStructure
Structure SelectedEntities Extends SelectedMasterStructure
EndStructure
Global max_selected_structures = 9999999
Dim SelectedEntities.SelectedMasterStructure(max_selected_structures)
MP_Graphics3D(800, 600, 0, 2)
SetWindowTitle(0, "Multi-Pick Demo")
cam=MP_CreateCamera()
MP_CreateLight(1)
Max = 40
Global objcount
For n = 0 To Max
Entities.MasterStructure(0)\xpos = 10-Random(20)
Entities.MasterStructure(0)\ypos = 10-Random(20)
Entities.MasterStructure(0)\zpos = 24+Random(40)
Entities.MasterStructure(0)\enid = MP_CreateSphere(100)
MP_PositionEntity (Entities.MasterStructure(0)\enid, Entities.MasterStructure(0)\xpos, Entities.MasterStructure(0)\ypos, Entities.MasterStructure(0)\zpos)
MP_EntitySetColor(Entities.MasterStructure(0)\enid, RGBA(Random(255, 0), Random(255, 0), Random(255, 0), 255))
objcount+1
Next n
max_hex = 3
Dim Which_Hex(max_hex)
Which_Hex(0) = $FF
Which_Hex(1) = $FF
Which_Hex(2) = $00
Which_Hex(3) = $00
A1 = Which_Hex(0)
R1 = Which_Hex(1)
G1 = Which_Hex(2)
B1 = Which_Hex(3)
While Not MP_KeyDown(#PB_Key_Escape) And Not Quit
event = WindowEvent()
If event = #PB_Event_CloseWindow
Quit = 1
EndIf
If MP_MouseButtonDown(0)
If GetFocus_()=WindowID(0)
SelectedEntities.SelectedMasterStructure(0)\enid = MP_PickCamera (cam,WindowMouseX(0),WindowMouseY(0))
If SelectedEntities.SelectedMasterStructure(0)\enid
For i = 1 To MP_CountVertices(SelectedEntities.SelectedMasterStructure(0)\enid)
color = MP_VertexGetColor(SelectedEntities.SelectedMasterStructure(0)\enid, i)
MP_VertexSetColor(SelectedEntities.SelectedMasterStructure(0)\enid, i, MP_ARGB(A1, R1, G1, B1))
If i = MP_CountVertices(SelectedEntities.SelectedMasterStructure(0)\enid)
Break
EndIf
Next
If color = R1 & G1 & B1
mode = 1
EndIf
EndIf
EndIf
MP_DrawText (100,40, "Mesh "+Str(SelectedEntities.SelectedMasterStructure(0)\enid)+" selected",0)
MP_DrawText (100,60, "Mesh Count: "+Str(MeshCount),0)
EndIf
If mode = 1
If MP_KeyDown(#PB_Key_Up) Or MP_KeyDown(#PB_Key_W): MP_MoveEntity(SelectedEntities.SelectedMasterStructure(0)\enid, 0, 1, 0): EndIf
If MP_KeyDown(#PB_Key_Down) Or MP_KeyDown(#PB_Key_S): MP_MoveEntity(SelectedEntities.SelectedMasterStructure(0)\enid, 0, -1, 0): EndIf
EndIf
If MP_MouseButtonDown(1)
If GetFocus_()=WindowID(0)
SelectedEntities.SelectedMasterStructure(0)\enid = MP_PickCamera (cam,WindowMouseX(0),WindowMouseY(0))
If SelectedEntities.SelectedMasterStructure(0)\enid
MP_FreeEntity (SelectedEntities.SelectedMasterStructure(0)\enid)
EndIf
EndIf
EndIf
MP_RenderWorld()
MP_Flip ()
Wend