select / multi select / deselect a triangle?
Blitz3D Forums/Blitz3D Programming/select / multi select / deselect a triangle?
| ||
Hi all. As I complete my program, I thought of 1 last minute thing I wanted to add. Can someone please show me an example of how to single select & multi select / deselect a triangle on an entity? Thank You so kindly! ~GF |
| ||
Can anyone please assist? Thank You! =) ~GF |
| ||
What i have done to do/manage multi selection, is that when ctrl is held, multi select is activated, then when the mouseleft is hit, a camerapick/linepick is done at the cursor position and the next picked thing becomes selected if its selectionstate was notselected and notselected if its selectionstate was selected. Then depending on each thing selectionstate, i update its appearance (color or alpha) |
| ||
Do you have an example or know where to find one of multi / single / de-selecting a triangle? Thank You so kindly! |
| ||
Perhaps it's a dumb idea, but if you are using a low poly mesh, you can separate each polygon into a new entity, then you can easily pick them. |
| ||
ok, confused with that, @chipson. how would you do this? Can you please show me? I am grateful! :) Thank You so kindly @chipson & @RemiD! :D |
| ||
Some people know how to get the polygon information of a mesh, but to be honest, I have no idea :/ But I don't know, maybe I'll try to do that. |
| ||
Any luck, @chipson? Thank you so kindly! ~GF |
| ||
Yeah, this is my idea, but I don't know if this was you where refering to. Select Triangles with Left Click and de-select them with Right Click. Graphics3D 1024, 768, 32, 2 SetBuffer BackBuffer() Type poly Field ent Field surf Field sel Field col[2] End Type cam = CreateCamera() PositionEntity cam, 0, 0, -3 light = CreateLight() PositionEntity light, 10, 10, 10 temp = CreatePivot(): PointEntity(light, temp): FreeEntity temp obj = CreateSphere(4) surf = GetSurface(obj, 1) For i = 0 To CountTriangles(surf) - 1 p.poly = New poly p\ent = CreateMesh() p\surf = CreateSurface(p\ent) p_v0_x# = VertexX(surf, TriangleVertex(surf, i, 0)) p_v0_y# = VertexY(surf, TriangleVertex(surf, i, 0)) p_v0_z# = VertexZ(surf, TriangleVertex(surf, i, 0)) p_v1_x# = VertexX(surf, TriangleVertex(surf, i, 1)) p_v1_y# = VertexY(surf, TriangleVertex(surf, i, 1)) p_v1_z# = VertexZ(surf, TriangleVertex(surf, i, 1)) p_v2_x# = VertexX(surf, TriangleVertex(surf, i, 2)) p_v2_y# = VertexY(surf, TriangleVertex(surf, i, 2)) p_v2_z# = VertexZ(surf, TriangleVertex(surf, i, 2)) p_v0_nx# = VertexNX(surf, TriangleVertex(surf, i, 0)) p_v0_ny# = VertexNY(surf, TriangleVertex(surf, i, 0)) p_v0_nz# = VertexNZ(surf, TriangleVertex(surf, i, 0)) p_v1_nx# = VertexNX(surf, TriangleVertex(surf, i, 1)) p_v1_ny# = VertexNY(surf, TriangleVertex(surf, i, 1)) p_v1_nz# = VertexNZ(surf, TriangleVertex(surf, i, 1)) p_v2_nx# = VertexNX(surf, TriangleVertex(surf, i, 2)) p_v2_ny# = VertexNY(surf, TriangleVertex(surf, i, 2)) p_v2_nz# = VertexNZ(surf, TriangleVertex(surf, i, 2)) p_v0 = AddVertex(p\surf, p_v0_x#, p_v0_y#, p_v0_z#) p_v1 = AddVertex(p\surf, p_v1_x#, p_v1_y#, p_v1_z#) p_v2 = AddVertex(p\surf, p_v2_x#, p_v2_y#, p_v2_z#) VertexNormal p\surf, p_v0, p_v0_nx#, p_v0_ny#, p_v0_nz# VertexNormal p\surf, p_v1, p_v1_nx#, p_v1_ny#, p_v1_nz# VertexNormal p\surf, p_v2, p_v2_nx#, p_v2_ny#, p_v2_nz# p_t0 = AddTriangle(p\surf, p_v0, p_v1, p_v2) p\col[0] = Rand(0, 255) p\col[1] = Rand(0, 255) p\col[2] = Rand(0, 255) EntityColor p\ent, p\col[0], p\col[1], p\col[2] EntityPickMode p\ent, 2 Next FreeEntity obj fpslock = CreateTimer(60) While Not KeyDown(1) mh1 = MouseHit(1) mh2 = MouseHit(2) CameraPick(cam, MouseX(), MouseY()) picked = PickedEntity() For p.poly = Each poly If mh1 = 1 Then If picked = p\ent Then p\sel = 1 EndIf If mh2 = 1 Then If picked = p\ent Then p\sel = 0 EndIf If p\sel = 1 Then EntityColor p\ent, 255, 0, 0 Else EntityColor p\ent, p\col[0], p\col[1], p\col[2] EndIf TurnEntity p\ent, 0, 0.1, 0 Next RenderWorld() Text 10, 10, "Picked: " + picked Flip Wend End I hope you find it useful. |
| ||
Hi, @Chipson. This is EXACTLY what I'm looking for! But it lacks 2 features. The ability to select and delete single / multiple triangles from the mesh, and the ability to "re-create" a triangle if the "deleted space" is clicked. Other than that, it's PERFECT! Thanks again, @Chipson! ~GF |
| ||
Ok, as I said, It's not the best method anyway xD But adding that feature you said is easy. Press Backspace or Del Key to "delete" the selected triangles and click on them again to make them reappear. Hope it helps! :) P.S.: my nickname is well written, "Chispon" is a spanish word that means something like "sparky" LOL Graphics3D 1024, 768, 32, 2 SetBuffer BackBuffer() Type poly Field ent Field surf Field sel Field hide Field col[2] End Type cam = CreateCamera() PositionEntity cam, 0, 0, -3 light = CreateLight() PositionEntity light, 10, 10, 10 temp = CreatePivot(): PointEntity(light, temp): FreeEntity temp obj = CreateSphere(4) surf = GetSurface(obj, 1) For i = 0 To CountTriangles(surf) - 1 p.poly = New poly p\ent = CreateMesh() p\surf = CreateSurface(p\ent) p_v0_x# = VertexX(surf, TriangleVertex(surf, i, 0)) p_v0_y# = VertexY(surf, TriangleVertex(surf, i, 0)) p_v0_z# = VertexZ(surf, TriangleVertex(surf, i, 0)) p_v1_x# = VertexX(surf, TriangleVertex(surf, i, 1)) p_v1_y# = VertexY(surf, TriangleVertex(surf, i, 1)) p_v1_z# = VertexZ(surf, TriangleVertex(surf, i, 1)) p_v2_x# = VertexX(surf, TriangleVertex(surf, i, 2)) p_v2_y# = VertexY(surf, TriangleVertex(surf, i, 2)) p_v2_z# = VertexZ(surf, TriangleVertex(surf, i, 2)) p_v0_nx# = VertexNX(surf, TriangleVertex(surf, i, 0)) p_v0_ny# = VertexNY(surf, TriangleVertex(surf, i, 0)) p_v0_nz# = VertexNZ(surf, TriangleVertex(surf, i, 0)) p_v1_nx# = VertexNX(surf, TriangleVertex(surf, i, 1)) p_v1_ny# = VertexNY(surf, TriangleVertex(surf, i, 1)) p_v1_nz# = VertexNZ(surf, TriangleVertex(surf, i, 1)) p_v2_nx# = VertexNX(surf, TriangleVertex(surf, i, 2)) p_v2_ny# = VertexNY(surf, TriangleVertex(surf, i, 2)) p_v2_nz# = VertexNZ(surf, TriangleVertex(surf, i, 2)) p_v0 = AddVertex(p\surf, p_v0_x#, p_v0_y#, p_v0_z#) p_v1 = AddVertex(p\surf, p_v1_x#, p_v1_y#, p_v1_z#) p_v2 = AddVertex(p\surf, p_v2_x#, p_v2_y#, p_v2_z#) VertexNormal p\surf, p_v0, p_v0_nx#, p_v0_ny#, p_v0_nz# VertexNormal p\surf, p_v1, p_v1_nx#, p_v1_ny#, p_v1_nz# VertexNormal p\surf, p_v2, p_v2_nx#, p_v2_ny#, p_v2_nz# p_t0 = AddTriangle(p\surf, p_v0, p_v1, p_v2) p\col[0] = Rand(0, 255) p\col[1] = Rand(0, 255) p\col[2] = Rand(0, 255) p\hide = 0 EntityColor p\ent, p\col[0], p\col[1], p\col[2] EntityPickMode p\ent, 2 Next FreeEntity obj fpslock = CreateTimer(60) While Not KeyDown(1) mh1 = MouseHit(1) mh2 = MouseHit(2) CameraPick(cam, MouseX(), MouseY()) picked = PickedEntity() For p.poly = Each poly If mh1 = 1 Then If picked = p\ent Then If p\hide = 1 Then p\sel = 0: p\hide = 0 Else p\sel = 1 EndIf EndIf EndIf If mh2 = 1 Then If picked = p\ent Then p\sel = 0 EndIf If KeyDown(211) Or KeyDown(14) Then If p\sel = 1 Then p\hide = 1: p\sel = 0 EndIf If p\sel = 1 Then EntityColor p\ent, 255, 0, 0 Else EntityColor p\ent, p\col[0], p\col[1], p\col[2] EndIf If p\hide = 1 Then EntityAlpha p\ent, 0 Else EntityAlpha p\ent, 1 TurnEntity p\ent, 0, 0.1, 0 Next RenderWorld() Text 10, 10, "Picked: " + picked Flip Wend End |
| ||
Hi, @Chispon! Sorry for the typo :P Anyway, is there a way to connect each triangle to each other so if we were to say "move" a selected triangle, the object would morph correctly? Thanks again! :) ~GF |
| ||
Oh, I don't know, I'm pretty sure that Blitz3D can perform mesh morphing, there should be some examples around there. |
| ||
It's not really "morphing-morphing", I'm after. It's to combine all triangles with each other. I also wanted to be able to actually delete the triangle instead of just hiding it, then make it so it creates a totally new triangle in it's place instead of setting the transparency back to opaque. Thanks again! ~GF |
| ||
Well, it's deleting finally, but for some reason, it waits until my mouse is over it and the triangles are all selected for some reason. It also needs the ability to recreate a triangle instantly onto the model. Thanks again, @Chispon! ~GF |
| ||
Well, my brain is burning, I have no idea on how to do that. I hope someone else have the solution. Good luck! |
| ||
I think sswift has an example in the code archives for ray intersect triangle. Should get you started. |
| ||
Thanks Matty. I recall seeing it, but I fgt. where it is. >< |