1
0
mirror of https://github.com/CFC-Servers/material-editor-tool.git synced 2025-03-04 03:13:00 -05:00

Tweaks+Improvements (#3)

* Catch advmat 2 rotation + an error.

* Add alphatype support.

+ tweak style & var names

* Apply suggestion + style
This commit is contained in:
StrawWagen 2023-11-27 14:01:53 -07:00 committed by GitHub
parent bb83014111
commit 096c5ff392
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 50 additions and 18 deletions

View File

@ -28,13 +28,14 @@ function advMat_Table:ValidateAdvmatData( data )
ScaleY = data.ScaleY or 1,
OffsetX = data.OffsetX or 0,
OffsetY = data.OffsetY or 0,
ROffset = data.ROffset or 0,
ROffset = data.ROffset or data.Rotate or 0, -- data.Rotate, catch advmat 2 rotation
UseNoise = data.UseNoise or false,
NoiseTexture = data.NoiseTexture or "detail/noise_detail_01",
NoiseScaleX = data.NoiseScaleX or 1,
NoiseScaleY = data.NoiseScaleY or 1,
NoiseOffsetX = data.NoiseOffsetX or 0,
NoiseOffsetY = data.NoiseOffsetY or 0,
AlphaType = data.AlphaType or 0,
}
return dataValid
@ -44,7 +45,7 @@ function advMat_Table:GetMaterialPathId( data )
local dataValid = self:ValidateAdvmatData( data )
local texture = string.Trim( dataValid.texture )
local uid = texture .. "+" .. dataValid.ScaleX .. "+" .. dataValid.ScaleY .. "+" .. dataValid.OffsetX .. "+" .. data.OffsetY .. "+" .. dataValid.ROffset
local uid = texture .. "+" .. dataValid.ScaleX .. "+" .. dataValid.ScaleY .. "+" .. dataValid.OffsetX .. "+" .. data.OffsetY .. "+" .. dataValid.ROffset .. "+" .. dataValid.AlphaType
if dataValid.UseNoise then
uid = uid .. dataValid.NoiseTexture .. "+" .. dataValid.NoiseScaleX .. "+" .. dataValid.NoiseScaleY .. "+" .. dataValid.NoiseOffsetX .. "+" .. dataValid.NoiseOffsetY
@ -59,6 +60,12 @@ function advMat_Table:GetStored()
return self.stored
end
-- indexes are 1 / 3 to catch advmat 2'ed props, removed index 2 support, it was too specialized.
local alphaTypes = {
[1] = "$alphatest",
[3] = "$translucent"
}
function advMat_Table:Set( ent, texture, data )
if not IsValid( ent ) then return end
data.texture = texture
@ -99,13 +106,16 @@ function advMat_Table:Set( ent, texture, data )
local matTable = {
["$basetexture"] = tempMat:GetName(),
["$basetexturetransform"] = "center .5 .5 scale " .. ( 1 / dataV.ScaleX ) .. " " .. ( 1 / dataV.ScaleY ) .. " rotate " .. dataV.ROffset .. " translate " .. dataV.OffsetX .. " " .. dataV.OffsetY,
["$vertexalpha"] = 0,
["$vertexcolor"] = 1
}
local iTexture = tempMat:GetTexture( "$basetexture" )
if not iTexture then return end
if dataV.AlphaType > 0 then
matTable[alphaTypes[data.AlphaType]] = 1
end
for index, currData in pairs( dataV ) do
if ( index:sub( 1, 1 ) == "$" ) then
matTable[k] = currData

View File

@ -14,6 +14,8 @@ TOOL.ClientConVar["noisescalex"] = "1"
TOOL.ClientConVar["noisescaley"] = "1"
TOOL.ClientConVar["noiseoffsetx"] = "0"
TOOL.ClientConVar["noiseoffsety"] = "0"
TOOL.ClientConVar["alphatype"] = "0"
TOOL.DetailWhitelist = {
"concrete",
"plaster",
@ -55,6 +57,7 @@ function TOOL:LeftClick( trace )
local noisescaley = tonumber( self:GetClientInfo( "noisescaley" ) )
local noiseoffsetx = tonumber( self:GetClientInfo( "noiseoffsetx" ) )
local noiseoffsety = tonumber( self:GetClientInfo( "noiseoffsety" ) )
local alphatype = tonumber( self:GetClientInfo( "alphatype" ) )
advMat_Table:Set( trace.Entity, string.Trim( texture ):lower(), {
ScaleX = scalex,
@ -67,7 +70,8 @@ function TOOL:LeftClick( trace )
NoiseScaleX = noisescalex,
NoiseScaleY = noisescaley,
NoiseOffsetX = noiseoffsetx,
NoiseOffsetY = noiseoffsety
NoiseOffsetY = noiseoffsety,
AlphaType = alphatype,
} )
return true
@ -147,41 +151,41 @@ function TOOL:Think()
return
end
if not self.PreviewMat or not self.PreviewMatNoise then
if not self.PreviewMat or not self.PreviewNoisedMats then
self.PreviewMat = CreateMaterial( "AdvMatPreview", "VertexLitGeneric", {
["$basetexture"] = texture,
["$basetexturetransform"] = "center .5 .5 scale " .. ( 1 / scalex ) .. " " .. ( 1 / scaley ) .. " rotate " .. roffset .. " translate " .. offsetx .. " " .. offsety,
["$vertexalpha"] = 0,
["$vertexcolor"] = 1,
["$vertexalpha"] = 0
} )
local PreviewMatNoise = {}
local previewNoisedMats = {}
local previewMatTable = {
["$basetexture"] = texture,
["$basetexturetransform"] = "center .5 .5 scale " .. ( 1 / noisescalex ) .. " " .. ( 1 / noisescaley ) .. " rotate " .. roffset .. " translate " .. noiseoffsetx .. " " .. noiseoffsety,
["$vertexcolor"] = 1,
["$vertexalpha"] = 0,
["$vertexcolor"] = 1,
["$detailtexturetransform"] = "center .5 .5 scale 1 1 rotate 0 translate 0 0",
["$detailblendmode"] = 0,
}
previewMatTable["$detail"] = self.DetailTranslation[ "concrete" ]
PreviewMatNoise.concrete = CreateMaterial( "AdvMatPreviewNoiseConcrete", "VertexLitGeneric", previewMatTable )
previewNoisedMats.concrete = CreateMaterial( "AdvMatPreviewNoiseConcrete", "VertexLitGeneric", previewMatTable )
previewMatTable["$detail"] = self.DetailTranslation[ "plaster" ]
PreviewMatNoise.plaster = CreateMaterial( "AdvMatPreviewNoisePlaster", "VertexLitGeneric", previewMatTable )
previewNoisedMats.plaster = CreateMaterial( "AdvMatPreviewNoisePlaster", "VertexLitGeneric", previewMatTable )
previewMatTable["$detail"] = self.DetailTranslation[ "metal" ]
PreviewMatNoise.metal = CreateMaterial( "AdvMatPreviewNoiseMetal", "VertexLitGeneric", previewMatTable )
previewNoisedMats.metal = CreateMaterial( "AdvMatPreviewNoiseMetal", "VertexLitGeneric", previewMatTable )
previewMatTable["$detail"] = self.DetailTranslation[ "wood" ]
PreviewMatNoise.wood = CreateMaterial( "AdvMatPreviewNoiseWood", "VertexLitGeneric", previewMatTable )
previewNoisedMats.wood = CreateMaterial( "AdvMatPreviewNoiseWood", "VertexLitGeneric", previewMatTable )
previewMatTable["$detail"] = self.DetailTranslation[ "rock" ]
PreviewMatNoise.rock = CreateMaterial( "AdvMatPreviewNoiseRock", "VertexLitGeneric", previewMatTable )
previewNoisedMats.rock = CreateMaterial( "AdvMatPreviewNoiseRock", "VertexLitGeneric", previewMatTable )
self.PreviewMatNoise = PreviewMatNoise
self.PreviewNoisedMats = previewNoisedMats
end
@ -197,12 +201,12 @@ function TOOL:Think()
noiseTexture = "concrete"
end
self.PreviewMatNoise[noiseTexture]:SetMatrix( "$detailtexturetransform", noiseMatrix )
self.PreviewNoisedMats[noiseTexture]:SetMatrix( "$detailtexturetransform", noiseMatrix )
if self.noise ~= self:GetClientInfo( "noisetexture" ) then
self.noise = noiseTexture
self.Preview = self.PreviewMatNoise[noiseTexture]
self.Preview = self.PreviewNoisedMats[noiseTexture]
end
end
@ -214,7 +218,10 @@ function TOOL:Think()
matrix:Rotate( Angle( 0, roffset, 0 ) )
if mat:GetString( "$basetexture" ) ~= texture then
mat:SetTexture( "$basetexture", Material( texture ):GetTexture( "$basetexture" ) )
local iMaterial = Material( texture ):GetTexture( "$basetexture" )
if iMaterial then
mat:SetTexture( "$basetexture", iMaterial )
end
end
mat:SetMatrix( "$basetexturetransform", matrix )
@ -297,7 +304,7 @@ do
end
CPanel:CheckBox( "#tool.advmat.usenoise", "advmat_usenoise" )
CPanel:ControlHelp( "If this box is checked, your material will be sharpened using an HD detail texture, controlled by the settings below." )
CPanel:ControlHelp( "#tool.advmat.usenoise.helptext" )
CPanel:AddControl( "ComboBox", {
Label = "#tool.advmat.noisetexture",
@ -316,6 +323,13 @@ do
LocalPlayer():ConCommand( "advmat_noise" .. k:lower() .. " " .. v )
end
end
local alphabox = CPanel:ComboBox( "#tool.advmat.alphatype", "advmat_alphatype" )
alphabox:AddChoice( "#tool.advmat.alphatype.none", 0 )
alphabox:AddChoice( "#tool.advmat.alphatype.alphatest", 1 )
alphabox:AddChoice( "#tool.advmat.alphatype.translucent", 3 )
CPanel:ControlHelp( "#tool.advmat.alphatype.helptext" )
end
end
/*
@ -334,7 +348,9 @@ if CLIENT then
language.Add( "tool.advmat.offsetx", "Horizontal Translation" )
language.Add( "tool.advmat.offsety", "Vertical Translation" )
language.Add( "tool.advmat.roffset", "Rotation" )
language.Add( "tool.advmat.usenoise", "Use noise texture" )
language.Add( "tool.advmat.usenoise.helptext", "If this box is checked, your material will be sharpened using an HD detail texture, controlled by the settings below." )
language.Add( "tool.advmat.noisetexture", "Detail type" )
@ -347,6 +363,12 @@ if CLIENT then
language.Add( "tool.advmat.details.wood", "Wood" )
language.Add( "tool.advmat.details.rock", "Rock" )
language.Add( "tool.advmat.alphatype", "Alpha Type" )
language.Add( "tool.advmat.alphatype.none", "None" )
language.Add( "tool.advmat.alphatype.alphatest", "Alphatest" )
language.Add( "tool.advmat.alphatype.translucent", "Translucent" )
language.Add( "tool.advmat.alphatype.helptext", "Texture-level transparency, for windows, foliage, etc. If unsure, set to None, or AlphaTest." )
list.Set( "tool.advmat.details", "#tool.advmat.details.concrete", { advmat_noisetexture = "concrete" } )
list.Set( "tool.advmat.details", "#tool.advmat.details.plaster", { advmat_noisetexture = "plaster" } )
list.Set( "tool.advmat.details", "#tool.advmat.details.metal", { advmat_noisetexture = "metal" } )