Jump to content

Getting brushes' surface


shadmar
 Share

Recommended Posts

I was sure I had done this before, but I'm stuck.

 

This is my entity script attached to the brush:

 

 

        if self.entity:GetClassName()=="Brush" then
           tolua.cast(self.entity, "Model")
           System:Print(self.entity:GetClassName()) -- still says brush, so I cant get to surface
           System:Print(self.entity:CountSurfaces()) -- crashes, since it is still a brush
       end

  • Upvote 2

HP Omen - 16GB - i7 - Nvidia GTX 1060 6GB

Link to comment
Share on other sites

Agree... i thought this was possible before. The only way I have found that I can get a brush's material is if I perform a pick on the brush or if I just perform SetMaterial() on it (which seems silly to do then perform a GetMaterial())..

 

Casting the Brush to Model doesn't appear to work... but if the brush doesnt have mass or script, then it will be converted to the model class and the normal GetSurface/Material will work. You can perform a pick on a brush and get the material but that's alot of work for something like this.

 

Edit: yeah the pick only works if you just set the material via code... otherwise it doesn't work. hmmm.

 

The entity script I was testing this with (the camera is global in my main script):

function Script:Start()

if self.entity:GetMaterial()==nil then System:Print("material not found") end

local material = Material:Load("Materials/developer/bluegrid.mat")

self.entity:SetMaterial(material)

if self.entity:GetMaterial()~=nil then System:Print("material found") end

end

 

function Script:UpdateWorld()

local window = Window:GetCurrent()

if camera==nil then System:Print("no cam") end

if window:MouseHit(1) then

local pickinfo = PickInfo()

local p = window:GetMousePosition()

if (camera:Pick(p.x,p.y,pickinfo,0,true)) then

System:Print("Class: "..pickinfo.entity:GetClassName())

if pickinfo.entity:GetClassName()=="Brush" then

local bmat = pickinfo.entity:GetMaterial()

if bmat~=nil then System:Print("Brush mat found") end

end

if pickinfo.entity:GetClassName()=="Model" then

local mmat = pickinfo.surface:GetMaterial()

if mmat~=nil then System:Print("Model mat found") end

end

end

end

end

  • Upvote 2

Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590

LE / 3DWS / BMX / Hexagon

macklebee's channel

Link to comment
Share on other sites

Well, I'm working on the automatic setting of cubemaps for substances, which are all fine on models, but on brushes it gets complicated when you can't get to the material, thanks for the effort and example mack.

HP Omen - 16GB - i7 - Nvidia GTX 1060 6GB

Link to comment
Share on other sites

The brush entity is not documented or "official" because it is too complicated to use. To create brushes you have to do things like update the tex coords, normals, build the faces and edges, and build the visible geometry. I don't want the user to think this is something they need to know.

  • Upvote 1

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

Adding it in. It's brush->GetFace()->GetMaterial()

 

Will this addition also include brush->GetFace(index)->SetMaterial(material) and brush->CountFaces()? Counting faces would be nice but SetMaterial() would allow us to apply different materials to a brush's different faces just like in the editor.

  • Upvote 1

Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590

LE / 3DWS / BMX / Hexagon

macklebee's channel

Link to comment
Share on other sites

  • 3 weeks later...
  • 10 months later...

http://www.leadwerks.com/workshopitem?tags=&queryType=1&fileType=0&fileid=699303085

 

Interesting I worked on this and wanted to ask the same about catching a brush surface because of need to use GetVertexTexCoords()

 

Or is there another way to make this ?

It's a bit strange because with Model:Box() I would get no problem.

So another way would be to construct with Model:Box() the same Brush as edited (assuming it is a box) and apply GetSurface()...

 

I also wanted to ask about changing texture scale (easy to change from the editor) with a script function on brushes ?

 

thx

 

 

Link to comment
Share on other sites

Currently you cannot get the surface of a brush (at least via lua) which means you cannot use Get/SetVertexTexCoords(). You can get the face of a brush via a pick and you can set the material but you can't set the vertex texcoords. You could try not applying script or mass to your Editor-created CSG/brushes. Then at runtime when the map is loaded, the CSG/brushes will be automatically converted to the Model class which will allow you to get the surface and set the vertex texcoords.

 

Edit: you could change the texture scale / position through a shader

  • Upvote 1

Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590

LE / 3DWS / BMX / Hexagon

macklebee's channel

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...