Non-maintained solution
The proposed solution is not natively supported and may not work in all scenarios and versions.
Feature conflict
The following approach won't work as expected when semi-transparent selection with Halo is enabled.
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, 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] = (Vector3D) sphere.Normals[i].Clone();
}
ShadedPointCloud spc1 = new ShadedPointCloud(points, normals);
spc1.LineWeightMethod = colorMethodType.byEntity;
spc1.LineWeight = 10;
design1.Entities.Add(spc1, Color.Orange);
FastPointCloud version
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)
{
InitGraphicsData(data.RenderContext);
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 = sphere.Normals[i];
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;
design1.Entities.Add(sfpc1, Color.Orange);
Comments
Please sign in to leave a comment.