SmartBone 2 - Simulated Physics and Collision solution for Bones

I understand that it would be easier to figure it out with a place file. So I’m looking into my development file for the second iteration of my hair library.

I almost had it but what has me scratching my head is how do I appropriately add the calculation.
Given just the rotational elements of the bone

function Class.new(Bone: Bone, RootBone: Bone, RootPart: BasePart): IBone
	local ParentCFrame = Bone.Parent:IsA("Bone") and Bone.Parent.TransformedWorldCFrame or RootPart.CFrame
	local InitialOrientation=CFrame.new(0,0,0)
	if Bone~=RootBone then
		InitialOrientation=Bone.CFrame-Bone.CFrame.Position
	end
end
	local self = setmetatable({
		Bone = Bone,
		FreeLength = -1,
		Weight = 0.7,
		ParentIndex = -1,
		HeirarchyLength = 0,
--etc
	TransformCFrame=InitialOrientation
		AnimatedWorldCFrame = Bone.TransformedWorldCFrame,
		StartingCFrame = Bone.TransformedCFrame,
		TransformOffset = CFrame.identity,
		LocalTransformOffset = CFrame.identity,
		RestPosition = Vector3.zero,
		CalculatedWorldCFrame = Bone.TransformedWorldCFrame,

		Position = Bone.TransformedWorldCFrame.Position,
		LastPosition = Bone.TransformedWorldCFrame.Position,
function Class:ApplyTransform(BoneTree)
do end
	
self.SolvedAnimatedCFrame = false

	if self.ParentIndex < 1 then
do end		
return
	end

	local ParentBone: IBone = BoneTree.Bones[self.ParentIndex]
	local BoneParent = ParentBone.Bone

	-- We check if the magnitude of rotation sum is zero because that tells us if it has already been averaged by another bone.
	-- if ParentBone.NumberOfChildren > 1 and ParentBone.RotationSum.Magnitude ~= 0 then
	-- 	local AverageRotation = ParentBone.RotationSum / ParentBone.NumberOfChildren
	-- 	ParentBone.CalculatedWorldCFrame = CFrame.new(ParentBone.Position)
	-- 		* CFrame.fromEulerAnglesXYZ(AverageRotation.X, AverageRotation.Y, AverageRotation.Z)
	-- 	ParentBone.RotationSum = Vector3.zero
	-- end

	if ParentBone and BoneParent then
		if ParentBone.Anchored and BoneTree.Settings.AnchorsRotate == false then -- Anchored and anchors do not rotate
			--if BoneParent~=ParentBone.RootBone then
			--	BoneParent.Transform =ParentBone.TransformCFrame
			--end
			BoneParent.WorldCFrame = ParentBone.TransformOffset
			BoneParent.CFrame*=ParentBone.TransformCFrame
		--	BoneParent.WorldCFrame = CFrame.new(ParentBone.Position) * ParentBone.CalculatedWorldCFrame.Rotation
		else -- Not anchored
			BoneParent.WorldCFrame = ParentBone.CalculatedWorldCFrame
			BoneParent.CFrame*=ParentBone.TransformCFrame--*ParentBone.TransformCFrame
		end
	end
do end
end

To me it made sense since the World Position is being calculated and after that is done I multiply the bone’s CFrame by the orientation of the bone.
But It doesn’t seem to work. I also tried the of the angle orientation Inverse() as a sanity check.

Smart Bone Turned off


As you can see this rig has bones
wth initial Orientations as designed by the developers.
If they were all set to 0 as per the limitations of the current version

With the patch I mentioned enabled and smart bone running.

I disable the patch


Now it’s point the other direction.
I think part of the issue is how the WorldUp CFrame is calculated. To get that done I imagine you would simply multiply the InitialOrientation. But I’m just reverse engineering your system! I really do not know or do I have the time to spend another several hours trying to figure out how to fix it.

I forgot to mention this patch and issue does not affect previous SmartBone objects except by increasing the compatibility of the system to it’s actual completion.
This is because a bone with an initial orientation of 0,0,0 will calculate to the same sum.


In conclusion I think the issue is partially solved by the snippets I showed you and would be completely solved by including it into the WorldUp calculations made to determine gravity.

1 Like

This is an incredible system, however I am running into some issues with bones Infront of the player - what provisions can I make to prevent clipping?

I have tried adding collision & limiting angles however both of these dont work as well as I would like

Is there any alternatives to these?

Many thanks :slight_smile: !

1 Like

Add the tag SmartCollider to the legs of your character or your entire character

CollectionService=game:GetService("CollectionService")
CollectionService:AddTag(object,"SmartCollider")
1 Like

I appreciate you taking a look at this:

Sorry for the miscommunication, when I said I had made allowance for Collision what I meant was that I had already enabled and tried the SmartCollider.

I have been reconfiguring the bones & changing the Collision shapes, but to no avail.

Do you have any advice beyond this point? Do you have any examples of successful Smartbones & collision when the clothing is “Skirt-like”.

Many thanks,

1 Like

The creator told somebody to try increasing the bone radius of your smart bones.
I did write this module to assist me in bulk smartbone asset creation. On looking at it appears you can use the SetBoneRadius function to help debug your asset.
SmartBoneUtility.lua (4.8 KB)

local module = {}
local CollectionService = game:GetService("CollectionService")

-- Function to add a tag to an object
function module.AddTagToObject(object, tagName)
	if not CollectionService:HasTag(object, tagName) then
		CollectionService:AddTag(object, tagName)
	end
end

function module.setRoots(targetObject)	
	local str=""
	local t=0
	for i,v in targetObject:GetChildren() do
		if v:IsA("Bone") then
			t+=1
			if t~=1 then
				str..=","..v.Name
			else 
				str..=v.Name
			end		
		end 
	end
	targetObject:SetAttribute("Roots",str)
end

function module.copyAttributes(sourceObject, targetObject)
	local attributes = sourceObject:GetAttributes()
	for attributeName, attributeValue in pairs(attributes) do
		targetObject:SetAttribute(attributeName, attributeValue)
	end
	module.AddTagToObject(targetObject,"SmartBone")
end

function module.FormatChar(char)
	module.AddTagToObject(char.Head,"SmartCollider")
	module.AddTagToObject(char.UpperTorso,"SmartCollider")	
	module.AddTagToObject(char.LowerTorso,"SmartCollider")	
	module.AddTagToObject(char.LeftUpperArm,"SmartCollider")
	module.AddTagToObject(char.RightUpperArm,"SmartCollider")	
end

function module.SetBoneRadius(object,radius)
	for i,v in object:GetDescendants() do
		if v:IsA("Bone") then
			v:SetAttribute("Radius",radius)
		end
	end 
end 

function module.ConvertModelToAccessory(Dir,output)
for i,v in Dir:GetChildren() do
	local c= v:FindFirstChildOfClass("MeshPart") 
	if c then 
		local d = Instance.new("Accessory")
		local p=Instance.new("Attachment")
		p.Name="HairAttachment"
		c.Parent=d
		p.Parent=c c.Name="Handle"
		d.Parent=output
	end
end
end


return module

I find this module to be crucial when developing smartbone assets in bulk.
That was because at the time I discovered this there was no access to the plugin.

3 Likes

For some reason, my cape is glitchy. I’ll let the video explain itself;

External Media

someone please help thank you

Try this: SmartBone 2 - Simulated Physics and Collision solution for Bones - #356 by Magus_ArtStudios

2 Likes

Hello, my cape’s bones get bugged whenever the character is falling/going at high speeds.

I tried messing with most of the attributes but it didn’t help.

thanks!

3 Likes

For some odd reason, the mesh acts very weird if a bone has more than one child. Is there a fix for this? :thinking:

1 Like

Try v0.3.1‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎

2 Likes

hello, I may be stupid but i cant access the smartbone editor plugin, it says " You need permissions to access this content"

1 Like

Try v0.3.1‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎

(btw thats the version im using and from what i can tell i think it has something to do with the gravity)

I need help, how would I rig a sail in blender? (Using SB2)

image
I’m using this for my ship sails to flutter in the wind
worked fine but threw a couple errors after a while, so updated to the newer version of the module and now it crashes my game within seconds while giving me this warning

3 Likes

I’m also experiencing this bug with SmartBone2.
“If you see this report this as a bug, (NaN Calc world cframe)”

refer to this‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎

2 Likes

Also, i’m currently using Smartbone 1 is there any way to prevent that false mesh deformation with Smartbone 1? Like editing any scripts or something else?

any fixes to this?
the bones are resetting rotation when i move