click on object
Blitz3D Forums/Blitz3D Beginners Area/click on object
| ||
I am sure there is a way to click on a mesh, but even looking through the forums, I havn't spotted one. Thanks Dicon |
| ||
Try CameraPick(Camera,MouseX(),MouseY()) |
| ||
The entity must be pickable as well. Look into EntityPickMode() as well as CameraPick(). |
| ||
Thanks all, will try that tomorrow. Dicon |
| ||
Well, it does work and the result is ( for the mesh) the number 25707784 which I cannot see how it can identify the mesh itself. I could set up an array to read it out, which would be clumbsy but the name of the mesh would be better. Dicon Making my own world game creator |
| ||
Do you know of the handle and object commands? Well, these commands allow you to jump straight to a type object, if you have the handle number. What you basically do is place this handle in the entityname() of the entity. The only other way you can do this, is to store the array number of the entity, in the entityname(). That way, you can get the pickedentity then: array(EntityName(PickedEntity()) is the entity your after. I use the type method, as i can store other information in the type fields, but it's really whatever is easiest for you! |
| ||
That number is the entity. I suppose it represents the memory address where the entity information is stored. try: cube = createcube() print cube You can use this number for instance like this: HideEntity PickedEntity() (PickedEntity returns which mesh was picked) |
| ||
I think he's wanting to jump straight to the entity, and the only real way to do that at speed is to store the information in the entityname(), as it's the only associated data with the entity that will hold this information, with actually affecting the entity in any way. |
| ||
This is where I am so far ............................... ( snipped for brevity ) item$="med_support_beam.b3d" My_Object=LoadMesh(item$) NameEntity My_Object,"beam" EntityPickMode My_Object,3 PositionEntity My_object, 30,ground_level#+h#,30 PointEntity camera,my_object If MouseDown(1) Then EntityName$=CameraPick ( camera,MouseX(),MouseY() ) Text 0,80," Object Picked is "+ EntityName$ which returns 25707784 I tried If MouseDown (1)Then Entitynames$=EntityPick ( camera,10 ) which doesn't work at all. I am making a "Game Maker" that needs for meshes to be loaded, then selected, then moved or scaled then saved as a "Scene" Any suggestions? Dicon |
| ||
You want to store all your meshes in an array to start (if your using arrays), then, go through each array slot and give each entity an entityname, using it's array slot.for loop = 0 to 20 ; 20 entities in the array nameentity entity_array(loop),loop next ... later on in code, when your doing your pick.... CameraPick camera,mousex(),mousey() array_slot = entityname(pickedentity()) entitycolor array(array_slot), 0,0,0 that will give you the array slot of the entity picked, and color it black. |
| ||
Have a study on this: I wrote this for Rez a few weeks ago. It does show you how to name an entity, and retrieve and display that name when clicked on. This is a fully functioning "shape editor" :) It allows the user to select, move, rotate each shape. This could easily be modified to use modeled meshes instead of primitive shapes. Pay particular attention to where the shapes are created, right before the main loop. That is where they are named and numbered. The function get_input() performs the camerapick and stores the name, coordinates, and rotation information for the function hud() to display. Important global variables are the global "entity" and "name$." The global "entity" actually holds Blitz's reference to that particular entity, which is that number you've seen before. (478328018) or similar. When you want to alter or move an entity later in the program, we check that variable "entity" (which is again the stored number) against all entities to find out which one is "selected". |
| ||
Use this:; Check if mouse is being clicked If MouseDown(1) Then ; Pick the entity where the mousepointer is (PickedEnt now contains the handle to the picked entity) PickedEnt = CameraPick(camera, MouseX(), MouseY()) ; Check if a valid entity has been picked If PickedEnt Then ; If the entity was valid (the user clicked on a pickable entity), grab the name of the entity EntName$ = EntityName$(PickedEnt) Else ; In case no valid entity was picked (open space or non-pickable entity), set EntName to nothing ("") EntName$ = "" EndIf EndIf ; Print the entity name Text 0,80," Object Picked is "+ EntName$ |
| ||
Can i ask how you are storing your entities? An array, or a Type list? |
| ||
Drak! That does look good. All I have to do now is to unpick the formula from your program and incorperate it into mine. Failing this I will have to hire a paid programmer to do the work for me as I am not going to use the program to write a game but to show off my grapics designs for game makers. I am NOT a programmer ( Gawd know I have tried ) but I have the designs and game plans and the graphics. But. Not the skill to programe. I have tried quite a few "Game Designers " ( no skill coding skill needed ) and there were bugs and flaws in them all. So... I will spend a few more days on this then get a pro to program for me. ( There must be a few out there that need the dosh. Dicon square eyed and flat bum. |
| ||
Drak...It works fine. I was so near, but not close enough. Tomorrow I will set up the arrays to hold the mesh type,name, x,y,z and rotation direction. Nice to see the name I have given them show up. I use Blender for the meshes and Ultimate unwrap for UV work, DPaint for graphics. I tried 3D World Studio and Silent Walk but they were too buggy, a shame really cause' 3D World Studio did export all the meshes and textures to B3D. So, that's why I am doing it for myself. With help from allthe folks here. Thanks. Dicon |
| ||
PowerPC603, I chose your system as the simplest. Like I said, I am a bad coder. Further up my program, the position,rotation and all the other variables are put into an array, along with the name$ with name_cntr being the variable pointer to each mesh array group. I have the name. now all I need is the way to load a new mesh and/or access a pre loaded one. I can save and load arrays and most other simple things but i seem to have reached an impasse. Thanks ;...........................................................Load Mesh ....................... Function load_mesh() item$="meshes\med_support_beam.b3d"; ;name of mesh chosen from menu My_Object=LoadMesh(item$) NameEntity My_Object,"med_support_beam"+Str$(name_cntr) ;name of mesh chosen from menu m_name$(name_cntr)="med_support_beam"; name of beam ScaleEntity my_object,x_scale#,y_scale#,z_scale# h#=MeshHeight(my_object)/2 EntityPickMode my_object,3 FlipMesh my_object PositionEntity my_object,5,5,5 ; starting position RotateEntity my_object ,0,0,180 ; make it face the Right way name_cntr=name_cntr+1 ; adds the number to the end of the name i.e. beam2 End Function ;......................................................... If any one can help it would be appreciated. Dicon |
| ||
The above has been tweaked and works ok. Thanks all. I guess that all I need to get further on with it is a way to change "my_object" which is the mesh "beam1" to become "beam2" which is another mesh, so's I can add more meshes to the terrain. Thanks Dicon |
| ||
Having arrived at an impasse' I need to find one thing. That clicking on a mesh from a selection of meshes, ( probably the pick command ) I can then move, rotate and change the "picked" entity. I have tried everything, de-constructing code from the forums and spent hours re-arranging what I have. Please help. Dicon I would go gray if I wasn't already! |
| ||
I've constructed a complete example that: - shows the name of the picked entity - shows the entity-handle of the picked entity - searches through types to find the entityhandle and show a value stored in this instance (so you can see that the correct type instance was found) - it also marks the recently picked entity red, while it unmarks all other entities white (using entitycolor), so you visually see that the correct entity was picked and can be used to modify it Graphics3D 800, 600, 0, 2 SetBuffer BackBuffer() SeedRnd MilliSecs() ; Setup type structure Type TObj Field Entity ; Holds the handle to an entity Field Value ; Holds a random value End Type ; Create 20 instances of the type "TObj" and create a cube for each instance For i = 1 To 20 ; Create a new TObj instance temp.TObj = New TObj ; Create a new cube entity and store the handle in the type instance temp\Entity = CreateCube() ; Position the cube at some random coordinates PositionEntity temp\Entity, Rnd#(-100.0, 100.0), Rnd#(-100.0, 100.0), Rnd#(-100.0, 100.0) ; Scale the cubes ScaleEntity temp\Entity, 5.0, 5.0, 5.0 ; Make the cube polygon-pickable EntityPickMode temp\Entity, 2 ; Set the entityname NameEntity temp\Entity, "Cube " + Str$(i) ; Finally add a number to the instance temp\Value = i * 1000 Next Global camera = CreateCamera() PositionEntity camera, 0, 0, -200 While Not KeyHit(1) Local PickedEnt, EntName$, EntityInstance.TObj ; Check if mouse is being clicked If MouseHit(1) Then ; Pick the entity where the mousepointer is (PickedEnt now contains the handle to the picked entity) PickedEnt = CameraPick(camera, MouseX(), MouseY()) ; Check if a valid entity has been picked If PickedEnt Then ; If the entity was valid (the user clicked on a pickable entity), grab the name of the entity EntName$ = EntityName$(PickedEnt) ; Find the type-instance where the entity belongs to EntityInstance.TObj = FindObject(PickedEnt) ; Mark the picked entity MarkObject(PickedEnt) Else ; In case no valid entity was picked (open space or non-pickable entity), set EntName to nothing ("") EntName$ = "" ; Also set the reference to a TObj instance to null (no instance) EntityInstance.TObj = Null ; Un-mark all entities MarkObject(0) EndIf EndIf RenderWorld ; Print the entity name Text 10, 10, "Object-name: " + EntName$ Text 10, 22, "Object-handle: " + PickedEnt If EntityInstance <> Null Then Text 10, 34, "Value of the object instance: " + EntityInstance\Value EndIf Flip Wend End ; This function finds the TObj type-instance where the stored entity-handle is the same as the Entity-handle provided as a parameter Function FindObject.TObj(Entity) ; Search through all TObj instances For temp.TObj = Each TObj ; When the given Entity-handle matches the entity-handle that was stored in the TObj instance, return the TObj instance If temp\entity = Entity Then Return temp Next End Function Function MarkObject(Entity) ; Search through all TObj instances For temp.TObj = Each TObj ; When the given Entity-handle matches the entity-handle that was stored in the TObj instance If temp\entity = Entity Then ; Color the picked entity red EntityColor temp\Entity, 255, 0, 0 Else ; Mark all other entities white (in case another entity was picked before, it would stay red if it isn't un-marked) EntityColor temp\Entity, 255, 255, 255 EndIf Next End Function |
| ||
Once you have the entity handle then you can keep a record of that as a Global variable, something like 'CurrentMesh' This way, you can then deal with the rotating and all by referring to the CurrentMesh. |
| ||
Thanks to you all for your help. I will now play with the code over the weekend. Thanks for the program PowerPC603. Dicon If I ( no.. when) I do get it finished I will put up some screen shots! Great |