Simple Subviewport/Camera3D -> Mesh Texture

Godot Version

4.4.1

Question

Hi all,

I know this is a simple thing to do and I have spent hours trying to get it to work, but no luck. I have a simple tv studio camera that I am screwing with. I’m using godot 4.4.1 on the quest, but also launch the quick view on my desktop for testing, both do not work.

Here’s the relevant parts of my scene.

[gd_scene load_steps=12 format=3 uid="uid://cmscgovvjjs5b"]

[ext_resource type="Script" uid="uid://b3o6vqjqc4nd3" path="res://addons/godot-xr-tools/objects/pickable.gd" id="1_nvitf"]
[ext_resource type="PackedScene" uid="uid://eppwab8ir3lf" path="res://game_assets/tools/tv_camera_1/tv_camera_1.glb" id="1_p3vgv"]
[ext_resource type="Script" uid="uid://xdx1rg4xkmbn" path="res://game_assets/structures/equipment/studio_camera_1.gd" id="1_xg1l4"]
[ext_resource type="Script" uid="uid://cvclgxrwye62x" path="res://libs/game_assets_meta_data.gd" id="2_p3vgv"]
[ext_resource type="Script" uid="uid://wjlvv8t3lnfx" path="res://addons/godot-xr-tools/objects/grab_points/grab_point_hand.gd" id="4_2xb2h"]

[sub_resource type="QuadMesh" id="QuadMesh_nvitf"]
resource_local_to_scene = true
lightmap_size_hint = Vector2i(4, 4)
size = Vector2(0.48, 0.44)
orientation = 0

[sub_resource type="ViewportTexture" id="ViewportTexture_2xb2h"]
viewport_path = NodePath("CameraResources/SubViewport")

[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_6qccd"]
resource_local_to_scene = true
albedo_texture = SubResource("ViewportTexture_2xb2h")
...
[node name="CameraResources" type="Node3D" parent="."]

[node name="SubViewport" type="SubViewport" parent="CameraResources"]
handle_input_locally = false
render_target_update_mode = 4

[node name="Camera3D" type="Camera3D" parent="CameraResources/SubViewport"]
transform = Transform3D(-4.37114e-08, 0, -1, 0, 1, 0, 1, 0, -4.37114e-08, 0.992632, 1.4867, -0.144331)
current = true
fov = 54.5

[node name="tv_camera_1" parent="CameraResources" instance=ExtResource("1_p3vgv")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.000622988, 1.49853, -0.00477505)

[node name="back_camera_view" type="MeshInstance3D" parent="CameraResources"]
transform = Transform3D(-1, 0, -8.74228e-08, 0, 1, 0, 8.74228e-08, 0, -1, -0.746915, 1.45429, -0.0367884)
mesh = SubResource("QuadMesh_nvitf")
skeleton = NodePath("../..")
surface_material_override/0 = SubResource("StandardMaterial3D_6qccd")
...

The studio_camera_1.gd above was just for debugging, there’s nothing in there. The mesh texture renders fine in the editor if I place objects in front of the camera, but when I launch my game, it renders the first frame (my skybox and the ground) and then nothing else.

As you can see above, I have a subviewport with a camera3d under it and then a quadmesh which points to the subviewport, but only 1 frame. :frowning: What am I doing wrong?

My viewport settings:

And the camera

Oh one last thing I should say, it looks bizarre that the first frame doesn’t have all the candy in it except the ground, but that makes sense as the other stuff gets spawned through threading so the first frame would logically just show the skybox and ground, but the next frames should show the trees and other stuff.

Thanks!

  1. Make sure the spawned objects are on a visibility layer the camera renders
  2. Ensure the material for the camera has ‘local to scene’ enabled, as well as the mesh for it.
  3. Make sure the camera shares the position/rotation of the camera mesh object

1 and 2 are definitely true, but as for 3, to me this doesn’t compute. The quadmesh has to have the same position and rotation as the camera?! I thought the quadmesh could be anywhere in the scene as long as its standardmaterial was set to the respective subviewport? For argument’s sake I just did that and it didn’t work. It has the same result.

I figured it out. You can’t tell in my scene, but the camera is still at the origin. I guess the local to scene made it such that the camera doesn’t move with the scene when it is spawned?

To be clear, when I spawn objects/gridsquares from my collision gridsquares, all scenes are at 0,0,0 and then I position them appropriately depending upon where the player is on my 7 klick map, apparently the Camera3d didn’t go with its scene, but stuck around at the origin to sell some smokes and send out the vibe. I account for that now and position it appropriately on ready and all is well.

I guess that’s just something I need to remember going forward? Or is there something else rotten in the state of Denmark?

It works as intended now, but the extra transform I’m doing makes me feel dirty. :stuck_out_tongue:

So it worked? Putting the camera at the quad mesh’s position worked? And cameras never translate with their owner node3d if they are a child of a subviewport, because the subviewport node doesn’t pass on transform info. Thats why you need a script to do it for you.

No, what you suggested didn’t work because the problem was moving the grid scene and the camera not following.

I think I need a RemoteTransform3D in my scene to fix this for good, but I have it working enough to be unblocked. Thanks.

Well either way glad to hear you fixed it. PS: I love the art style of your game. Sky and mountains look great.

Oh gosh I appreciate it, but it’s so raw right now. I haven’t had time to make things purdy yet. I’ve been stuck screaming at blender for 3d models and working on boring architecture code. In a month I can finally make thiings look presentable, but nonetheless I appreciate the comment.

Yeah just added the RemoteTransform3D and I was able to take out the manual transform. Lovely!

I need these cameras for security cameras and a tv studio I’m making which will be at the start of the game with “breaking news” hehe.

Cool! Do you have an itch page or github page for the game? I would love to see update for this, or even help out.

Currently I only have a dumb blog. I plan to launch the demo in late October and launch the game in early December, fingers crossed I can keep to my production schedule. Starting in August, I’ll open up with discord and social media.

I gotta start a blog for my game, I make no progress, too lazy. Its starting to piss me off, my own laziness that is, so gonna lock in now. Thanks for the link btw.