Shaded PointCloud

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

Requires Eyeshot >= 9.0.351

The following class draws a PointCloud with normals information per each vertex, so it can be drawn with proper illumination:

Derived class:

class ShadedPointCloud : PointCloud
{
    public ShadedPointCloud(IList<Point3D> points, IList<Vector3D> normals) : base(points)
    {
Normals = normals; } public Vector3D[] Normals { get; set; } protected override void SetShader(DrawParams data) { data.ShaderParams.Lighting = true; base.SetShader(data); } protected override void DrawEntity(RenderContextBase context, object myParams) { context.DrawPointsWithNormalsIndeterminate(Vertices, Normals, 0, Vertices.Length); } protected override void DrawSelected(DrawParams data) { // Set the wire color (usually used to draw the PointCloud) to the material diffuse data.RenderContext.SetColorDiffuse(data.RenderContext.CurrentWireColor, data.RenderContext.CurrentWireColor); base.DrawSelected(data); }
protected override void Draw(DrawParams data) { // Set the wire color (usually used to draw the PointCloud) to the material diffuse data.RenderContext.SetColorDiffuse(data.RenderContext.CurrentWireColor, data.RenderContext.CurrentWireColor); base.Draw(data); } }

Creation code:

// Create a sphere, get its vertices and normals and create the point cloud from them
Mesh sphere = Mesh.CreateSphere(10, 30, 30);
Point3D[] points = new Point3D[sphere.Vertices.Length];
Vector3D[] normals = new Vector3D[sphere.Normals.Length];

for (int i = 0; i < sphere.Vertices.Length; i++) { points[i] = (Point3D) sphere.Vertices[i].Clone();
normals[i] = new Vector3D(sphere.Vertices[i].X, sphere.Vertices[i].Y, sphere.Vertices[i].Z); normals[i].Normalize(); }
ShadedPointCloud spc1 = new ShadedPointCloud(points, normals); spc1.LineWeightMethod = colorMethodType.byEntity; spc1.LineWeight = 10; model1.Entities.Add(spc1, 0, Color.Orange);
Was this article helpful?
0 out of 0 found this helpful
Have more questions? Submit a request

Comments

1 comment
  • FastPointCloud version, tested in v2021.1

    Derived class:

    class ShadedFastPointCloud : FastPointCloud
    {
    public ShadedFastPointCloud(float[] points, float[] normal) : base(points)
    {
    NormalArray = normal;
    }

    public float[] NormalArray { get; set; }

    protected override void SetShader(DrawParams data)
    {
    data.ShaderParams.Lighting = true;
    base.SetShader(data);
    }

    public override void Compile(CompileParams data)
    {
    data.RenderContext.CompileVBO(drawData, DrawWithoutVBO, new VBOParams()
    {
    vertices = PointArray,
    normals = NormalArray,
    primitiveMode = primitiveType.PointList
    });
    }

    protected override void DrawSelected(DrawParams data)
    {
    // Set the wire color (usually used to draw the PointCloud) to the material diffuse
    data.RenderContext.SetColorDiffuse(data.RenderContext.CurrentWireColor, data.RenderContext.CurrentWireColor);

    base.DrawSelected(data);
    }

    protected override void Draw(DrawParams data)
    {
    // Set the wire color (usually used to draw the PointCloud) to the material diffuse
    data.RenderContext.SetColorDiffuse(data.RenderContext.CurrentWireColor, data.RenderContext.CurrentWireColor);
    base.Draw(data);
    }

    protected override void Render(RenderParams data)
    {
    // Set the wire color (usually used to draw the PointCloud) to the material diffuse
    data.RenderContext.SetColorDiffuse(data.RenderContext.CurrentWireColor, data.RenderContext.CurrentWireColor);
    base.Render(data);
    }
    }

    Creation code:

    Mesh sphere = Mesh.CreateSphere(10, 30, 30);

    float[] points = new float[sphere.Vertices.Length * 3];
    float[] normals = new float[sphere.Normals.Length * 3];

    for (int i = 0; i < sphere.Vertices.Length; i++)
    {
    points[i * 3 + 0] = (float) sphere.Vertices[i].X;
    points[i * 3 + 1] = (float) sphere.Vertices[i].Y;
    points[i * 3 + 2] = (float) sphere.Vertices[i].Z;

    Vector3D n = new Vector3D(sphere.Vertices[i].X, sphere.Vertices[i].Y, sphere.Vertices[i].Z);
    n.Normalize();

    normals[i * 3 + 0] = (float) n.X;
    normals[i * 3 + 1] = (float) n.Y;
    normals[i * 3 + 2] = (float) n.Z;
    }

    ShadedFastPointCloud sfpc1 = new ShadedFastPointCloud(points, normals);

    sfpc1.LineWeightMethod = colorMethodType.byEntity;
    sfpc1.LineWeight = 10;
    model1.Entities.Add(sfpc1, Color.Orange);
    0

Please sign in to leave a comment.