Shaded PointCloud

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:

 

 

class ShadedPointCloud : PointCloud
        {
            public ShadedPointCloud(IList<Point3D> points) : base(points)
            {
            }

            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);
            }
        }

 

Here's how to use it:

 

            // Create a Sphere, get its vertices and normals and create
// the point cloud from them
var sp1 = Mesh.CreateSphere(10, 30, 30); Point3D[] pts1 = new Point3D[sp1.Vertices.Length]; Vector3D[] normals1 = new Vector3D[sp1.Normals.Length]; for (int i = 0; i < sp1.Vertices.Length; i++) { pts1[i] = (Point3D) sp1.Vertices[i].Clone(); normals1[i] = new Vector3D(sp1.Vertices[i].X, sp1.Vertices[i].Y, sp1.Vertices[i].Z); normals1[i].Normalize(); } var spc1 = new ShadedPointCloud(pts1); spc1.Normals = normals1; spc1.LineWeightMethod = colorMethodType.byEntity; spc1.LineWeight = 10; viewportLayout1.Entities.Add(spc1, 0, Color.Orange);

 

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.