Module3D V6 (ViewportFrame Implementation)

I have been maintaining Module3D for several years, each being better than the last (except version 5 in some cases). With Roblox’s new ViewportFrames comes a better way to handle the task of adorning models to frames. Previously, you could not use the module with SurfaceGuis, and you won’t get smooth performance with large models. Now both are possible, and at the same time!

image


Advantages Of V6
Module3D V6 is a complete re-write to utilize ViewportFrames instead of positioning objects and correcting the orientation. The advantages of the new implementation this include:

  • More and larger models can be adorned without a performance hit.
  • Positioning frames in BillboardGuis behind the objects are no longer needed.
  • Post-processing effects no longer affect the objects.
  • Map lighting no longer affects the objects.
  • Objects adorned to the sides of the display don’t get distorted.
  • Clipping with the map is longer a problem.
  • Models can be adorned to SurfaceGuis.
  • Updating the rotation uses a lot fewer resources.
  • Properties like FiledOfView can be changed independently of the player’s camera.


Module API
The available API is included in the module. Here is what the module contains:

Module3D:Attach3D(Frame,Model)
	Attaches a model or part to a frame. Returns a Model3D object.
	Does not use a clone of the model so it can be referenced directly.

Model3D object:
	Model3D.Object3D - the model for the bounding box. If the input model was a model, it will be the same as the input.
	Model3D.Parent - the parent frame of the model.
	Model3D.AdornFrame - the frame the model is adorned to.
	Model3D.Camera - the camera used by the viewport frame.
	
	Model3D:Update()
		Force updates the camera CFrame.
	Model3D:SetActive(Active)
		Sets the frame being active.
	Model3D:GetActive()
		Reutrns if the frame is active.
	Model3D:SetCFrame(NewCF)
		Sets the CFrame offset.
		Automatically updates the camera CFrame.
	Model3D:GetCFrame()
		Returns the CFrame offset.
	Model3D:SetDepthMultiplier(Multiplier)
		Sets the multiplier for how far back the camera should go.
		Automatically updates the camera CFrame.
	Model3D:GetDepthMultiplier()
		Returns the depth multiplier
	Model3D:End()


Example
The following file uses the SurfaceGui example above including:

  • Module3D V6 and the Towers model are in ReplicatedStorage
  • SurfaceGUI and the script are in StarterGui

Local Script:

local Frame = script.Parent:WaitForChild("Frame")
local Module3D = require(game.ReplicatedStorage:WaitForChild("Module3D"))
local Towers = game.ReplicatedStorage:WaitForChild("Towers")

local Model3D = Module3D:Attach3D(Frame,Towers)
Model3D:SetDepthMultiplier(1.2)
Model3D.Camera.FieldOfView = 5
Model3D:SetActive(true)

game:GetService("RunService").RenderStepped:Connect(function()
	Model3D:SetCFrame(CFrame.Angles(0,tick() % (math.pi * 2),0) * CFrame.Angles(math.rad(-10),0,0))
end)

Model:
Module3D V6 Example.rbxl (410.6 KB)

44 Likes

This seems really useful, btw have you researched a way to make this new feature useful for Scopes,

I think i might be wrong about this actually.

2 Likes

Module3D won’t be ideal since you will need more direct control over the camera. I would recommend using a ViewportFrame, clone all the instances in the map, and set the camera’s field of view for the ViewportFrame to a lower value. You probably will need to make it a square or rectangle through.

2 Likes

Sounds like an interesting experiment!

This would require dual render, don’t even bother making this with a viewport frame, it will be too resource intensive.

5 Likes

This is incredible, going to use this.

Thank you so much!

It’s actually not very resource-intensive at all surprisingly.

I still wouldn’t do something like that currently as VIewportFrames currently lack all special 3D effects.

1 Like

Can you make a mirror with this new feature?

3 Likes

I’m on it!

1 Like

Incredible, thank you!!

Since ViewportFrames are now live 2 months later, I have removed the beta warning. I am thinking about implementing it in the next (and probably only) update for Roblox Battle (2018 Edition).

1 Like

Are you going to take advantage of the new addition to viewports?

There will be a V6.1 at some point with these features, but I am not sure when. I have some other things to prioritize first.

1 Like