ViewportFrame Handler - Custom updating objects & humanoids in VPFs

Hey boatbomber, I was wondering why my humanoid animations (AnimationTrack) wouldn’t play in ViewportFrames. Does this module allow me to animate Humanoid objects with them? I’m curious to see what the Humanoid handlers do.

If it does, then I’d be really glad, since I’m still looking for solutions to this (very) annoying problem. All of your open-source projects are awesome and I’m looking forward to an answer.

1 Like

ViewportFrames don’t natively support animations or physics.

This module does work with animations, just not in the way you might think.

When you tell the module to render a humanoid, it’ll make sure the VPF’s humanoid matches the pose of the workspace humanoid. If you animate the workspace humanoid, it’ll show up properly in the VPF as the handler will manually set the CFrames.

2 Likes

So trying to utilize ViewportFrames + the module for an FPS viewmodel doesn’t work? I’ve tried using object handlers but I don’t really think I’m doing it correctly.

I’ll try locally storing a copy of the viewmodel in Workspace at 0, 0, 0, then render the object to the viewport. Hopefully it works.

Edit 2: It works! It works! Thanks for clarifying @boatbomber, your modules are absolutely helpful!

4 Likes

Shouldn’t this be something that reflection property should do?

Shouldn’t this be something that reflection property should do?

The Reflectance property just defines how much a part reflects the skybox cubemap. Even if it had raytraced reflections, that’s still not what the module does.

This module has nothing to do with reflections. This is a module to help you handle your VPFs. Although you could try to use it for makeshift reflections, that is not what this is. You can see various uses throughout the thread, and not a single one is a reflection. It can be used for cameras, fps viewmodels, shop items, flashbangs, scopes, and more.

What part of this thread made you think it was a reflection module? Let me know so I can rephrase and clear it up for future readers.

1 Like

I was looking on wiki how to make a mirror and found your post and after seeing the above gif I thought that was a tilted mirror. My bad, I read your whole post now.

3 Likes

How would I add skybox to this?

You can’t add a skybox to a viewport instance.

How do I update the Camera position? It’s just floating in mid-air right now.

Quick note: The RenderHumanoid fails to use the meshes.
I would suggest inserting this snippet between lines 295 and 296 (In the iterating loop for the characters descendants):

		if d:IsA("CharacterMesh") then
			d:Clone().Parent = CharacterClone
		end
1 Like

There seems to be a problem with tool connections (renderhumanoid’s descendant added connection) not being disconnected.

bivxi7_88371

I added a few lines like checking if :Destroy() was called and setting it into self.Destroyed. Anyways, that’s not relevant,
I changed the descendantadded/removing connections to this:

Character.DescendantAdded:Connect(function(d)
  print("Adding tool")
  print("VF Handler has beed destroyed? " .. tostring(self.Destroyed))
  if d:IsA("BasePart") then
    humHandler.ObjHandlers[d] = self:RenderObject(d,FPS,CharacterClone)
  end
end)
Character.DescendantRemoving:Connect(function(d)
  print("Removing tool")
  print("VF Handler has beed destroyed? " .. tostring(self.Destroyed))
  if humHandler.ObjHandlers[d] then
    humHandler.ObjHandlers[d]:Destroy()
  end
end)

And obviously, you can see the gif, it’s still adding and removing even though it’s destroyed, which causes a lot of errors (and memory leaks).

I was able to fix this by doing the below:

  • In ViewportHandler.new, I added a table to track event connections:
local Handler = {
	HandlerID = HTTP:GenerateGUID(false);
	Frame = Frame;
	ObjectsRenderQueue = {}; --Active only
	AllObjects = {}; --Includes inactive
	EventConnections = {};
}
  • In ViewportHandler:Destroy, I added:
for _, Connection in ipairs(self.EventConnections) do
	Connection:Disconnect()
end

self.EventConnections = nil
  • I changed ViewportHandler:RenderHumanoid's event connections:
local DescendantAddedConnection = Character.DescendantAdded:Connect(function(d)
  if d:IsA("BasePart") then
    humHandler.ObjHandlers[d] = self:RenderObject(d,FPS,CharacterClone)
  end
end)
local DescendantRemovedConnection = Character.DescendantRemoving:Connect(function(d)
  if humHandler.ObjHandlers[d] then
    humHandler.ObjHandlers[d]:Destroy()
  end
end)

table.insert(self.EventConnections, DescendantAddedConnection)
table.insert(self.EventConnections, DescendantRemovedConnection)
  • I added the disconnects to humHandler:Destroy:
function humHandler:Destroy()
  DescendantAddedConnection:Disconnect()
  DescendantRemovedConnection:Disconnect()
  for i,o in pairs(self.ObjHandlers) do
    o:Destroy()
  end
  CharacterClone:Destroy()
end

Afterwards there were no errors in my console:
uao2xa_88381

It says nil because it only gets set when Destroy is called, so basically it just means it wasn’t destroyed.

I encountered this because I’m putting the SurfaceGUI on a tablet tool to have a live feed on the go.

5 Likes

I got a problem with this, it seems like R6 characters appear as blocky. I don’t want that. How would I fix this?

I have a question, does this not support MeshParts & Models (asked about models because i saw you looping through one’s descendants)?
If i change the sanity check below to work with MeshParts will it break the module? Not home rn so can’t test

if not Object or not (typeof(Object) == “Instance” and Object:IsA(“BasePart”)) then warn(“Invalid Object”) return end

So, this is rendering on the server right?

really cool but, does this work with shadows?
edit:
nope, im just going to make a green overlay for “nightvision”

This is honestly pretty cool and useful for viewport stuff.

I tweaked my own version with skybox support. It forks off the Roblox skybox meaning if you add one off the workshop it will put it on the viewport. However, it doesn’t support sun movement or time but it does support sunangularsize.

Use ViewportHandler.new(Frame,trueorfalseforskybox)

And boatbomber. If you officially add this to the module let me know so I can remove this. Thanks!

1 Like

does this work for tools and accessories

Really cool? Would you be willing to add frustum culling to this? I use the viewport with a camera for a map gui, and I want it to render only parts visible from the camera, when it’s fov, position, or things that would influence the frustum change, to prevent lag

can this be used to create a rear view mirror for a car? basically look behind without a separate key

Tweens are acting extremely laggy. Why?