Jump to content

Remove meshes from viewport and apply different color to different viewport


Brijesh
 Share

Recommended Posts

I created 2 viewport from scene and set camera position of both viewport different  so i can get two different view in one canvas.

Now i try to remove some meshes from one viewport, display all meshesh in viewport1 but need to remove some mashes that is display in viewport1 and display rest meshes in viewport2.

Is it possible ?? Can anyone help me ...!!!

Can i set different background colour to different viewport ??

Link to comment
Share on other sites

Hiya @Brijesh.

Would it be ok if all mesh stayed in both viewports (they are a common SCENE), but camera 1 can only "see" SOME mesh, and camera 2 can only see OTHER mesh?

The non-seeable mesh would still be in-the-scene and at their current .positions.  They could be collided-with, but, not seen.

And you could choose when/not to have them BE seen/not.  Does that sound workable?  If so, your answer is layerMasks (and possibly renderTargetTextures) (RTT's).

RTT's let you use ONE viewport, but you can put PLANES on the screen... with views from different cameras... as their textures.  You could parent these planes to the main camera, so they stay in the corners of the main viewport, no matter how you turn the main camera.  But it is (possibly-) challenging to navigate the EXTRA cameras... using the mouse/controllers.

Anyway, here is a playground with FOUR renderTargetTextures, with background panel, parented to main camera 1.  Pretty cool way to do multiple views, huh?  Notice that RTT's don't display post-processing things like highlightLayer.  Those things happen LATER... further "downstream" from RTT's.

Mon1 is the little view window furthest left.  It is a RTT of camera 1... which is also the main camera.  Notice that mon1 does NOT have a picture of the 4 viewers at the bottom of camera 1... within ITS little-view (mon1).  HOW did we remove the 4 planes and background plane... from mon1 view?

Using layerMasks... that's how.  :)  In lines 14-17, we set all cameras... to layerMask 2.  Now let's look at the 'mon' planes and background plane... lines 86, 95, 104, 114, and 124.  All set layerMask 1.  That is why those 5 planes are NOT displayed in mon1.

You can do the same.  All mesh you want "seen" in viewport 1... set layerMask = 1.  All mesh you want seen in viewport 2, layerMask 2.  Easy, huh?  Remember... they will STILL BE THERE, just invisible.

About the background colors... same deal.  Make 2 skyboxes with solid color cubeMap images (skyboxes/cubeMaps need 6 images each).  One... maybe blue images, and the other, perhaps green.  Same as mesh... set skybox1.layerMask = 1, and skybox2.layerMask = 2.  Now one viewport should have blue background, and the other green.

Just for fun, here is that demo... WITHOUT using layerMasks.  See the mon1-4 planes in mon1 little-view?  Nod.  Friendly forum helpers taught me how to fix that.  :)

Would this stuff work for you?  I hope some of this helps.  Be well, party on.

Link to comment
Share on other sites

Thanks @Wingnut , Its working fine.

But i have one problem, I have 2 mashes, I want to show this 2meshes  in one main view as normal scene and want to show only 1 mesh out of this 2meshes in second viewport. and first view port is as its with 2 mashes.

but when i set 2nd mesh in second viewport, its disappear from 1st viewport.

please help me ...!!!

Link to comment
Share on other sites

Hi again, B.  Good to hear that you are rolling well.

http://www.babylonjs-playground.com/#13TVWJ#4

How is your binary number knowledge?  :)

Above demo is a 3-viewport scene, but really, it is 5 viewports.  Each blue line is also a viewport.  :)


SO, camera 1, 3, and 5 are the important cameras.  You can ignore camera 2 and 4.

Line 8:    camera1.layerMask = 0x00000001;
Line 15:  camera3.layerMask = 0x00000010;
Line 24:  camera5.layerMask = 0x00000100;
 

Now, let's go look at the layerMasks on the 3 colored boxes:

Line 102:  cb1.layerMask = 0x00000001;  (red box -> camera 1 display only)
Line 111:  cb2.layerMask = 0x00000110;  (green box -> camera 3 and camera 5 display)
Line 120:  cb3.layerMask = 0x00000111;  (blue box -> camera 1 and 3 and 5 display)

Do you understand how this "masking" works, when we use binary numbers like this?   I hope so, and I think it solves your issue.

Examine this, and if you have troubles, just ask.  Hope this helps.  Be well, good luck.

Link to comment
Share on other sites

  • 1 month later...

Still not working.  hmmm.

#2 in the series is working, though, so, it's all ok.  :)

sort of.

Lost all the layerMask changes/tests, though.  (sniff)

Hmm, @Temechon once offered to help me recover lost playgrounds.  I wonder if he has some magic faerie dust he can sprinkle.  hmm.  :) 

It's not a high priority, though (not important).  We're all good here, as long as Brijesh is cool.

Brijesh... do you have EXACT COPY of #4 playground?  That would be handy.  :)  (#4 is broken PG for me.)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...