Facepunch / garrysmod-issues

Garry's Mod issue tracker
140 stars 56 forks source link

Decals & GetRenderMesh #5296

Open shadowscion opened 2 years ago

shadowscion commented 2 years ago

Details

Decals are not rendered when placed on entities that use GetRenderMesh, even if the mesh matches the model.

GMod version 2022.07.13, branch: x86-64, multicore: 1

Steps to reproduce

Place this code in a in lua/entities/ Spawn it from the top spawn menu in the other category Shoot at or use the Paint tool on the entity, for clarity's sake it will alternate between normal DrawModel and GetRenderMesh

DEFINE_BASECLASS("base_anim")

ENT.PrintName   = "meshtest_decal"
ENT.AdminOnly   = false
ENT.RenderGroup = RENDERGROUP_BOTH
ENT.Spawnable   = true

function ENT:SpawnFunction( ply, tr, ClassName )
    if not tr.Hit then return end

    local ent = ents.Create( ClassName )

    ent:SetModel( "models/Combine_Helicopter/helicopter_bomb01.mdl" )
    ent:SetPos( tr.HitPos + tr.HitNormal * 16 )
    ent:Spawn()
    ent:Activate()

    return ent
end

function ENT:Initialize()
    if SERVER then
        self:PhysicsInit( SOLID_VPHYSICS )
        self:SetMoveType( MOVETYPE_VPHYSICS )
        self:SetSolid( SOLID_VPHYSICS )
    end
end

if SERVER then return end

local myMaterial = Material( "models/wireframe" )

function ENT:CreateMesh()
    if self.Mesh then self.Mesh:Destroy() end

    local visualMeshes = util.GetModelMeshes( self:GetModel() )

    if not visualMeshes then return end

    local visualMesh = visualMeshes[1]

    myMaterial = Material( visualMesh.material )

    self.Mesh = Mesh()
    self.Mesh:BuildFromTriangles( visualMesh.triangles )
end

function ENT:GetRenderMesh()
    if not self.alternate then return end
    if not self.Mesh then return self:CreateMesh() end

    return { Mesh = self.Mesh, Material = myMaterial }
end

function ENT:Draw()
    self:DrawModel()
end

function ENT:Think()
    self.alternate = not self.alternate
    self:SetNextClientThink( CurTime() + 1 )
    return true
end
Kot-Charodey commented 6 months ago

I join the issue. I am surprised that this issue has not been fixed yet. I am working on an add-on with dynamically created models, and I encountered this bug recently. Without decals, the graphics of the add-on suffer greatly, HELP! 🤬