Icosphere

@dave1707 - very neat and impressive, I think I”ll put my searching on the back burner now - your demo meets all my needs at moment.

Notice you put a blank main in the dependency. I tend to use a demo including a Main useable tab for the dependency so I can check the demo without running a dedicated demo file as the Main in the dependency is ignored. Alternatively I use a simple text display stating what the dependency function is (makes them stand out a little against project files). Thanks for the help.

@Bri_G I didn’t want to add my demo to Main because it was originally too big. I had to find a smaller world map to use than I have in my original demo. I also forgot to add the parameter documentation.

s1 = icoSphere(pos,size,level,flat,ins,image)

pos … vec3(x,y,z) x,y,z position of the sphere
size … size of the sphere
level … sphere level (1-6) higher values use more triangles to create sphere
flat … (true or false) true shows trianglular surface, false shows smooth surface
ins … (true or false) true shows reverse image when inside sphere, false doesn’t
image … image to use as texture. Width should be twice the Height to keep ratio

@dave1707 - thanks again, figured out most of the parameters from the code but wasn’t quite sure of the two booleans.

@Bri_G I updated the IcoCreate using your suggestion to include a demo in Main. I also added an option to choose material type (Basic, Standard, Specular). There are instructions on how to set the parameter values and if you don’t supply an image (nil) then a multi-colored sphere is created.

@dave1707 - excellent, neat finished product. I just added a few lines to print out for the project icon.


    font("Futura-CondensedExtraBold")
    fontSize(64)
    fill(255, 246, 0)
    text("Sphere Dependencies",WIDTH/2,HEIGHT/2)

@dave1707 - looking back resurrected an old @Jmv38 tutorial for spheres pre Craft. This goes through the creation of meshes and some optimisations on sphere texture code.

@Steppers - I know it’s old hat but it is well put together and helpful for anyone getting into meshes. Images are provided off the net.

@Bri_G That’s actually a very nice walkthrough of the ideas. I really like it! Thanks for bringing it up again, it should be available on WebRepo now.

On a related note I’d really appreciate it if you can submit projects using the google form, I’ve got a script setup for the form that saves me a lot of time processing submissions :smile: Cheers!

@Bri_G I don’t remember seeing that before. When was it originally posted.

@dave1707 - the file I took it from was dated 10th August 2013. At the time I thought it was the bee’s knees and still think it’s an excellent example of mesh 3D.

@dave1707 - I asked @Simeon how we would compensate for loss of the structure function blah(…) but heard no reply. Could you outline the approach to this? I am trying to update another old demo with this structure present.

I’ve run into something I haven’t been able to figure out yet. Here’s some code that textures an icosphere and has an option to draw the lines of the triangles that makeup the icosphere.

The problem: for icospheres 5 and above, it doesn’t draw all the triangles. As far as I can tell all the info is there because the textured icospheres are drawn correctly. So if the texture is correct, why aren’t the triangles correct.

To see the lines, slide the lines parameter. If you want to see a slow motion of the lines being drawn, slide the slow parameter. The slow isn’t that useful for the lower level icospheres.

Change the value of the “level” variable from 0 thru 6 and run for each to see the issue.

Hopefully I’m not doing something stupid.

@Simeon or anyone, any suggestions.

See updated code below

@dave1707 - sounds like it’s wrapping round allocated memory. Off at the top on at the bottom, once the allocated memory is full. Not run it yet will check out soon.

Edit: ran it and I see what you mean. I think@Simeon and @John need to look at this, hopefully not a problem in version 4.

Something I think is happening with the above triangles. I think there’s a limit for the number of triangles (lines) that can be drawn. If I change the for loop in drawLines for a level 5 icosphere from 1 to 9997, it looks like the triangles that aren’t drawn starting at 1 are being drawn. Will continue with that thought.

@dave1707 - interesting, very impressive. I can confirm partial loss of sphere structure at level 5. Can you influence the lineWidth for the wireframe?

Another issue I have noticed, and I may have seen this before with distortion of vertices so models don’t appear correct and distort when rotating, - set level to 4 and rotate the model no probs. Then set the wireFrame on - still looks good. Now switch textured back on - do you see the distortion? If you can confirm I think there may be an error in the Craft display of models. Some of my vertex shaded models are fine in modelling packages but distort in Craft. Something I have raised before.

@Bri_G Im not seeing any type of distortion on level 4 or 5 when switching back and forth between the texture or lines. What I think you might be seeing on the texture is the reverse image. The front of the sphere is clear and you’re seeing the inside of the back of the sphere. Does the sphere rotate in the opposite direction that you’re sliding your finger to rotate it.

@dave1707 - you could be right, but why should you see that effect if you are not moving the camera position? Also it is occurring after re-texturing - doesn’t make sense.

@Bri_G I have my ico settings different than what I posted. I set them to what I posted. When I switch between texture, lines, and back to texture, I see what I describe above. That’s caused by the line of code in drawlines(), s.material.blendMode=NORMAL. I had to add that line so the texture disappears when I draw the lines. When you switch back to texture, the outside of the texture is still clear and you’re seeing the inside of the back of the sphere. Not sure why the outside is clear but the inside isn’t.

@Bri_G To fix the reverse texture problem when going from lines back to texture, change the line

    s1=icoSphere(vec3(0,0,0),100,level,false,true,1,image)
to
    s1=icoSphere(vec3(0,0,0),100,level,false,false,1,image)

Instead of setting the “inside” parameter to true, set it to false.

After further investigation, the triangles stop drawing when the count reaches 32,768 which is hex 8000. That seems like a likely number to stop at.

Verified. I modified my version of the code and added another slider. That slider draws triangles starting at 32,767 instead of 1. At the level 5 icosphere, when I flip the slider back and forth between false and true, I can see the triangles being displayed for the first part of the sphere and then the remaining part of the sphere.