Request for Text Rendering features in Graphics class

Request for Text Rendering features in Graphics class

alexisDVJML
Collaborator Collaborator
3,692 Views
22 Replies
Message 1 of 23

Request for Text Rendering features in Graphics class

alexisDVJML
Collaborator
Collaborator

Not sure the right place where to ask for these features, maybe by putting here can see how many of us would be interested 🙂

3D features:

- Rendering Text, similar to what is feasible in nwCreate: text at specific position, size and "plane"
- Filling polygon as long as all points are in one planes

2D features:
- Rendering Text with specific angle/orientation

- Filling Polygon

Main Scientist, Full Stack Developer & When Time Permits Director of IDIGO ► On your marks, Set, Go
3,693 Views
22 Replies
Replies (22)
Message 2 of 23

garylzimmer
Enthusiast
Enthusiast

Definitely agree with these requests! Right now if I render text inside a rectangle, the rectangle gets rendered on top of the text, which can make it harder to read. I wish there were a way to change the display order or set the z coordinate that the text was rendered at.

0 Likes
Message 3 of 23

alexisDVJML
Collaborator
Collaborator

I faced the same issue, here is what I do:

- for 3D rendering, I offset the text by 0.1mm following plane normal
- for 2D rendering, aka overlay,just draw in correct order
Hope this helps.


Main Scientist, Full Stack Developer & When Time Permits Director of IDIGO ► On your marks, Set, Go
0 Likes
Message 4 of 23

garylzimmer
Enthusiast
Enthusiast

Thanks for the advice! I just tried switching the order from text first then rectangle to the opposite. Now I'm getting weird behavior where if I look at my graphics from the top plan view, it looks great, but if I change the view to anything else the text disappears. It does still show if pivot the camera under the rectangles, but that's not very useful for me.

 

The documentation for rectangle says

"Renders a 2D rectangle in the XY plane at the current Z depth."

How can I change the current Z depth so that I could render the rectangles under my text?

0 Likes
Message 5 of 23

alexisDVJML
Collaborator
Collaborator

 I do not experience such weird issue when drawing in 2D aka overlay.

Drawing is done in the order of my instructions whatever the camera orientation.

 

Below simplified extract of my source code:

// g is the Graphics object received in Render(View aView, Graphics aGraphics) OR in  OverlayRender(View aView, Graphics aGraphics)

// start overlay
g.BeginWindowContext();

// draw rect
g.Color(Color.White, 0.8);
g.Rectangle(bottomLeft, topRight, true);

// draw text
g.Color(Color.Black, 1.0);
g.Text2D(mSettings.labelSettings.fs.fi, info.overlayLabel, Point2D.Origin, (int)x, (int)y+ 4);

// end overlay
g.EndWindowContext();

Note that:
- I enclose my calls in BeginWindowContext & CloseWindowContext

- I do my rendering in the Render method aver doing any 3D rendering
- I do not touch the Depth, not even sure what the methods DepthMask and DepthTest do 😉

Hope this helps.

Main Scientist, Full Stack Developer & When Time Permits Director of IDIGO ► On your marks, Set, Go
Message 6 of 23

garylzimmer
Enthusiast
Enthusiast

After trying out BeginWindowContext, it seems we're talking about different use cases. I'm rendering rectangles and text beneath my model at z = 0 in 3d space. I'm not using BeginWindowContext or BeginUserContext.

 

Thanks for your help though! These forums are kind of a graveyard of people looking for help and getting no responses.

0 Likes
Message 7 of 23

garylzimmer
Enthusiast
Enthusiast

Did some more reading of the API docs, it looks like Render defaults to model context which is what I'm talking about.

0 Likes
Message 8 of 23

alexisDVJML
Collaborator
Collaborator

Haha, not really a graveyard,

 

For your use case of drawing in 3D, I gave one solution earlier: offset the text by 0.1mm to the rectangle following plane normal.

 

 

Main Scientist, Full Stack Developer & When Time Permits Director of IDIGO ► On your marks, Set, Go
Message 9 of 23

alexisDVJML
Collaborator
Collaborator

BTW, there is  no Text drawing methods in 3D, at least as far as I know, thus my previous guess you were talking about 2D rendering.

 

Your extract "Renders a 2D rectangle in the XY plane at the current Z depth" refer to Rectangle(Point2D bottomLeft, Point2D topRight, bool filled) which is also a 2D overlay method.

 

Below example of combined 3D (cuboids with arrows) and 2D (labels near the cuboid and bottom summary) rendering we do in our plugin. We can render hundreds of these without noticeable lag 😉

Render 3D + 2D.png

 

So either I'm really amiss or my previous advises should work 😉

Main Scientist, Full Stack Developer & When Time Permits Director of IDIGO ► On your marks, Set, Go
Message 10 of 23

garylzimmer
Enthusiast
Enthusiast

I appreciate your continued help and find your screenshot very interesting!

I'm not using overlay mode in my example. I'm rendering in model context where everything is drawn at z=0.

In the first screenshots, I draw the text first, then the rectangles.

textfirstangle.PNGtextfirsttopdownperspective.PNG

In this the next screenshots, I render the rectangles first, then the text.textsecondangle.PNGtextsecondtopdownpersp.PNG

The rectangles are so dark because I lowered their transparency to 20% but the text still doesn't show through.
When you say:

"for 3D rendering, I offset the text by 0.1mm following plane normal"
Can you give me a code snippet? I don't understand how I can offset text in z-direction.

0 Likes
Message 11 of 23

alexisDVJML
Collaborator
Collaborator

Nice concept you got there !

 

Looking at your first screenshot (reproduced below), I finally understand what you want to achieve and maybe the reason/explanation for your issue.

Your screenshot:

textfirstangle.PNG

 

 

 

 

 

 

Looks like, please confirm, you use:
- Text2D(TextFontInfo fontInfo, string text, Point2D origin, int offsetX, int offsetY) for the text
- Rectangle(Point3D origin, Vector3D xVector, Vector3D yVector, bool filled) for the rect thus showing as a parallelogram at this angle

 

My understanding of the Rendering in Navisworks is:
- 3D methods, like Rectangle(Point3D origin...) render like the actaul 3D objects in the model,using clipping, culling etc
- 2D methods are actually Overlay methods withotu any depth per se

 

In addition, while not explicitly documented, I 'm assuming:

- 3D methods should be enclosed by BeginModelContext/EndModelContext (but most probably not needed if called from Render(View view, Graphics graphics) since this should be the current context)

- 2D methods should be enclosed by BeginWindowContext/EndWindowContext(but most probably not needed if called from OverlayRender(View aView, Graphics aGraphics) since this should be the current context)

 

Now back to your use case, I would guess:
- you do all the rendering in the Render(View aView, Graphics aGraphics) method
- you call alternatively Text2D and Rectangle(3D....)
Thus the things get messed up

 

If I understood correctly above, you do not need any trick to offset some part, instead you could try something like the following pseudo-code in Render(View aView, Graphics aGraphics:

BeginModelContext();
for (int i = 0; i != areasCount; i++)
    Rectangle(area[i].position...);
EndModelContext();

BeginWindowContext();
for (int i = 0; i != areasCount; i++)
    Text2D(area[i].name...);
EndWindowContext();
Main Scientist, Full Stack Developer & When Time Permits Director of IDIGO ► On your marks, Set, Go
Message 12 of 23

garylzimmer
Enthusiast
Enthusiast

Very close! Text2D is correct, but I'm using 

Rectangle(Point2D, Point2D, Boolean) "Renders a 2D rectangle in the XY plane at the current Z depth."

in the screenshots. That's why I was wondering what "current Z depth" meant and how if possible I could change that.

 

I think the issue maybe because I'm drawing two objects on the same z-plane so it renders awkwardly. I think I may try to change to the 3d rectangle method that you mentioned, that way I can set the origin in a lower z coordinate than the text.

 

For the 3D version of the rectangle method, it mentions the origin of the rectangle. Is that located at a corner of the rectangle or the center of the rectangle? 3d vectors confuse me a bit.

0 Likes
Message 13 of 23

alexisDVJML
Collaborator
Collaborator

Wondering how you manage to draw parallelogram at the visually correct position using Rectangle(Point2D, Point2D, Boolean) 😉

for Rectangle(Point3D,...) the initial point is at the corner, than you need to provide the correct vectors for the directions in 3D. I'm not at my dev station right now.

Note that when you draw in 3D, these are real 3D and thus for example will be hidden/clipped if you have object in front of them, which can be what you want or not.

 

Drawing in 2D has no z-order as far as I know, just follow your drawing instructions order.
Did you try to draw all rectangles in a first loop and then all texts in a second look all part of one single Render or RenderOverlay?

Main Scientist, Full Stack Developer & When Time Permits Director of IDIGO ► On your marks, Set, Go
Message 14 of 23

garylzimmer
Enthusiast
Enthusiast

How did you draw the arrows in your plugin? I see the BeginPolygon and BeginComplexPolygon methods, but they aren't very intuitive. What is VertexProperties?

 

Could you add text to your cuboids if you wanted to? I've found that the "feature" of always having 2D text face the viewer to be annoying to deal with. I wish I could keep text flat to my rectangles.

0 Likes
Message 15 of 23

alexisDVJML
Collaborator
Collaborator

1/ Arrows in 3D:
I use a combination of Graphics.Triangle(3D) and Graphics.Rectangle(3D): single direction arrow = 1 rectangle + 1 triangle, dual arrow = 2 triangles and one rectangle

I experimented a little with the Polygon related methods but didn't manage to have them filled even they were closed polygon with all vertex in a plane.

 

2/ Text in 3D:

There is 3D method equivalent to Draw Text. I have in my To-Do list a task of implementing such drawing "manually" by using Windows Font, tesselating and drawing triangles but this is not yet on top of my to-do list, thus my request to add this to the API.

Main Scientist, Full Stack Developer & When Time Permits Director of IDIGO ► On your marks, Set, Go
0 Likes
Message 16 of 23

garylzimmer
Enthusiast
Enthusiast

I was looking into ways to convert text to vertexes in C# and the only way I can find was formatted text (using WPF)

I haven't tried it yet, since all I know is WinForms and there's a bit of a learning curve.

0 Likes
Message 17 of 23

garylzimmer
Enthusiast
Enthusiast

@alexisDVJML wrote:

2/ Text in 3D:

There is 3D method equivalent to Draw Text. I have in my To-Do list a task of implementing such drawing "manually" by using Windows Font, tesselating and drawing triangles but this is not yet on top of my to-do list, thus my request to add this to the API.


Did you ever figure this out? It would be super useful to include in my program!

0 Likes
Message 18 of 23

garylzimmer
Enthusiast
Enthusiast

I found some resources on tessellation in C# but the examples are over my head. With enough work, couldn't you do filled in polygons by tessellating the polygons and drawing 2d or 3d filled-in triangles?
https://github.com/speps/LibTessDotNet

0 Likes
Message 19 of 23

garylzimmer
Enthusiast
Enthusiast

Sorry to keep blowing up this post, but I figured out how to do filled in polygons!

 

VertexProperties vProp = VertexProperties.HasColors;	

					graphics.BeginPolygon(vProp);					

graphics.VertexColor(color, transpancy);

foreach (Point3D p3d in zone.pointList)

{								

graphics.Vertex(p3d);

}

graphics.EndPolygon();					

Autodesk.Navisworks.Api.Application.ActiveDocument.ActiveView.RequestDelayedRedraw(ViewRedrawRequests.Render);

 

 

Message 20 of 23

garylzimmer
Enthusiast
Enthusiast

Furthermore, just so this information is on the internet. I avoided the text and polygon clipping issues by having the text be projected onto the overlay render layer and the polygon on the model space.

 

EDIT: What's funny is that you complained you couldn't get the polygons to fill in, but I can't get them to not fill in!

AND I can't get transparency to work like it did for the rectangles! I think the issue is that the render method is constantly getting called and drawing more polygons on top of each other making them opaque instead of transparent. Not sure how I can solve this one...