GetSurfaceBrush ( surface )
Parameters
| surface - surface handle |
Description
|
Returns a copy of a surface's brush - the material that one part of a mesh is drawn with. A mesh is made of surfaces, one per material, and each surface carries its own brush. GetSurfaceBrush reads one back, which is the key to inspecting a loaded model: loop the surfaces with CountSurfaces and GetSurface, grab each brush, and pull out its textures with GetBrushTexture and TextureName. It also pairs naturally with PaintSurface or PaintMesh to clone one model's material onto another, as the example does. Like GetEntityBrush, the returned brush is a COPY, not a live link. Editing it with BrushColor and friends changes nothing on screen until you paint it back onto a surface or mesh. Each call creates a brand new brush, so free it with FreeBrush when you are done with it - calls made every frame without a matching FreeBrush are a slow leak. See also: GetEntityBrush, GetBrushTexture, GetSurface, PaintSurface, FreeBrush. |
Example
; GetSurfaceBrush Example ; ----------------------- Graphics3D 640,480,0,2 SetBuffer BackBuffer() camera=CreateCamera() PositionEntity camera,0,1,-6 light=CreateLight() RotateEntity light,45,45,0 ; The donor sphere - its surface is painted with a coloured brush donor=CreateSphere() PositionEntity donor,-1.5,1,0 paint=CreateBrush(255,200,0) PaintSurface GetSurface(donor,1),paint ; The receiver sphere starts plain white receiver=CreateSphere() PositionEntity receiver,1.5,1,0 While Not KeyDown(1) ; 1/2/3 repaint the donor's surface with a new colour If KeyHit(2) BrushColor paint,255,200,0 PaintSurface GetSurface(donor,1),paint EndIf If KeyHit(3) BrushColor paint,0,220,120 PaintSurface GetSurface(donor,1),paint EndIf If KeyHit(4) BrushColor paint,180,80,255 PaintSurface GetSurface(donor,1),paint EndIf ; Space: read the donor surface's brush and give it to the receiver If KeyHit(57) surf=GetSurface(donor,1) brush=GetSurfaceBrush(surf) PaintMesh receiver,brush ; The returned brush is a copy - free it to avoid leaks FreeBrush brush EndIf TurnEntity donor,0,1,0 TurnEntity receiver,0,-1,0 ; Arrow keys move the camera If KeyDown(200) Then MoveEntity camera,0,0,0.1 If KeyDown(208) Then MoveEntity camera,0,0,-0.1 If KeyDown(203) Then TurnEntity camera,0,1,0 If KeyDown(205) Then TurnEntity camera,0,-1,0 RenderWorld Text 0,0,"1/2/3: repaint left sphere Space: copy its surface brush Esc: exit" Text 0,20,"brush=GetSurfaceBrush(surf) then PaintMesh receiver,brush" Flip Wend End
Index