Page Index Toggle Pages: 1 Send TopicPrint
Hot Topic (More than 10 Replies) Rendering of nodes in DiagramView3D (Read 5326 times)
Rennie
Full Member
***
Offline


I Love MindFusion!

Posts: 108
Location: Copenhagen, Denmark
Joined: Jul 17th, 2012
Rendering of nodes in DiagramView3D
Mar 17th, 2013 at 1:28am
Print Post  
As you may know, I've created a floorplan application using your program. One of the problems I ran into was that until the latest version the ruler did not support real-world measurements like meters and feet. This is/was a symptom of the fact that your program is not really intended for drawing real-world objects, which is fair enough since you're not advertising it as a CAD program.

Now I'm hoping to (mis)use your program even more. I intend to add a building planner view to my floorplan program, which should show a wireframe-like view of a building with composite nodes representing the floors. This should be viewed using the DiagramView3D viewer, with the camera typically looking at the building from about 30 degrees above the ground and 45 degrees from straight-on, i.e., looking at a corner of the building.

As far as I can determine, DiagramView3D does not render the nodes according to the angle of the camera. The size of the node is adjusted according to camera distance, but nothing else - all the nodes are shown as face-on, irrespective of the camera angle. This is not usable for nodes that represent real-world objects - they should be rendered tilted according to the camera angle.

What to do? Is there some way to make DiagramView3D render nodes according to camera angle? Is there some way that I can change the rendering of the nodes to take the camera angle into account?

Thanks.
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Rendering of nodes in DiagramView3D
Reply #1 - Mar 18th, 2013 at 8:18am
Print Post  
Hi,

DiagramView3D applies a perspective projection, but nodes are treated as 2D objects and always rendered face-on since they don't store any additional vertex positions nor normal vectors that would let the control draw them at an angle.

If all you need is a wireframe view, you could use DiagramLink objects to render it. E.g. build a mesh for each node from the floor plan, consisting of small nodes to use as wall vertices and links representing the wireframe edges. The floor vertices of the mesh should have the same coordinates as the node corners, however with 3D Z containing the 2D Y position and 3D Y set to 0, and then add four more ceiling vertices at same X,Z as floor counterparts and 3D Y set to the height you want for the wall.

If you need a full 3D view with proper lighting, textures, etc, check http://www.unity3d.com/. Unity lets you add objects to the scene dynamically, so you could export the coordinates for your 2D floor plan to some text file, then load it into the Unity app and create corresponding 3D objects by adding height to the floor plan objects. E.g. you can create a wall object using code like this (adapted from a personal project of mine Smiley):

Code
Select All
GameObject wall = GameObject.CreatePrimitive(PrimitiveType.Cube);
wall.name = "wall1";
wall.transform.position = new Vector3(nodeCenter.X, wallHeight/2, nodeCenter.Y);
wall.transform.localScale = new Vector3(nodeWidth, wallHeight, nodeHeight);
wall.renderer.material = wallMaterial; 



I hope that helps,
Stoyan
« Last Edit: Mar 18th, 2013 at 7:18pm by Stoyo »  
Back to top
 
IP Logged
 
Rennie
Full Member
***
Offline


I Love MindFusion!

Posts: 108
Location: Copenhagen, Denmark
Joined: Jul 17th, 2012
Re: Rendering of nodes in DiagramView3D
Reply #2 - Mar 19th, 2013 at 12:12am
Print Post  
Thanks for your reply. I'll see what I can do with using four DiagramLink items to represent a floor in the building.
  
Back to top
 
IP Logged
 
Rennie
Full Member
***
Offline


I Love MindFusion!

Posts: 108
Location: Copenhagen, Denmark
Joined: Jul 17th, 2012
Re: Rendering of nodes in DiagramView3D
Reply #3 - Mar 19th, 2013 at 3:02am
Print Post  
Stoyan,

I don't know what I'm doing wrong, but I simply can not get an unconnected link to display in the DiagramView3D. I can display nodes and connected links, but not unconnected links.

Could you please post a code snippet showing an example of how to create an unconnected link that shows up in a DiagramView3D?

Thanks.
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Rendering of nodes in DiagramView3D
Reply #4 - Mar 19th, 2013 at 6:32am
Print Post  
You will have to use connected links with small nodes representing the mesh vertices (make them transparent / invisible if you don't want them to be shown). That's necessary because links don't store any 3D location information but are only drawn as straight lines connecting the projected 3D locations of their Origin and Destination nodes.
  
Back to top
 
IP Logged
 
Rennie
Full Member
***
Offline


I Love MindFusion!

Posts: 108
Location: Copenhagen, Denmark
Joined: Jul 17th, 2012
Re: Rendering of nodes in DiagramView3D
Reply #5 - Mar 19th, 2013 at 11:33am
Print Post  
OK, I'll give it a try.

But I don't understand why unconnected links can't be projected by the 3D viewer. They have x-y coordinates for each end, and I did associate a LayoutTraits object with the link, like this:

Code
Select All
diagramLink.LayoutTraits[View3D.Position] = new Point3D(x, y, z);
 



I wasted a hell of a lot of time trying to get it to work. Sounds like a bug to me.

Edit:
And all those unnecessary nodes! How inefficient! How inelegant! How, how, how ... ugh!   Cry
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Rendering of nodes in DiagramView3D
Reply #6 - Mar 19th, 2013 at 11:48am
Print Post  
The 2D coordinates for each end mean nothing to the 3D viewer, and obviously a single LayoutTraits[View3D.Position] won't let you specify 3D positions for both ends. Its current implementation relies on actual nodes positions, so you cannot avoid them at this time.
  
Back to top
 
IP Logged
 
Rennie
Full Member
***
Offline


I Love MindFusion!

Posts: 108
Location: Copenhagen, Denmark
Joined: Jul 17th, 2012
Re: Rendering of nodes in DiagramView3D
Reply #7 - Mar 19th, 2013 at 11:53am
Print Post  
Oops - I edited my reply at same time as your reply.

Yes, the single LayoutTraits[View3D.Position] implies the same Z value for both ends, and I can see that is a major limitation on the use of unconnected links. So I'll accept the situation and learn to live with it.   Huh
  
Back to top
 
IP Logged
 
Rennie
Full Member
***
Offline


I Love MindFusion!

Posts: 108
Location: Copenhagen, Denmark
Joined: Jul 17th, 2012
Re: Rendering of nodes in DiagramView3D
Reply #8 - Mar 19th, 2013 at 12:35pm
Print Post  
PS. Just in case you do consider making some improvements in this area, then I'd prioritize the option of rendering node objects according to camera angle even higher than including unconnected links in the 3D view.
  
Back to top
 
IP Logged
 
Rennie
Full Member
***
Offline


I Love MindFusion!

Posts: 108
Location: Copenhagen, Denmark
Joined: Jul 17th, 2012
Re: Rendering of nodes in DiagramView3D
Reply #9 - Mar 19th, 2013 at 1:06pm
Print Post  
Sorry about going on and on about this. But would it be feasible to use the ShapeNode.CustomDraw feature for me to draw the node tilted according to camera angle?

Edit: Are there examples of using this feature in your samples library?
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Rendering of nodes in DiagramView3D
Reply #10 - Mar 20th, 2013 at 7:40am
Print Post  
What you could do is to draw projected lines yourself from the view3D.Paint event handler with the help of PointToClient(Point3D) method:

Code
Select All
private void diagramView3D_Paint(object sender, PaintEventArgs e)
{
	var cube = new[]
	{
		new Point3D(00, 00, 00),
		new Point3D(10, 00, 00),
		new Point3D(10, 00, 10),
		new Point3D(00, 00, 10),
		new Point3D(00, 10, 00),
		new Point3D(10, 10, 00),
		new Point3D(10, 10, 10),
		new Point3D(00, 10, 10)
	};

	for (int i = 0; i < 4; i++)
		DrawEdge(e.Graphics, cube[i], cube[(i + 1) % 4]);
	for (int i = 0; i < 4; i++)
		DrawEdge(e.Graphics, cube[i + 4], cube[(i + 1) % 4 + 4]);
	for (int i = 0; i < 4; i++)
		DrawEdge(e.Graphics, cube[i], cube[i + 4]);
}

private void DrawEdge(Graphics g, Point3D p1, Point3D p2)
{
	var cp1 = diagramView3D.PointToClient(p1);
	var cp2 = diagramView3D.PointToClient(p2);
	g.DrawLine(Pens.Black, cp1, cp2);
} 



You will also need to implement some kind of Z culling - i.e. do not draw a line when any of its points is behind the camera of you will get strange results.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint