It is currently Tue Sep 25, 2018 6:02 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 7 posts ] 
Author Message
 Post subject: Coloring of entities not possible?
PostPosted: Thu Apr 11, 2013 6:08 pm 
Offline
User
User

Joined: Thu Apr 11, 2013 5:47 pm
Posts: 36
Hey guys,

I'm working on some kind of 3D editor and I want to mark the selected entity with a red coloration. I worked with other 3D engines in the past and the usual way to do this was using something like ColorEntity(Entity, Color) but there seems to be no similar way to do this with PB-Ogre.

After studying the manual I thought I could achieve this by using GetEntityMaterial() to read out the material of the entity and then SetMaterialColor() to change its color, but GetEntityMaterial() returns a MaterialID wich is not usable with SetMaterialColor(). Going that way would have had the problem that several entites that have the same material would have been colored, too. And even if I would add an additional MaterialLayer with a red texture on it, it would show the same behaviour.

Does anybody know how to achive something like this in PB-Ogre? Or does anyone have an alternative idea how to mark a selected entity in a 3D editor app?

Thanks in advance
MAC

PS: The same thing with making an entity transparent after creation. Other engines use something like EntityAlpha(Entity, Alpha) for making entities transparent. In PB-Ogre it seems you have to alter the material to get something like this wich brings the same problems as mentioned above, or is there another way to do it?


Top
 Profile  
Reply with quote  
 Post subject: Re: Coloring of entities not possible?
PostPosted: Thu Apr 11, 2013 10:04 pm 
Offline
Addict
Addict
User avatar

Joined: Tue Aug 19, 2003 11:36 am
Posts: 1400
Location: Doubs - France
MightyMAC wrote:
Or does anyone have an alternative idea how to mark a selected entity in a 3D editor app?


May be with EntityBoundingBox() ? Look at EntityBoundingBox.pb example
You can also create a Red transparent entity and place it in the position of the selected entity

Quote:
PS: The same thing with making an entity transparent after creation.


Look at MaterialTransparent.pb example (This is not really what you are looking for, because this solution affects the material)

_________________
Please correct my english
http://purebasic.developpez.com/


Top
 Profile  
Reply with quote  
 Post subject: Re: Coloring of entities not possible?
PostPosted: Fri Apr 12, 2013 1:46 am 
Offline
Always Here
Always Here

Joined: Fri Oct 23, 2009 2:33 am
Posts: 5779
Location: Wales, UK
You can define a material to be specifically for a specific entity - in the script essentially the same material can be defined several times, perhaps matching the material name to an entity name/ID. So then a change to an individual object will not affect other objects.

_________________
IdeasVacuum
If it sounds simple, you have not grasped the complexity.


Top
 Profile  
Reply with quote  
 Post subject: Re: Coloring of entities not possible?
PostPosted: Fri Apr 12, 2013 6:18 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Sun Jul 29, 2012 10:33 pm
Posts: 721
Location: United States
As IdeasVacuum said your going to have to set a new material for each entity. In order to change the color without it affecting the others.
Same goes for alpha.
It sounds like you already know how to change the material, but I'll give you my example of changing material colors and alpha just in case.


Code:
;#####Press ESCAPE to Exit#####
#CameraSpeed = 3
V=1
VA=1
R=255
A=50
Define.f MouseX, MouseY, KeyX, KeyY
  ExamineDesktops()
  InitEngine3D()
  InitSprite()
  InitKeyboard()
  InitMouse()

W=DesktopWidth(0)
H=DesktopHeight(0)
If OpenWindow(0, 0, 0, W, H, "Material Effects", #PB_Window_MinimizeGadget | #PB_Window_ScreenCentered)
  OpenWindowedScreen(WindowID(0), 0, 0, W, H, 0, 0, 0)
 
  ;##Texture For Floor##
      CreateTexture(0,16,16)
      StartDrawing(TextureOutput(0))
      Box(0, 0, 16, 16, RGB(120, 120, 120))
      StopDrawing()
      CreateMaterial(0, TextureID(0))
  ;##Texture For Sphere##
      CreateTexture(1,16,16)
      StartDrawing(TextureOutput(1))
      Box(0, 0, 16, 16, RGB(255, 0, 0))
      StopDrawing()
      CreateMaterial(1, TextureID(1))
  ;##Transparent Texture For Cube##
      CreateTexture(2, 16, 16)
      StartDrawing(TextureOutput(2))
      DrawingMode(#PB_2DDrawing_AllChannels | #PB_2DDrawing_AlphaBlend)
      Box(0, 0, 16, 16, RGBA(0, 0, 255, 100))
      StopDrawing()
      CreateMaterial(2, TextureID(2))
      MaterialBlendingMode(2, #PB_Material_AlphaBlend)
     
      CreatePlane(0, 3000, 3000, 100, 100, 100, 100)
      CreateEntity(0, MeshID(0), MaterialID(0), 0, -200, 0)
      CreateSphere(1,50)
      CreateEntity(1, MeshID(1), MaterialID(1), -100, 0, 0)
      CreateCube(2,100)
      CreateEntity(2, MeshID(2), MaterialID(2), 100, 0, 0)
     
    CreateLight(1, RGB(155,155, 155), 0, 500 , 0)
    CreateCamera(0, 0, 0, 100, 100)
    MoveCamera(0, 0, 50, 350)
    CameraLookAt(0,0,0,0)
    CameraBackColor(0,RGB(0,0,0))
   
    Repeat

      If ExamineMouse()
        MouseX = -MouseDeltaX() * #CameraSpeed * 0.05
        MouseY = -MouseDeltaY() * #CameraSpeed * 0.05
      EndIf
      If ExamineKeyboard()
       
        If KeyboardPushed(#PB_Key_Left)
          KeyX = -#CameraSpeed
        ElseIf KeyboardPushed(#PB_Key_Right)
          KeyX = #CameraSpeed
        Else
          KeyX = 0
        EndIf
       
        If KeyboardPushed(#PB_Key_Up)
          KeyY = -#CameraSpeed
        ElseIf KeyboardPushed(#PB_Key_Down)
          KeyY = #CameraSpeed
        Else
          KeyY = 0
        EndIf   
       
      EndIf
     
   ;##Edit the Spheres Color##
      If R>254
        V=-1
      ElseIf R<1
        V=1
      EndIf
      R=R+V
      StartDrawing(TextureOutput(1))
      Box(0, 0, 16, 16, RGB(R, 0, 0))
      StopDrawing()
      CreateMaterial(1, TextureID(1))
      SetMeshMaterial(1, MaterialID(1))

   ;##Edit the Cubes Transparency##
      If A>254
        VA=-1
      ElseIf A<1
        VA=1
      EndIf
      A=A+VA
      StartDrawing(TextureOutput(2))
      DrawingMode(#PB_2DDrawing_AllChannels | #PB_2DDrawing_AlphaBlend)
      Box(0, 0, 16, 16, RGBA(0, 0, 255, A))
      StopDrawing()
      CreateMaterial(2, TextureID(2))
      SetMeshMaterial(2, MaterialID(2))
     
      RotateCamera(0, MouseY, MouseX, 0, #PB_Relative)
      MoveCamera  (0, KeyX, 0, KeyY)
      RenderWorld()
      FlipBuffers()
    Until KeyboardPushed(#PB_Key_Escape)

Else
  MessageRequester("Error", "The 3D Engine can't be initialized",0)
EndIf

End


Top
 Profile  
Reply with quote  
 Post subject: Re: Coloring of entities not possible?
PostPosted: Fri Apr 12, 2013 10:00 pm 
Offline
User
User

Joined: Thu Apr 11, 2013 5:47 pm
Posts: 36
@Samuel:
This would all be nice despite the fact that the materials of the entities will mostly be in material scripts in practice. And the main problem is that you can't manipulate a material of which you only have a MaterialID. It would be cool if the material commands like SetMaterialColor() or CopyMaterial() would work with MaterialIDs instead of material numbers. Then you could read out the material of an entity, copy it (to not influence entities that share the same material with the entity that was selected), color it and lay the new material on to the selected mesh. As far as I can see this would work in Ogre in other languages, but PB has this seperation of MaterialID and material number which makes this impossible.

As a first solution I will do what Comtois mentioned: Read out the bounding box coordinates of the selected mesh and position a box there with a red, transparent material attached to it.

@Comtois:
Do you think it would be possible in a future release of PB to have material commands work with MaterialIDs instead of the material numbers to have better manipulation possibilities for materials that come out of material scripts instead of being created within PB itself?


Top
 Profile  
Reply with quote  
 Post subject: Re: Coloring of entities not possible?
PostPosted: Tue Apr 16, 2013 11:36 am 
Offline
Addict
Addict
User avatar

Joined: Tue Aug 19, 2003 11:36 am
Posts: 1400
Location: Doubs - France
MightyMAC wrote:
@Comtois:
Do you think it would be possible in a future release of PB to have material commands work with MaterialIDs instead of the material numbers to have better manipulation possibilities for materials that come out of material scripts instead of being created within PB itself?


No, you will still need a PB number. I will change the function this way

GetEntityMaterial(#Material, entityID)

_________________
Please correct my english
http://purebasic.developpez.com/


Top
 Profile  
Reply with quote  
 Post subject: Re: Coloring of entities not possible?
PostPosted: Wed Dec 13, 2017 11:38 am 
Offline
User
User

Joined: Sat May 31, 2003 2:59 pm
Posts: 49
EntityMaterial approach works, but it is far from perfect solution. Imagine, you have hundreds of entities on the scene, each has its own material. It would be a headache to manage their transparency with EntityMaterial. Let's vote for EntityAlpha()! :wink:

_________________
--
troy


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye