Icosahedron — subdividing and mapping

Wait, @dave1707 — did you adjust the icosphere vertices to make it an icosahedron?

I’ve seen you do some impressive stuff, and maybe I’m just too math-challenged to know how hard things like that are, but that kind of blows me away. Dang, dude, wow. And THANKS! :pray:t2:

…so I’ve now added your icosahedron to the project (it’s got the blue dots in the picture below)…

Icosahedron Mapping.zip (3.3 MB)

…but there’s a weird thing you might see if you run it.

I’ve made buttons that will generate the vertices cubes for each of the spheres—GPT’s @LoopSpace’s, and yours. If you try to generate yours and LoopSpace’s, Codea will crash with a permanent hang—at least it does on my iPad—but Codea handles generating the GPT cubes fine even when either of the other sets of cubes has been made.

Something about trying to make vertices cubes on your sphere and LoopSpace’s crashes Codea… for me.

@UberGoober I can’t take credit for the vertices positions. It’s just the way they are when you do the icospheres. I thought you already knew that since you were doing all the vertices positions. As for the Codea hangs, my iPad does the same thing. If I do my vertices first, then Loopspace, it hangs.

Wait really? The Codea icospheres are icosahedrons? That’s trippy, because I had assumed they would be the same things as the sphere asset in the Primitives, which is more like @Loopspace’s thing. I guess not! Codea has two separate geometries for spheres, it seems.

Updated version now toggles to a wireframe that shows vertices.

Useful if anyone wants that wireframe material too.

Icosahedron Mapping.zip (3.6 MB)

@UberGoober Here’s a version I have that’s similar. I draw the lines connecting the vertices but I also show the unwrapped position of the vertices below it. The lines work up to icoLevel 4 but don’t draw completely above that. It still shows the unwrapped positions up to icoLevel 8.

This starts at icoLevel 1 but you can change the value up to icoLevel 8. You can drag your finger to rotate the lines.

viewer.mode=FULLSCREEN

function setup() 
    icoLevel=1
    
    fill(255)
    offset=6
    col=color(255)
    
    assert(OrbitViewer, "Please include Cameras as a dependency")        
    scene = craft.scene()
    v=scene.camera:add(OrbitViewer, vec3(0,0,0), 50, 0, 3000)
    
    sTab={}
    table.insert(sTab,create(10,icoLevel))
end

function draw()
    background(0)
    update(DeltaTime)
    scene:draw()
    
    for a,b in pairs(sTab) do
        b.material.opacity=0
        drawLines(b)
    end
    
    for a,b in pairs(sTab[1].model.uvs) do
        ellipse(b.x*WIDTH*.95+20,b.y*200+60,3)
    end
end

function update(dt)
    scene:update(dt)
end

function create(size,level)
    local s=scene:entity()
    s.position=vec3(0,offset,0)
    s.model=craft.model.icosphere(size,level)  -- create icosphere
    s.material=craft.material(asset.builtin.Materials.Standard) 
    return s
end

function drawLines(s)
    s.material.blendMode=NORMAL
    local sd=scene.debug
    local pTab=s.model.positions
    local iTab=s.model.indices
    for z=1,#s.model.indices,3 do
        local p1=pTab[iTab[z]]+s.position
        local p2=pTab[iTab[z+1]]+s.position
        local p3=pTab[iTab[z+2]]+s.position
        sd:line(p1,p2,col)
        sd:line(p1,p3,col)
        sd:line(p2,p3,col)
    end
end