Coloring of entities not possible?

Everything related to 3D programming
MightyMAC
User
User
Posts: 42
Joined: Thu Apr 11, 2013 5:47 pm

Coloring of entities not possible?

Post by MightyMAC »

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?
User avatar
Comtois
Addict
Addict
Posts: 1429
Joined: Tue Aug 19, 2003 11:36 am
Location: Doubs - France

Re: Coloring of entities not possible?

Post by Comtois »

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
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/
IdeasVacuum
Always Here
Always Here
Posts: 6425
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: Coloring of entities not possible?

Post by IdeasVacuum »

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.
User avatar
Samuel
Enthusiast
Enthusiast
Posts: 755
Joined: Sun Jul 29, 2012 10:33 pm
Location: United States

Re: Coloring of entities not possible?

Post by Samuel »

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: Select all

;#####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
MightyMAC
User
User
Posts: 42
Joined: Thu Apr 11, 2013 5:47 pm

Re: Coloring of entities not possible?

Post by MightyMAC »

@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?
User avatar
Comtois
Addict
Addict
Posts: 1429
Joined: Tue Aug 19, 2003 11:36 am
Location: Doubs - France

Re: Coloring of entities not possible?

Post by Comtois »

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/
troy
User
User
Posts: 51
Joined: Sat May 31, 2003 2:59 pm

Re: Coloring of entities not possible?

Post by troy »

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
Post Reply