Make StaticModel with custom Model that uses line primitives instead of triangles.
I didn’t test it but it should work in theory.
Maybe there’s another way but I don’t know about.
I appreciate your help but I don’t have a clue how to do this. Is this some simple setting, or do I need to create my own models in Blender or something?
Thanks for pointing me to the sample. That may really tax my understanding but I can try.
Don’t laugh, remember I really don’t understand much about this. However, I was playing around with the SetDrawRange and got something that almost works.
private void CreateStellarHaloNode()
{
stellarHaloNode = universeNode.CreateChild();
stellarHaloNode.Scale = new Vector3(130000.0f, 130000.0f, 130000.0f);
var haloComp = stellarHaloNode.CreateComponent<StaticModel>();
haloComp.Model = CoreAssets.Models.Sphere.Clone();
var geometry = haloComp.Model.GetGeometry(0, 0);
geometry.SetDrawRange(PrimitiveType.LineList, 0, 3840);
var haloMaterial = Material.FromColor(new Color(0.0f, 1.0f, 0.0f, 1.0f), false);
var tech = ResourceCache.GetTechnique(NO_TEXTURE_UNLIT_ALPHA);
haloMaterial.SetTechnique(0, tech);
haloMaterial.RenderOrder = RENDER_ORDER_STRUCTURE;
haloComp.SetMaterial(haloMaterial);
}
I don’t really understand what SetDrawRange does, but the above code does yield this.
I don’t think I can cover the whole topic of rendering 3D geometry in one reply.
You have to fix indices in index buffer.
Indices are either 16bit or 32bit integers, index buffer data is accessible in public interface.
The easiest modification is for each (a b c) triplet in index buffer create three pairs (a b) (b c) (c a) instead. You should get double size of bufer for lines comparing to triangles. You may later remove duplicate edges.
Ok, thanks for Eugene’s last hint, I think I have this working. I take the IndexBuffer for the triangles of a StaticModel Sphere, and convert them into sets of lines.
This code is not really optimized and is designed more for clarity. I also don’t (yet) throw away duplicate lines.
private void CreateStellarHaloNode()
{
stellarHaloNode = universeNode.CreateChild();
stellarHaloNode.Scale = new Vector3(130000.0f, 130000.0f, 130000.0f);
var haloComp = stellarHaloNode.CreateComponent<StaticModel>();
haloComp.Model = CoreAssets.Models.Sphere.Clone();
var geometry = haloComp.Model.GetGeometry(0, 0);
var indexBuffer = geometry.IndexBuffer;
var indexCount = indexBuffer.IndexCount;
var triangleCount = indexCount / 3;
unsafe
{
var newIndices = new short[indexCount * 2];
var shadowData = (short *)indexBuffer.ShadowData;
for (var i = 0; i < triangleCount; i++)
{
var a = shadowData[i * 3];
var b = shadowData[i * 3 + 1];
var c = shadowData[i * 3 + 2];
newIndices[i * 6 + 0] = a;
newIndices[i * 6 + 1] = b;
newIndices[i * 6 + 2] = b;
newIndices[i * 6 + 3] = c;
newIndices[i * 6 + 4] = c;
newIndices[i * 6 + 5] = a;
}
indexBuffer.SetSize(indexCount * 2, false, false);
fixed (short *indexPtr = &newIndices[0])
{
indexBuffer.SetDataRange(indexPtr, 0, indexCount * 2, true);
}
geometry.SetDrawRange(PrimitiveType.LineList, 0, indexCount * 2);
}
var haloMaterial = Material.FromColor(new Color(0.0f, 1.0f, 0.0f, 0.25f), false);
var tech = ResourceCache.GetTechnique(NO_TEXTURE_UNLIT_ALPHA);
haloMaterial.SetTechnique(0, tech);
haloMaterial.RenderOrder = RENDER_ORDER_STRUCTURE;
haloComp.SetMaterial(haloMaterial);
}
Part of the difference between your recent attempt and SceneKit is scenekit only seems to be rendering a hemisphere, so the lines in the background aren’t showing up.