ModelWrapper Module

ModelWrapper allows you to set the CFrame, Scale, Color, Transparency, and Material of a whole Model, while preserving the original values and avoiding the dreaded ‘brick shift’ caused by accumulating float inaccuracies. You can set and reset each of those properties subject to the following minor limitations:

  • No support for resetting the CFrame (I don’t see the use-case)
  • Scale is set with a number, not a Vector3, so the model scales uniformly on each axis
  • Does not (in this version) accommodate adding or removing descendants after the Wrapper over the Model is instantiated

You may find this particularly useful when making placement systems, for example, where you may want the model to:

  • Temporarily be semi-transparent
  • Change color depending on whether the placement is valid

Documentation is found in the Module. Grab it here:

Feedback and bug reports are welcomed!

21 Likes

:frowning:
image

Sorted, thanks.

2 Likes

Any chance of this becoming a plugin?

1 Like

Awesome Module, I didn’t know that you can do

local self = setmetatable({}, ModelWrapper)

	function ModelWrapper.new(Model)
		local self = setmetatable({}, ModelWrapper)
		-- Code
		return self
	end

This taught me something new :grinning:

I know that it’s the same as

local Var = setmetatable({}, ModelWrapper)

but using self is way cooler!


Suggestion

Add something like

Last Updated “Date” in the script + Version so we know if it’s outdated

Upload it as a Module so we can just require it

Add code that will print(‘Module Outdated’) if it’s outdated by Linking it to a MainModule or something

Beautiful!

Some quick feedback:

I think as @Starception suggested this would also be quite useful in the case of a plugin. Perhaps a widget that allows you to select which models should have this extra precision, then when the primary CFrame or size properties are changed you can apply the cached offsets.

I also think it would be worth having the cache be updated when a descendant is added to the model. At the very least have a method so that we can update it ourselves manually.

5 Likes