Put another head's model in my head and remove original.

Dear Guys,

I have started my project on switching heads. But many ways I have tried and I have found I cant get added clientsidemodel head as scaled as it should be. Because with bonemerge the head will be scaled down like my original head.
Also

[LUA]
local bonelist = {
“ValveBiped.Bip01_Pelvis”,
“ValveBiped.Bip01_Spine”,
“ValveBiped.Bip01_Spine1”,
“ValveBiped.Bip01_Spine2”,
–“ValveBiped.Bip01_Spine4”,
–“ValveBiped.Bip01_Neck1”,
–“ValveBiped.Bip01_Head1”,
“ValveBiped.forward”,
“ValveBiped.Bip01_R_Clavicle”,
“ValveBiped.Bip01_R_UpperArm”,
“ValveBiped.Bip01_R_Forearm”,
“ValveBiped.Bip01_R_Hand”,
“ValveBiped.Anim_Attachment_RH”,
“ValveBiped.Bip01_L_Clavicle”,
“ValveBiped.Bip01_L_UpperArm”,
“ValveBiped.Bip01_L_Forearm”,
“ValveBiped.Bip01_L_Hand”,
“ValveBiped.Anim_Attachment_LH”,
“ValveBiped.Bip01_R_Thigh”,
“ValveBiped.Bip01_R_Calf”,
“ValveBiped.Bip01_R_Foot”,
“ValveBiped.Bip01_L_Thigh”,
“ValveBiped.Bip01_L_Calf”,
“ValveBiped.Bip01_L_Foot”,
“ValveBiped.Bip01_R_Wrist”,
“ValveBiped.Bip01_L_Wrist”,
“ValveBiped.Bip01_L_Ulna”,
“ValveBiped.Bip01_R_Ulna”,
}

hook.Add( “PostPlayerDraw” , “manual_model_draw_example” , function( ply )

/*Should Work*/




--local boneindex = ply:LookupBone("ValveBiped.Bip01_Head1")
--local bonematrix = ply:GetBoneMatrix(ply:LookupBone("ValveBiped.Bip01_Head1"))
--ply:ManipulateBoneScale( boneindex, Vector(0,0,0) )
--ply:SetBoneMatrix( boneindex , bonematrix )

--if IsValid(ply.MaskMDL) then SafeRemoveEntity( ply.MaskMDL ) end
--if IsValid(ply.MaskMDL) then
--else
--ply.MaskMDL = ClientsideModel( "models/player/Group01/male_06.mdl")
--end
--local MaskMDL = ply.MaskMDL	
--MaskMDL:SetParent( ply )
--MaskMDL:AddEffects(EF_BONEMERGE)
/*
local headboneindex = MaskMDL:LookupBone("ValveBiped.Bip01_Head1")
local headbonematrix = MaskMDL:GetBoneMatrix(MaskMDL:LookupBone("ValveBiped.Bip01_Head1"))
MaskMDL:ManipulateBoneScale( headboneindex, Vector(1,1,1) )
MaskMDL:SetBoneMatrix( headboneindex , headbonematrix )
*/

if IsValid(ply.MaskMDL) then
else
ply.MaskMDL = ClientsideModel( "models/player/Group01/male_06.mdl")
end
local MaskMDL = ply.MaskMDL	
local headmatrix = ply:GetBoneMatrix(ply:LookupBone("ValveBiped.Bip01_Head1"))
for key, bone in pairs(bonelist) do
	local index = MaskMDL:LookupBone(bone)  
	--if !isnumber(MaskMDL:GetBoneMatrix(index)) then print(MaskMDL:GetBoneMatrix(index)) end
	local matrix = MaskMDL:GetBoneMatrix(index)
	--print(matrix)
	if isnumber(matrix) then
	matrix:Scale(vector_origin)
	matrix:SetTranslation(headmatrix:GetTranslation())
	MaskMDL:SetBoneMatrix(index, matrix) 
	end
end

local position, angles = ply:GetBonePosition(ply:LookupBone("ValveBiped.Bip01_Head1"))
	
local x = angles:Up() * 0  
local y = angles:Right() * 0
local z = angles:Forward() * -65

angles:RotateAroundAxis(angles:Forward(), -90)  
angles:RotateAroundAxis(angles:Right(), -90)  
angles:RotateAroundAxis(angles:Up(), 0)  

MaskMDL:SetPos(position + x + y + z)
MaskMDL:SetAngles(angles)

end )

[/LUA]

I searched on inter for others who solved this problem. Actually nobody. I only found 7 years old codes.
As far as I know maybe I need to use [LUA]GM:PostDrawOpaqueRenderables( boolean bDrawingDepth, boolean bDrawingSkybox )[/LUA] Because I had also problem with the model appeared on viewmodel also. I am using hat modify function on postplayerdraw they are working perfectly. Just the head change isnt.

Also my script is on CLIENT side.

i recall tiramisu 2 having this feature, maybe see how it was done there?

The version i have found from github says dont use. Really outdated. I will check it today. Anybody has any other idea? I can remove the head but cant put the model where to the body is. And only head appear for other model.

Okay i searched so much. Im not clever than before. No feature that can manipulate the extra model to attach right to the original player model. And other part of the model disappear.

So no new idea? In Gmod no developer who ever did this. It will be secret 4ever? No tips?

This is a little dumb but it can work: if you’re sure that the arms and hands will never go above the neck, you can use render clip planes.

this isnt a problem. I wanna place head into the original model heads pos. Thats what I am trying to do. Without bonemerge. Bonemerge not the best.

You’re welcome to create this and then share how did you achieve this! No one here is forced to share this kind of technique, and i’m sure that a good developer even not knowing it, with 20 minutes to think something out of the box, would get a good solution

But expecting people to just come out and tell you how stuff it’s done, it’s useless

Well I just gave you an idea of how to do this, so what are you asking?

Nobody asked copy paste the code. Just tips. And I will tell you it helped or not.

As i’ve stated…Nobody here knows how to do that, but if you give to a good developer this task, he’ll sit and think about this a good amount of time until he finds how to complete this task
Just do a brainstorm…Think about 2 models attached and parented, scale every bone except neck and head, use a clip plane…I don’t know, think something, don’t expect us to know about everything, that’s the spoonfed behavior that we really hate here

[LUA]
Heads = Heads or {}
function ClearHeads()
–print(#Heads)
for k, v in pairs(Heads) do
if #Hats > 0 then

		--table.RemoveByValue( Heads, v )
		--SafeRemoveEntity( v )
	end
end
for k, v in pairs( Heads ) do
	if not IsValid( v ) then
		Heads[ k ] = nil
	elseif not IsValid( v.Owner ) then
		print("Removing Head")
		SafeRemoveEntity( v )
		Heads[ k ] = nil
	end
end

end

function AddHead(name,ply)
SafeRemoveEntity( ply.head )
–if IsValid(ply.head) then return ply.Hat end
local head
print(“Creating Head”)
head = ClientsideModel( name )
head:SetNoDraw(true)
ply.Head = head
head.Owner = ply

table.insert(Heads, head )
print(#Heads)
--return head

end

function ModifyHead()
–print()
if IsValid(LocalPlayer().Head) then
if IsValid(LocalPlayer().Head.Owner) then
LocalPlayer().Head.Owner = nil
end
LocalPlayer().Head = nil
end

--SafeRemoveEntity( LocalPlayer().Head )

ClearHeads()
if IsValid(LocalPlayer().Head) then
SafeRemoveEntity( LocalPlayer().Head )
--LocalPlayer().Head.Owner = nil
SafeRemoveEntity( LocalPlayer().Head )
end
if IsValid(LocalPlayer().Head) then
LocalPlayer().Head = nil
end
ClearHeads()
if IsValid(LocalPlayer().Head) then
LocalPlayer().Head = nil
end

end

hook.Add( “PostPlayerDraw”, “Test_Switch_Head”, function( ply )
ClearHeads()
if !IsValid(ply) or ply:Team() != TEAM_ALIVE or !ply:Alive() then return end

if not IsValid( ply.Head ) then

	local bone = ply:LookupBone("ValveBiped.Bip01_Head1")
	local vm = ply:GetBoneMatrix(bone)
	
	vm:Scale(Vector(0.01, 0.01, 0.01))
	
	ply:SetBoneMatrix(bone, vm)
	
	
	AddHead( "models/player/group01/female_01.mdl", ply )
	ply.Head:SetParent(ply)
	ply.Head:AddEffects( EF_BONEMERGE )
	for i = 0, ply.Head:GetBoneCount()-1 do
		if ply.Head:GetBoneName( i ) == "ValveBiped.Bip01_Head1" 
		then
			local vm = ply.Head:GetBoneMatrix(i)
			vm:Scale( Vector( 1, 1, 1 ) ) -- 1/0.01
			ply.Head:SetBoneMatrix( i, vm )
		elseif ply.Head:GetBoneName( i ) != "__INVALIDBONE__" and 
		ply.Head:GetBoneName( i ) != "ValveBiped.Bip01_Head1" 
		then
			local vm = ply.Head:GetBoneMatrix( i )
			vm:Scale( Vector( 0.01, 0.01, 0.01 ) )
			ply.Head:SetBoneMatrix( i, vm )
		end
	end
end
ply.Head:SetNoDraw( false )

end)
[/LUA]

I cant understand why scale not working. I will try with manipulate tomorrow.