Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Documenting the CollisionGroupData property format #424

Open
phoriah opened this issue Jun 20, 2024 · 1 comment
Open

Documenting the CollisionGroupData property format #424

phoriah opened this issue Jun 20, 2024 · 1 comment

Comments

@phoriah
Copy link
Contributor

phoriah commented Jun 20, 2024

If you wish to document the format behind the CollisionGroupData property -
here's luau code that generates CollisionGroupData-like output using buffers.

CollisionGroupData = function()
	local collision_groups = game:GetService("PhysicsService"):GetRegisteredCollisionGroups()

	local col_groups_n = #collision_groups

	if col_groups_n == 0 then
		return "\1\0"
	end

	local buffer_size = 2 -- Initial size

	for _, group in collision_groups do
		buffer_size += 7 + #group.name
	end

	local b = buffer.create(buffer_size)

	local offset = 0

	buffer.writeu8(b, offset, 1) -- ? [CONSTANT] Version byte (likely)
	offset += 1
	buffer.writeu8(b, offset, col_groups_n) -- Group count
	offset += 1

	for i, group in collision_groups do
		local name, id, mask = group.name, i - 1, group.mask
		local name_len = #name

		buffer.writeu8(b, offset, id) -- ID
		offset += 1

		buffer.writeu8(b, offset, 4) -- ? [CONSTANT] Not sure what this is (also not sure about u8, could be i8)
		offset += 1

		buffer.writei32(b, offset, mask) -- Mask value as signed 32-bit integer
		offset += 4

		buffer.writeu8(b, offset, name_len) -- Name length
		offset += 1
		buffer.writestring(b, offset, name) -- Name
		offset += name_len
	end

	return buffer.tostring(b)
end

Hopefully it's enough.
Feel free to correct the code if it's wrong!

@phoriah
Copy link
Contributor Author

phoriah commented Jan 3, 2025

Updated the code above.
It would be nice to somehow confirm what the constants are meant to represent (especially the second one)

phoriah added a commit to phoriah/rbx-dom that referenced this issue Jan 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants