Trouble with Enhanced OpenGL display
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 19/07/2012 at 06:23, xxxxxxxx wrote:
I finished my first python tag and it is working fine, except for the fact that it garbles the display in Enhanced OpenGL mode.
Check out the video:Is there any solution for this?
Thank you very much in advance.Rui Batista
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 19/07/2012 at 08:46, xxxxxxxx wrote:
Ok, I found out that I should use DrawLine instead of DrawLine2D.
But since I must provide world coordinates (that is fine), the drawing is always performed on a 2D plane aligned with the XY plane of the object.
How can I make my drawings appear at the world position of the points but always face the camera?Rui Batista
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 19/07/2012 at 18:59, xxxxxxxx wrote:
Here is a video with the problem I'm having:
Is there any way to use DrawLine but make it behave like DrawLine2D?
Because DrawLine2D doesn't work fine with OpenGLRui Batista
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 20/07/2012 at 12:18, xxxxxxxx wrote:
Anyone?
Never thought it could be so complicated -
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 20/07/2012 at 12:57, xxxxxxxx wrote:
Could you show a little of the code that actually draws the text?
-Nik
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 20/07/2012 at 14:15, xxxxxxxx wrote:
Sure
The actual code that draws the lines is:
def draw_atom(d,pos,coords,scale,up,bd) :
# d is the digit to draw (0-9)
# pos is the position if the digit inside the number (0 to the number of digits that the number has)
# coords is the coordinates in world space where to draw the number
# scale is the scaling value to draw the numbers in varying sizes
# up is the value to add to the Y coordinate so that the numbers don't overlap the point handles
# bd is the BaseDraw
number=numbers[d] # get the list with the numbers coordinates
n=len(number)
pos2=pos*100*scale # calculate the position
for f in range(0,n-1) :
# calculate the coordinates
p1=c4d.Vector(pos2+number[f][0]*scale,number[f][1]*scale-up,0)
p2=c4d.Vector(pos2+number[f+1][0]*scale,number[f+1][1]*scale-up,0)
# draw the lines that compose the number
bd.DrawLine(coords+p1,coords+p2,c4d.NOCLIP_Z)
returnBut, before calling this, I set the drawing matrix with:
bd.SetMatrix_Matrix(op, op.GetMg(),5)
I know the problem should be in the matrix setting but I really don't know how to solve this.
Oh, the coords that are fed into the draw_atom procedure are derived from the world position of the vertexes of the object, with:coords=op.GetPoint(idd)*op.GetMg()
Thank you for checking this
Rui Batista
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 21/07/2012 at 07:34, xxxxxxxx wrote:
An option is to convert object point positions to camera space and calculate the DrawLine() start and end points there.
This example draws a '4' on the fourth point of an object. It always faces the camera and maintains a constant size when zooming and resizing viewports.
It currently works for the perspective and parallel cameras and the standard orthographic views (not Axonometric).
Let me know of any issues if you end up using it.
//------------------------------------------------
def RotateMatrix(m, rot) :
pos = m.off
scale = c4d.Vector(m.v1.GetLength(), m.v2.GetLength(), m.v3.GetLength())
m = utils.HPBToMatrix(rot)
m.off = pos
m.v1 = m.v1.GetNormalized() * scale.x
m.v2 = m.v2.GetNormalized() * scale.y
m.v3 = m.v3.GetNormalized() * scale.z
return m
def RotationOffset(proj) :
if proj is c4d.Pright: rotOffs = c4d.Vector(utils.Rad(90), 0, 0)
elif proj is c4d.Pleft: rotOffs = c4d.Vector(utils.Rad(-90), 0, 0)
elif proj is c4d.Ptop: rotOffs = c4d.Vector(0, utils.Rad(-90), 0)
elif proj is c4d.Pbottom: rotOffs = c4d.Vector(0, utils.Rad(90), 0)
elif proj is c4d.Pback: rotOffs = c4d.Vector(utils.Rad(180), 0, 0)
else: rotOffs = c4d.Vector(0, 0, 0)
return rotOffs
def ViewSize(doc, bd) :
frame = bd.GetFrame()
frameWdth = frame['cr']
frameHght = frame['cb']
rd = doc.GetActiveRenderData()
x_res = rd[c4d.RDATA_XRES_VIRTUAL]
y_res = rd[c4d.RDATA_YRES_VIRTUAL]
aspRat = y_res / x_resif float(frameHght) / frameWdth >= aspRat:
viewSize = float(frameWdth)
else:
viewSize = (1.0 / aspRat) * frameHghtreturn viewSize
class PyDrawTest(plugins.TagData) :
def Init(self, tag) :
return Truedef Draw(self, tag, op, bd, bh) :
doc = documents.GetActiveDocument()
camera = bd.GetSceneCamera(doc)
if camera is None: camera = bd.GetEditorCamera()
mCam = camera.GetMg()
bd.SetPen(c4d.Vector(1.0, 1.0, 1.0))
proj = bd.GetProjection()
if proj is not c4d.Pperspective and proj is not c4d.Pparallel:
mCam = RotateMatrix(mCam, RotationOffset(proj))
bd.SetMatrix_Matrix(camera, mCam, 4)
points = op.GetAllPoints()
pt_g = op.GetMg() * points[4]
pt = ~mCam * pt_g
defaultFlen = 36.0
viewSize = ViewSize(doc, bd)
scale = 1000.0if proj is c4d.Pperspective:
zoom = camera[c4d.CAMERA_FOCUS] / defaultFlen * viewSize * 1000.0
else:
zoom = camera[c4d.CAMERA_ZOOM] * pt.z * viewSizenumber = [[0, 0], [0, 20], [-8, 10], [4, 10]]
n = len(number)
for x in xrange(n - 1) :
offs1_x = number[x][0] * pt.z * scale / zoom
offs1_y = number[x][1] * pt.z * scale / zoom
offs2_x = number[x+1][0] * pt.z * scale / zoom
offs2_y = number[x+1][1] * pt.z * scale / zoom
p1 = c4d.Vector(pt.x + offs1_x, pt.y + offs1_y, pt.z)
p2 = c4d.Vector(pt.x + offs2_x, pt.y + offs2_y, pt.z)bd.DrawLine(p1, p2, c4d.NOCLIP_Z)
return True//------------------------------------------------
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 21/07/2012 at 10:38, xxxxxxxx wrote:
Thanks for posting that David.
But I don't get any result from it. It doesn't draw anything.I don't think the problem is with your code. Because I can make it work in the py-DoubleCircle ObjectData plugin example just fine.
The problem is that tag's seem to need something else to draw that isn't listed in your code. And I can't figure out what that is.Much Simpler Example:
def Draw(self, tag, op, bd, bh) : doc = documents.GetActiveDocument() bd.SetMatrix_Screen() bd.SetPen(c4d.Vector(1.0, 1.0, 1.0)) bd.DrawLine(c4d.Vector(0,0,0), c4d.Vector(200,200,0), c4d.NOCLIP_Z) return True
This simple code should draw a simple line on the screen. But it doesn't.
Something is missing. And I can't find it.
Do you have a simpler example like this of just drawing a simple line using a tag plugin?-ScottA
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 21/07/2012 at 17:20, xxxxxxxx wrote:
Thank you very much, David.
After some fiddling to adjust it to my structure, I finally made it work.
Except... for the orthogonal views. For some reason, it is not drawing the numbers on the orthogonal views, only on the perspective view. Not even in the parallel perspectives... just on the perspective view -
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 21/07/2012 at 18:25, xxxxxxxx wrote:
That's a drag. Here's the plugin and test scene I've been using. Hopefully this will be enough for you to shoehorn it into your plugin. Otherwise, perhaps the solution posted today in SDK Help will work.
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 21/07/2012 at 18:49, xxxxxxxx wrote:
Got it working!!!
Thank you very, very much, David.
Now, on to optimizing the speed.Rui Batista
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 21/07/2012 at 20:14, xxxxxxxx wrote:
Good to hear!
Originally posted by xxxxxxxx
The problem is that tag's seem to need something else to draw that isn't listed in your code. And I can't figure out what that is.
See how you go with my uploaded example Scott. Hopefully this will work for you as well.
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 21/07/2012 at 22:18, xxxxxxxx wrote:
Thanks for the file David.
I had an indentation problem in my code using your draw method. But the stupid console wasn't picking it up. And it actually ran the plugin even though the indentation was wrong!After playing around with this. I think I know why my small example doesn't.
I think it's because I'm trying to use SetMatrix_Screen(). And that function might require width and height variables to work.Everything works fine using bd.SetMatrix_Matrix(camera, mCam, 4).
But that ties the lines being drawn to the object. And I was trying to draw lines on the screen, not tied to any object using a tag.
I can do this in C++ using the GeClipMap() class(although the text is still a background object and I can't figure out to make it a foreground object). So That might be the way I'll have to do it in Python too.-ScottA
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 23/07/2012 at 00:54, xxxxxxxx wrote:
No worries Scott.
Width and height variables aren't necessary when using screen space coordinates. BaseView.WS() will convert coordinates from world to screen space for you.
I've found the BaseDraw 2D drawing functions to be much faster than GeClipMap. Also, reliably drawing in the foreground can be done using these functions with a SceneHookData plugin. Unfortunately this class isn't currently supported in the Python SDK.