Adam's Lair Forum

game development and casual madness
It is currently 2018/08/18, 23:48

All times are UTC + 1 hour [ DST ]




Post new topic Reply to topic  [ 6 posts ] 
Author Message
PostPosted: 2018/03/08, 23:29 
Newbie
Newbie

Joined: 2018/03/08, 22:08
Posts: 4
Role: Hobbyist
How can you draw a procedural mesh from vertices? I have been able to draw a triangle using FillPolygon in Canvas calling a IDrawDevice. But that draws in front of every thing and it doesn't look like its affected by anti aliasing. Thank you for the help.


Top
 Profile  
 
PostPosted: 2018/03/09, 11:29 
Forum Addict
Forum Addict
User avatar

Joined: 2013/09/19, 14:31
Posts: 872
Location: Italy
Role: Hobbyist
Hi, and welcome to the gang! :mrgreen:

First of all, what are you trying to do, and what are your inputs?
Do you already have your procedural mesh as, say, a set of points? triangles? or are you looking for a way to generate your mesh as well?
Second, have you already read something about custom drawing? (i.e. do you know the difference between DrawingGroups, Overlay and such?)

If you prefer, feel free to also post your code and we'll take a look.
Good luck! :D

_________________
Come on Duality's Discord channel. We have cookies! :mrgreen:


Top
 Profile  
 
PostPosted: 2018/03/09, 16:01 
Newbie
Newbie

Joined: 2018/03/08, 22:08
Posts: 4
Role: Hobbyist
Thank you for the warm welcome. Ive only been working with Duality for a couple of days but I really enjoy it. I would like move from another open source C# engine to duality. Ive been running into issues that I cant seem to fix with mesh drawing. Its not drawing the vertices in the correct location. Ive also moved it to Monogame, it works well and runs so fast but I feel like everything is a struggle with it. GUIs, screen management etc.

The input would be a set of vertices which would end up drawing a mesh made of triangles to screen. So yes I am looking to generate the mesh too. I have been reading through the source code, looking at the examples and reading the wiki, but I have not come across DrawingGroups or Overlays. If you could point me in the right direction that would be great.

Thanks for the help,
Ron


Top
 Profile  
 
PostPosted: 2018/03/09, 19:45 
Site Admin
Site Admin
User avatar

Joined: 2013/05/11, 22:30
Posts: 2055
Location: Germany
Role: Professional
Hey there, and welcome! ^^

Long story short, it sounds like what you're after is implementing a custom renderer. There's a Wiki article on that, which should explain some basic concepts and also provide a few examples that you might be able to adapt.

Quote:
Ive been running into issues that I cant seem to fix with mesh drawing. Its not drawing the vertices in the correct location.

Can you show us your code and maybe take a screenshot of what the result looks like when rendered? Maybe we can point you into the right direction, and judging by the fact that you already saw something, you're probably not that far off from the right approach :)

_________________
Blog | GitHub | Twitter (@Adams_Lair)


Top
 Profile  
 
PostPosted: 2018/03/09, 20:44 
Newbie
Newbie

Joined: 2018/03/08, 22:08
Posts: 4
Role: Hobbyist
Adam wrote:
Hey there, and welcome! ^^

Long story short, it sounds like what you're after is implementing a custom renderer. There's a Wiki article on that, which should explain some basic concepts and also provide a few examples that you might be able to adapt.

Quote:
Ive been running into issues that I cant seem to fix with mesh drawing. Its not drawing the vertices in the correct location.

Can you show us your code and maybe take a screenshot of what the result looks like when rendered? Maybe we can point you into the right direction, and judging by the fact that you already saw something, you're probably not that far off from the right approach :)



Thank you, yes that just might be what im looking for. Wasn't even considering it to be a custom renderer during my search. Just to be clear the mesh issue of not drawing correctly is not in the Duality engine. I can post some code, but i have it running correctly in Monogame so my code is correct. Its the other engine that I was trying to use that is having issues. I have it running pretty fast there but draws incorrectly, then I tried a different mesh function and while it draws correct it takes a huge performance hit.

Thank you again for the help.
Ron


Top
 Profile  
 
PostPosted: 2018/03/10, 02:31 
Newbie
Newbie

Joined: 2018/03/08, 22:08
Posts: 4
Role: Hobbyist
Thank you both for the help, I was able to draw a triangle to the screen properly. For future reference in case someone else needs to do this here is the code I used:

Code:
using System;
using System.Collections.Generic;
using System.Linq;

using Duality;
using Duality.Components;
using Duality.Drawing;
using Duality.Resources;

namespace DrawTriangle
{
    [RequiredComponent(typeof(Transform))]
   public class DrawTriangle : Component, ICmpRenderer
    {
        private const float SampleCircleRadius = 50.0f;

        private ContentRef<Material> material = null;// { get; private set; }
        private ColorRgba polyColor = new ColorRgba(0,0,0,255);

        public ContentRef<Material> Material
        {
            get { return material; }
            set { material = value; }
        }

        public ColorRgba PolyColor
        {
            get { return polyColor; }
            set { polyColor = value; }
        }

        float ICmpRenderer.BoundRadius
        {
            get { return SampleCircleRadius; }
        }

        bool ICmpRenderer.IsVisible(IDrawDevice device)
        {
            bool anyGroupFlag =
                (device.VisibilityMask & VisibilityFlag.AllGroups)
                != VisibilityFlag.None;
            bool screenOverlayFlag =
                (device.VisibilityMask & VisibilityFlag.ScreenOverlay)
                != VisibilityFlag.None;

            if (!anyGroupFlag) return false;
            if (screenOverlayFlag) return false;

            Vector3 myWorldPos = this.GameObj.Transform.Pos;
            return device.IsCoordInView(myWorldPos, SampleCircleRadius);
        }

        void ICmpRenderer.Draw(IDrawDevice device)
        {
            // Determine relative position and scale of the object based on
            // where the Camera is and whether a parallax effect is applied.
            Vector3 posTemp = this.GameObj.Transform.Pos;
            float scaleTemp = this.GameObj.Transform.Scale;
            device.PreprocessCoords(ref posTemp, ref scaleTemp);

            // Create an array containing the four vertices of our single quad
            VertexC1P3T2[] vertices = new VertexC1P3T2[3];

            vertices[0].Pos.X = posTemp.X + -100.0f * scaleTemp;
            vertices[0].Pos.Y = posTemp.Y + 0.0f * scaleTemp;
            vertices[0].Pos.Z = posTemp.Z;
            vertices[0].Color = polyColor;

            vertices[1].Pos.X = posTemp.X + 0.0f * scaleTemp;
            vertices[1].Pos.Y = posTemp.Y + 100.0f * scaleTemp;
            vertices[1].Pos.Z = posTemp.Z;
            vertices[1].Color = polyColor;

            vertices[2].Pos.X = posTemp.X + 100.0f * scaleTemp;
            vertices[2].Pos.Y = posTemp.Y + 0.0f * scaleTemp;
            vertices[2].Pos.Z = posTemp.Z;
            vertices[2].Color = polyColor;

            // Submit a drawing batch
            device.AddVertices(this.material, VertexMode.Triangles, vertices);
        }
    }
}


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC + 1 hour [ DST ]


Who is online

Users browsing this forum: Google [Bot] and 11 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group