Craft sphere texture

@John I’ve been playing around with the flat and smooth icospheres trying to see why the smooth icosphere is so hard to texture. I’ve come to the conclusion that the smooth icosphere can’t easily be textured and it might not be worth trying. The flat icosphere texture is easy and fast and looks OK at the high levels. I don’t know what your UV sphere generator is, but anything is worth a try.

@John - it’s been kinda fun exploring the options for a realistic sphere, we have some good expertise on the forum - @dave1707 and @LoopSpace generating some good options. I think the icosphere is fine for the Craft environment. I need a more realistic sphere which can be viewed from inside.

I have a generator from the @Jmv38 sphere tutorial which works fine, do mesh systems work well alongside Craft systems do they use the same co-ordinate system for 3D space?
Also @dave1707 has an excellent sphere generator.

Were you proposing to map out a UV texture for the icosphere?

@John, By a “UV-sphere generator” do you mean one that creates the vertices based on longitude and latitude? It’s not really important what the underlying triangulation is, but it would be easier to have the UV coordinates already in place rather than having to create them afterwards. If creating the UVs afterwards then it doesn’t really matter how the vertices were constructed. As you point out to @dave1707, the main issue is the vertex sharing in the smooth version but that could be an issue with a longitude-latitude based construction as well unless you explicitly duplicate the required vertices.

My routines texture both versions of the icosphere just fine - I’m not sure why @dave1707 says it is hard as I’ve given a solution. It just needs serialising to make it faster, but building it in to the original construction would be equally fine. With the smooth version, it figures out the needed duplications and adds in the relevant vertices.

@Bri_G The point of my PseudoMesh class is to convert old-style meshes into craft models that can then be used with models. My recent run of videos (starting with https://youtu.be/NNpcx6-HBgI) all work using this: create a mesh and then convert it to a model. Since I already have code for spherical meshes (and more) which are already prepared for textures, I don’t actually need to use the icosphere model myself.

@LoopSpace I guess my use of hard was wrong. I should have use time consuming since it takes a long time as you pointed out.

@LoopSpace - thanks again, I completely forgot that you had built PseudoMesh for that purpose. Since obj files are Craft compatible seems a good way to go. Will revisit your code.

@Bri_G Above you said you want to view a sphere from the inside. I took my above program, chopped it up a little, and added some code to let you view it from the inside. Just keep zooming in and then slide your finger around to rotate the sphere.

Removed the code. See updated code below.

@Bri_G How does the above code at level 5 flat=false look when using your Earth texture. I tried using some Earth images, but I haven’t found any images that were very good to start with. I believe the above code textures everything as good as it can be textured.

@dave1707 - sorry I didn’t comment straight away, trying to put Sokoban in Codea. Sphere looks fine to me I’m using a reduced image from

https://visibleearth.nasa.gov/view.php?id=57730

At 1024 x 512.

Try it yourself.

@Bri_G Thanks for the link. Those images had too much ice at the top and bottom, but that lead me to this link. I used the 5400x2700 at 14MB.

https://visibleearth.nasa.gov/view.php?id=73751

@dave1707 - thanks for the link, checked the hi-res one you downloaded, I tend to use 1024x512 res for most things. Very good speed and quality, are you sure about the ice/snow?

@Bri_G This was the image I used from your link. There was too much white at the top and bottom of the image. Maybe it wasn’t the one you used because I didn’t see a 1024x512 size.

https://eoimages.gsfc.nasa.gov/images/imagerecords/57000/57730/land_ocean_ice_2048.jpg

@dave1707 - I reduced an image from 2048x1024 to 1024x512. I have a number of these, some from JMV38 to show night and day. The difference seems to be around the North Pole. There seems to be sea all across the top of your image, I assume it depends where the satellite taking it the image was located relative to the equator.

@Bri_G The picture I found was taken in I think August. There were a bunch of pictures taken at different months, so the amount of ice/snow was different. I picked one with the least amount of ice/snow so the North Pole wasn’t all white.

@Bri_G If you use my PseudoMesh class then there’s an invertNormals method which swaps the direction that the mesh is viewed from. So using that before converting the mesh to a model changes it to inside-out.

@dave1707 - thanks for the update on your sphere code, works great. I can see both external and internal views of the sphere. I noted your tidying up around the seam.

Is the code reversing normals in the section which creates a uv table?

@Bri_G I didn’t tidy up around the seam. The problem is doing a smooth sphere as opposed to the flat sphere. My code works OK for the flat sphere (where you can see the triangles), but there are still a few areas that are bad for the smooth sphere. As you increase the level from 0 to 5 for the flat sphere, the triangles get smaller and the sphere looks smoother. As for reversing the normals, I don’t do anything with the normals. I still don’t know the exact usage for normals so I leave them alone. I think they’re used for lighting and reflections and I hope @LoopSpace will give a good explanation of they’re use. To get the texture to show from inside the sphere, I just add the reverse of the indices table to itself. So the indices table is twice it’s size. Half of the table has the indices values going in a clockwise direction and the other half goes in a counterclockwise direction. So how you view the texture depends on the winding direction of the indices values. I could change the code so you can’t see the sphere from the outside, only once you get inside. That might make for an interesting game. I’m cleaning up my original code to make it smaller and faster. I’ll post that when I’m done. So far I can texture a level 5 icosphere with outside and inside views in about 1/2 second.

EDIT:I tried making a sphere invisible except from the inside, but it didn’t work. What happens is you don’t see the outside of the sphere, but you can see the inside. It’s as if the near part of the sphere is invisible and you can see the inside of the far side.

@dave1707 I had a go at explaining normals here.

@LoopSpace That looks like a very informative link. I don’t recall seeing it before. I’m going to start reading it now.

@dave1707 As ever, if you have any questions or suggestions, please do share so that I can make it better. (It was written a while ago, well before craft came on the scene, so it doesn’t address the one-sidedness of craft objects that you describe above, but hopefully explains why normals are important.)

@LoopSpace I read the section on Normals and excluding the vector stuff, I think I understand what it’s doing. I’ll have to write a simple example for myself and play around with the values in the Normal array. Thanks for the link, I’m not sure why I haven’t seen it before now. Do you have links to more information you would like to share. I’ll go back at a later time and read the full doc.