PDA

View Full Version : Viewport Drawing Methods - gw.hPolygon, gw.hPolyline etc..


C00PER
12-08-2004, 01:49 PM
Hi. I have some questions regarding those GW. functions described in Viewport Drawing Methods. First - I can't figure out, why example showed in that chapter doesn’t work correctly. Here's the code:


-- Draw some primitives
gw.hPolyline #([300,50,16], [300,200,8], [450,250,4]) true
--
gw.hPolygon #([200,100,16], [280,100,8], [250,200,4]) \
#(red, blue, green) \
#([1.0,.5,0], [0.5,0.5,0], [0,0,0.5])
--
gw.hTriStrip #([50,50,0], [175,100,0], [25,100,0], [150,250,0]) \
#(red, blue, green, white) \
#([1.0,.5,0], [0.5,0.5,0], [0,0,0.5], [0.5,1,0])
--
-- Update the viewports
gw.enlargeUpdateRect #whole
gw.updateScreen()



This should draw 3 figures – Polyline, Polygon and TriStrip (not actually sure what TriStrip is). However it draws only hPolyline. After hour of experiments I found out that after switching video driver to Software mode hPolygon figure is finally drawn, but hTriStrip is not. So where's the catch?

Second question – How can I clear all previously drawn fiures during drawing of another figure? I am trying to make something similar to Render Region frame, not so complicated of course, it will be a simple rectangle without fill, with top left corner in the point of first click and bottom right corner in the point of mouse cursor. This rectangle should redraw when mouse moves, however all I can do is either leave previously drawn rectangle and add new ones and create a mess, or complecely clear specified region using gw.clearScreen <Box2>, so there will be only flat color. But I need to see objects below frame! Of course I can include completeredraw() command but it is so slow that it makes no sence to use those fast GW functions.. There should be a way to erase drawn figure but leave underlying viewport image

Here is the simple loop that draws a line with moving second point. How to erase old line without using completeredraw() and at the same time not loose viewport cotents?


mypoint1 = [50,80,0]
mypoint2 = [200,200,0]

for i = 1 to 200 do
(
gw.wPolyline #([mypoint1.x,mypoint1.y,10], [mypoint2.x,mypoint2.y+i,10]) true
gw.enlargeUpdateRect #whole
gw.updateScreen()
)



Thanks in advance.

Bobo
12-08-2004, 07:01 PM
gw.hTriStrip #([50,50,0], [175,100,0], [25,100,0], [150,250,0]) \
#(red, blue, green, white) \
#([1.0,.5,0], [0.5,0.5,0], [0,0,0.5], [0.5,1,0])

This feature has been disabled for some unknown reason.
There is no workaround except for drawing full polygons instead.


Second question How can I clear all previously drawn fiures during drawing of another figure?
As far as I can tell, you cannot erase a line, you have to update the view.
If you are using DualPlanes, you can flag all objects as background and then the redraws should theoretically just swap the background plane's DIB content, effectively drawing only your polylines on top of a bitmap...
I have not tested this though.


See
MAXScript Reference > Frequently Asked Questions > How To Make It Faster:
Use the 'flagForeground' node viewport state method.

The 3ds max graphics pipeline can use a dual plane technique for speeding up viewport redraws. When only few objects are changing, the graphics subsystem can take a snapshot of the viewport DIB bitmap showing only the non-changing objects which are flagged as background. After that, the graphics pipeline evaluates only the changing objects and draws on top of the background bitmap. These objects are internally flagged as foreground.

The flagForeground method controls the disposition of scene nodes in the viewport foreground/background planes, so you can influence interactive performance on a node. Nodes placed in the foreground plane are redrawn individually and so interactive changes to them through spinners in scripted rollout panels are much faster.

C00PER
12-09-2004, 03:57 AM
Thanks for the reply, Bobo. Unfortunaly this flagForeground method can't help me in any way. Or maybe I am just doing something wrong.. As far as I understand, this should be used to speedup redrawing of nodes that are changed by script, and I do not change any nodes.. I am manipulating completely different system. :hmm:

However, I found a way of efficient use of the completeredraw() command. I create a simple counter in the function that updates rectangle. When it reaches say 10 it calls completeredraw() command and then resets itself, so it redraws every tenth cycle.. I think that’s pretty enough at this moment. Thank you.

C00PER
12-09-2004, 04:42 AM
Hey! I guess I found simple and genius way to update ONLY a drawn frame :D There is a nodeInvalRect <node> command which specifies a node that should be redrawn with RedrawViews command. If you didn’t call a nodeInvalRect <node> before RedrawViews, it will redraw nothing… Guess what we supply as a node for invalidation? Our camera haha! And it works! 10 times faster than completeredraw()! However I noticed that it works well only when camera is selected…..But what if we are looking through perspective view, not camera hmm.. maybe creating of temporary dummy aligned to camera center will help.

-------
edit: Just tried this trick with dummy, aligned to (inverse (getviewtm())) and it works.. Speedup is dramatic and viewport contents are not lost. Cool! I guess this method shoud be included in Maxscript reference in How to make it faster haha :) now back to my script..

CGTalk Moderation
01-20-2006, 02:00 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.