Wireframe mode not working on material

I and trying to draw some nodes using the “wireframe” fillmode. It doesn’t seem to be working for me. Here is my C# code:

	private void CreateStellaHaloNode()
	{
		stellarHaloNode = universeNode.CreateChild();
		stellarHaloNode.Scale = new Vector3(130000.0f, 130000.0f, 130000.0f);

		var haloComp = stellarHaloNode.CreateComponent<StaticModel>();
		haloComp.Model = CoreAssets.Models.Sphere;
		var haloMaterial = Material.FromColor(new Color(1.0f, 0.5f, 0.0f, 0.75f));
		var tech = ResourceCache.GetTechnique(NO_TEXTURE_UNLIT_ALPHA);
		haloMaterial.SetTechnique(0, tech);
		haloMaterial.FillMode = FillMode.Wireframe;
		haloMaterial.RenderOrder = RENDER_ORDER_BULGE;
		haloComp.SetMaterial(haloMaterial);
	}

This is what I’m trying to get:

This is what the above code yields. Is there something else I need to set?

So no one has any ideas on this? Is what I’m doing supposed to work, or am I misunderstanding the (limited) documentation?

I don’t see any issues with code.
However, wireframe and point modes do not exist on some platforms (on GLES, to be specific).

Ah, that must be the problem. I am doing this on iOS which (I believe) is using OpenGL ES.

Is there any other way I can achieve this?

Seems like this limitation should be added to the docs.

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.

Eugene,

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?

Bill

I think he means you will have to create your model from a custom geometry with Vertex/IndexBuffers. See sample 34. Instead of using tris with

    geom->SetDrawRange(TRIANGLE_LIST, 0, numVertices);

you would use a LINE_LIST to define the geometry

    geom->SetDrawRange(LINE_LIST, 0, numVertices);

Second that ^^^
I forgot that we have sample for creating model.
It’s not easy process, but it’s straightforward.
You may get C#-specific issues tho.

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.

Obviously the lines it is using are not really right, but it does give a type of wireframe sphere.

Is there some modification of this that might get the wireframes looking correct?

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.

I don’t know where you’re going with that sphere, but there’s benefits to basing it on triacontahedron:

  • Easy (relatively uniform) cube UV mapping
  • Most even distribution of vertices
  • Used in geomatics

But if you’re creating plasmoids, the polar coordinates of a UV sphere might be more convenient.

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

Here is what it looks like:

I don’t necessarily like the way this is tessellated compared to SceneKit’s way (see image in initial posting), but I can live with it.

Thanks again for the help. I couldn’t have done this without you.

This looks like an icosphere, whereas the vertex arrangement in your OP is referred to as a UV sphere.

Thanks for that information on the different meshes for a sphere.

I tried creating a UVSphere in Blender and saved it. When I try to load it to use in my app I get a:

System.Exception: Models/UVSphere.blend is not a valid model file.

Can you tell me how this needs to be saved such that I can use it?

Urho comes with a UV sphere model.

Are you sure? Code completion for CoreAssets.Models. doesn’t show it. I also don’t see it in the CoreAssets directory of the Urho3D-1.7.1 source.

What’s is called?

I would like to know how to do this in Blender because I also need to make a custom Cylinder. I don’t like the way that is tessellated.

AFAIK there is no CoreAssets folder.

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.

Sorry, you are right. It was called SourceAssets.

So what is the name of the UVSphere and how is it accessed?

That is a good point. In SceneKit it only renders the front. I think that is because I specify:

	material.isDoubleSided = false

Is there an equivalent in Urho? Is it culling?