Notifications
Clear all

[Closed] Remove selected objects that are not actually visible in the current view

There might not be a good way to do this, but very often I want to exclude selected objects that are not actually visible for me in my current view. I know about the flag “isHiddenInVpt”, but that doesn’t work if the objects are not visible because they’re behind another object (attached image):

There objects aren’t really hidden, but they are “hidden” to me because they’re behind another object. Is there any way of determining if an object is actually not visible to me because it’s behind another object?

21 Replies
4 Replies
(@denist)
Joined: 10 months ago

Posts: 0

May I ask what it is for?
I want to hear all the arguments for this… and probably each of them I can question, or can suggest another, possibly simpler solution.

I can understand Klvnk doing this purely for fun… but what’s the practical use of it?

I remember back in the early days of the gaming industry we did this to exclude objects from rendering that weren’t in the camera… but we didn’t have GPU render and Z-buffer at that time. Well, why now?

(@jimmyvera)
Joined: 10 months ago

Posts: 0

Of course I often receive CAD models from customers, and when they want me to create animations/presentations for their products they rarely need to showcase anything “inside” of the model (the hidden parts). So lets say I receive a CAD model of some kind of machine which consists of several million polys, these models often have a lot of small and really dense/heavy geometry that’s inside of the model (which I don’t need). Removing these objects is often necessary for me to be able to work with the models without lag.

On many models it’s pretty easy to just manually select the “shell” of the model, then invert and delete. However, more often than not this process can be a bit more work than I’d like. If I could save some minutes for each model (in some cases more than minutes) it would definitely help, so it’s just an attempt to improve my workflow

Another use-case would be a pure general (maybe just a personal) workflow improvement, which would be to link the script to a hotkey that de-selects anything not visible in the current view. When working in and out of isolation mode it would just serve as a practical option.

Just to be clear though, I do practice workarounds. I could roughly split the model into different display layers and animate part for part. But still, it’s not optimal as I have to be careful to consider parent/child relationships etc. I’ve been able to do this without a script such as I’m asking for for years, but I’ve started to realize that I have to start addressing possible workflow improvements.

However, there might definitely be some tricks you could think of that could help, so I’m very open to hear what you think could be an alternative to a script similar to what miauu is working on?

Oh, and on another (random) note; How do you quote posts? I feel like a toddler when using this forum some times, I’m not able to search, and I don’t even know how to quote a post properly

(@miauu)
Joined: 10 months ago

Posts: 0

Select the text you want to quote from the comment you want to quote and either hit the “Reply” button under the quoted post or hit the “Quote” label which appears above the selected text.

Searching… no one can help you here.

My tool is ready.
There are few more stuff which I will release in the next versions:

  • speed improvement
  • select objects which are partially covered by the obstacles
  • option to select layers of visible objects(first layer contains all objects you see, second layer contains all objects which you can see when the level1 objects are removed ans so on).
(@jimmyvera)
Joined: 10 months ago

Posts: 0

I can’t believe I’ve never noticed the quote-option when selecting text

Awesome, I’m excited to test it I’ll let you know how it works when I receive the download instructions

disable textures, switch viewport shading to flat, get viewport bitmap and check pixel by pixel which wirecolors are visible. simple as that
of course it requires that objects have unique wirecolors

Wow, the creativity of you and a few others in here never seizes to amaze me, that’s a really clever idea. You don’t happen to know if something like this has been posted in here before? Or maybe something similar that I could use as reference when trying to write this script myself?

there certainly were scripts posted that separately solve parts of the task, but it is likely that you will faster code it yourself than find something with forum search broken
You’ll have to make sure to disable safe frames, stats, make viewport background flat-colored etc… in order this workaround to actually work.

I am currently working on a script which does exactly the same. Will be released as soon as possible.
Short video: https://drive.google.com/file/d/1mXedFqmaffEU-60MpXVdNqGxtI-tVAsn/view?usp=sharing

Oh, awesome! I’m curious, are you using the pixel method, or have you been able to figure out another method? The reason I ask is that I did some tinkering with the pixel method, and it kinda works, but it wasn’t completely accurate. I guess I would have to increase the resolution to increase the accuracy, but that would mean I would have to render the current view.

I am using few methods.
Here is another video. Almost everything that I need is already added:
https://drive.google.com/file/d/16S5hnyJNtE3xSMYZrTkCEUI3aeskVIs9/view?usp=sharing

It looks awesome, really excited to test it when you’re finished. I have to say, you amongst a few others in here have contributed and helped so many people, thank you!

this sort of thing works after a “fashion”

   fn getScreenBounds obj =
    (
    	maxy = maxx = -99999999.0;
    	miny = minx = 99999999.0;
    	
    	gw.setTransform(Matrix3 1);
    	
    	msh = snapshotasmesh obj;
    	for v = 1 to msh.numverts  do
    	(
    		spos = gw.wTransPoint (getvert msh v);
    		if spos.x > maxx then maxx = spos.x;
    		if spos.x < minx then minx = spos.x;	
    		if spos.y > maxy then maxy = spos.y;
    		if spos.y < miny then miny = spos.y;	
    	)
    	delete msh;
    	
    	Box2 minx miny (maxx - minx + 1) (maxy - miny + 1)
    )

    fn boxinbox b1 b2 =
    (
    	return contains b1 [b2.left, b2.top] and contains b1 [b2.right, b2.top] and contains b1 [b2.right, b2.bottom] and
    				contains b1 [b2.left, b2.bottom];
    )	

    fn IsObscured node1 node2 camera_pos =
    (
    	msh = snapshotasmesh node2;
    	
    	obscured = true;
    	for v = 1 to msh.numverts while obscured do
    	(
    		pos = getvert msh v;
    		dir = camera_pos - pos;
    		
    		if intersectray node1 (ray pos dir) == undefined then obscured = false;
    	)
    	
    	delete msh;
    	obscured;
    )	

    fn comp_node_depth v1 v2 =
    (
    	x1 = v1[2].x;
    	x2 = v2[2].x;

    	if x1 == x2 then 0 else if x1 > x2 then -1 else 1;
    )	

    fn getNodesInDepthOrder tm =
    (
    	nodes = for obj in objects collect #(obj, obj.pos * tm, getScreenBounds obj);	
    	qsort nodes comp_node_depth; 
    	nodes	
    )	

    fn hide_obscured =
    (
    	ivptm = inverse (getViewTM());
    	
    	nodes = getNodesInDepthOrder ivptm;
    	
    	for n = 1 to nodes.count - 1 do
    	(
    		unhide 	nodes[n][1];
    		
    		obscured = false
    		for nn = n + 1 to nodes.count while not obscured do
    		(
    			if boxinbox nodes[nn][3] nodes[n][3] then
    				obscured = IsObscured nodes[nn][1] nodes[n][1] ivptm[4];
    		)
    		if obscured then hide nodes[n][1];
    	)
    )	


    UnRegisterRedrawViewsCallback hide_obscured
    RegisterRedrawViewsCallback hide_obscured

This line

should be

pos = getvert msh v;

or a msh2 variable has to be used?

With this the script works fine: pos = getvert msh v;

Page 1 / 2