Givo
October 20, 2019, 10:56pm
1
Hi!
This is yet again a follow up on my last post. I have this playground: https://playground.babylonjs.com/#GQCSSP#5
The scene has an imported scene from blender. It has a rectangle scope, a plane that will show the scope sight, and a random camera. I would like to use the camera from the scene as the camera used for the render target texture, What can I do? Any help?
SceneLoader.ImportMesh
will only import meshes: use SceneLoader.load
instead.
1 Like
Givo
October 21, 2019, 11:00am
3
Thanks!
Wait, what am I doing wrong?
BABYLON.SceneLoader.Load("", "https://giv0.gitlab.io/assets/scope_test/", "scope%20test.babylon", scene, function (newStuff) {
splan = newStuff[1];
splan.material = material;
renderTargetTexture.activeCamera = newStuff[2];
//var scam = newMeshes[2];
});
(Pg #7 if you want to try it.)
How do you think this could work?
renderTargetTexture.activeCamera = newMeshes[2];
Cameras are not meshes
This is better: https://playground.babylonjs.com/#GQCSSP#8
1 Like
Givo
October 21, 2019, 4:50pm
5
I see, but I’m trying to use sceneloader.load. I have a camera exported in the scene from blender called scopecam
I want to use that as the camera showing on the scope.
nogalo
October 21, 2019, 4:57pm
6
I might be wrong but
scene.cameras
gives you array of cameras that you have in the scene. So instead of part of your code where you search meshes with that name
if (newMeshes[0].name == scopecam) alert(“lol”);
you need scene.cameras[i].name == scopecam.
2 Likes
Givo
October 21, 2019, 5:02pm
7
https://playground.babylonjs.com/#GQCSSP#10
This alerts you with 2 cameras, scope2 and camera. When I change line 61 to be BABYLON.SceneLoader.Load, the playground freezes. It’s not loading the camera from the .babylon file.
well it works with Append at least:
https://playground.babylonjs.com/#GQCSSP#11
It also works with Load but it will generate a new scene
1 Like
Givo
October 21, 2019, 5:11pm
9
So, Append is like a totally new scene? Now how would I not have it do that but also have the camera be the render target texture?
No Append is the opposite. It appends to the current scene
Load will create a new scene
1 Like
Givo
October 21, 2019, 5:15pm
11
Oh. Why can’t I move the camera? The active camera is set to the one from the blender scene.
Because you need to restore the active camera as the Append has used its own:
https://playground.babylonjs.com/#GQCSSP#12
1 Like
Givo
October 21, 2019, 5:36pm
13
Ok, but why does adding a texture the scopeplan (newMeshes[1]) freeze it again? https://playground.babylonjs.com/#GQCSSP#13
NM I put the line that reasigns the camera at the beginning, but now scopeplan doesn’t show anything.
https://playground.babylonjs.com/#GQCSSP#14
Just hover your mouse over newMeshes
Append callback returns the scene not the list of meshes:
https://doc.babylonjs.com/api/classes/babylon.sceneloader#append
1 Like
Givo
October 21, 2019, 5:50pm
15
so, https://playground.babylonjs.com/#GQCSSP#15 How do I set the texture of scopeplan to material? (used scope here because it is the big mesh and easier to see, i guess)
Something like that:
scene.getMeshByName("scopeplan").material = ...
1 Like
Givo
October 21, 2019, 6:00pm
17
What is “scope” ? I feel like there is a JavaScript problem here
You have to use a string in the getByName and scope seems undefined in your PG
2 Likes
nogalo
October 21, 2019, 6:08pm
20
Like DK said. You need to have string inside getMeshByName(‘scope’);
2 Likes