Textured Line or Curve

Revised for version 12. Now, viewportLayout1 is of type Model.

The proposed solution is not natively supported and may not work in all scenarios and versions.

Requires Eyeshot >= 9.0.457 

Here's an example on how to override the Line or Circle class in order to draw a curve with textured vertices by deriving the Line and Circle classes.

class MyLine : Line
{
    public MyLine(Line another) : base(another)
    {
    }

    public TextureBase texture;

    // 
    // 1D texture coordinates.
    // 
    public Point2D TextureCoordinates { get; set; }

    protected override void Draw(DrawParams data)
    {
        data.RenderContext.EndDrawBufferedLines();
        data.RenderContext.SetShader(shaderType.Texture1DNoLights);

        data.RenderContext.SetTexture(texture);

        data.RenderContext.DrawLine(StartPoint, EndPoint, TextureCoordinates);

        data.RenderContext.EndDrawBufferedLines();
    }

}

class MyCircle : Circle
{
    public MyCircle(Circle another) : base(another)
    {
    }

    public TextureBase texture;

    // 
    // 1D texture coordinates.
    // 
    public float[] TextureCoordinates { get; set; }

    protected override void DrawWireEntity(RenderContextBase context, object myParams)
    {
        context.DrawLineStrip(Vertices, TextureCoordinates);
    }

    protected override void Draw(DrawParams data)
    {
        data.RenderContext.SetShader(shaderType.Texture1DNoLights);

        data.RenderContext.SetTexture(texture);

        base.Draw(data);
    }
}

Then use them like below.

Remember to Dispose the texture object when it's no longer needed.

// Create a texture with a colormap
var texture = viewportLayout1.renderContext.CreateTexture1D(new Color[] { Color.Red, Color.Green, Color.Blue, Color.Yellow },
textureFilteringFunctionType.Nearest, textureFilteringFunctionType.Nearest, false, false);

var myL = new MyLine(new Line(0, 0, 100, 100));
myL.TextureCoordinates = new Point2D(0, 1);
myL.texture = texture;
viewportLayout1.Entities.Add(myL);

var myCirc = new MyCircle(new Circle(new Point3D(10, 10, 0), 20));
myCirc.texture = texture;

// Regenerate it in order to compute the vertices
myCirc.Regen(0.1);
myCirc.TextureCoordinates = new float[myCirc.Vertices.Length];

for (int i = 0; i < myCirc.Vertices.Length; i++)
{
    myCirc.TextureCoordinates[i] = (float)i / (myCirc.Vertices.Length - 1);
}

viewportLayout1.Entities.Add(myCirc); 

 

Was this article helpful?
0 out of 0 found this helpful
Have more questions? Submit a request

Comments

0 comments

Please sign in to leave a comment.