3D model viewing

@John, @Simeon - I recently installed an android app on my Nexus 7 called viewER. I was using it to check some of the models I have found, as I am still getting hit and miss results with Craft. It does seem to have a higher success rate than Craft so I am sure there is something I don’t understand with setting up a viewer in Craft or the code routines used by Craft for loading models are too rigid/precise and reject many poorly made obj files.

The main reason I posted this though was what I found with this ER viewer. See the following two links, one to the viewER website and the other to a video of a hologram effect using a truncated inverted pyramid. Must try this out with the android software and was wondering if you had seen this and implemented it in Codea?

viewER

And

Youtube Hologram

Edit: Oooops, tried to use the links above in the editing bar - made a mess of it so reverted to good old HTML. Sorry.

All another link to an app to do this on android or Apple gear.

Apple Store Hologram

Hi Bri

Improvements to model loading are currently in the pipeline for 3.0. As for the hologram viewer, you could do that pretty easily by rendering the model from the required angles in separate images and then drawing those to the screen in the right locations.

@John - thanks for the feedback, will try to set a hologram viewer up when I’be finished the current projects I am working on.

All - my apologies updated all links above to link direct to pages of interest.

@John - just tried to set up an asset folder for 3D models to see if it could get round my problems. Put two models in, one that works with Craft and one that doesn’t. Both showed the basic model shape in the asset directory display - both not textured. I noticed that the .obj and .mtl files were not present in the text file section of the assets directory. Is there any way we can get those file types recognised, it could be handy to edit files within that section. At least to be able to see they were present. The 3D image view is great but you can’t do much with it.

@John - following up on the Assimp importer l have examined a few of their test objects. Assimp seems to have incorporated a few variations on the OBJ loader accepting spaces in file names, mixing features and, happily for me, incorporating colours with the vertex data producing a gradient effect.

The model data seems very basic but I ran into a problem with the model of a cube incorporating colour data. One of the triangles in a face is not rendered using Craft. In contrast, on the Mac, the same model is fully rendered in the Finder window.

You can get the data, it’s open source, from the Assimp Github page in the tests directory. I have reposted the data for obj file below.

Can you explain this?

cube_with_vertexcolors.obj


g cube

v 0.0 0.0 0.0 0.48627 0.43137 0.47059
v 0.0 0.0 1.0 0.09412 0.00000 0.47451
v 0.0 1.0 0.0 0.01569 0.00000 0.17255
v 0.0 1.0 1.0 0.87843 0.00000 0.03922
v 1.0 0.0 0.0 0.09412 0.78431 0.09804
v 1.0 0.0 1.0 0.48627 0.03922 0.21961
v 1.0 1.0 0.0 0.30588 0.03922 0.19608
v 1.0 1.0 1.0 0.09020 0.00000 0.78431

vn 0.0 0.0 1.0
vn 0.0 0.0 -1.0
vn 0.0 1.0 0.0
vn 0.0 -1.0 0.0
vn 1.0 0.0 0.0
vn -1.0 0.0 0.0

f 1//2 7//2 5//2
f 1//2 3//2 7//2
f 1//6 4//6 3//6
f 1//6 2//6 4//6
f 3//3 8//3 7//3
f 3//3 4//3 8//3
f 5//5 7//5 8//5
f 5//5 8//5 6//5
f 1//4 5//4 6//4
f 1//4 6//4 2//4
f 2//1 6//1 8//1
f 2//1 8//1 4//1


p.s. A similar cube with universal colours suffers from the same problem in Craft.

All - anyone help, I have used model viewer scenes in which I have placed an object. Most objects are viewable centre screen in reasonable size - but some aren’t. Mostly I have used OrbitViewer(), so when I find the project is running OK but not showing the object centre screen I have to search. Some of these models are small and take time to find.

What I would like is a parameter.watch(OrbitViewer) which would allow me to find the objects then change the vec3() in the OrbitViewer() call so the object is front and centred. Anyone any idea on this?

@Bri_G Not sure if this will help. If you place a model at 0,0,0 , it should be in the center of view. Maybe the camera is too close or too far away to the model. In this example, putting the OrbitViewer in the draw function will allow you to move the camera in or out using the parameter slider. Try this on one of the models you’re having trouble with. Let me know if I’m way off base in what you’re trying to do.

function setup()
    parameter.integer("pos",-30,200,10)
    assert(craft, "Please include Craft as a dependency")
    assert(OrbitViewer, "Please include Cameras (not Camera) as a dependency")        
    scene = craft.scene()
    skyMaterial=scene.sky.material
    skyMaterial.sky=color(158, 202, 223, 255)
    skyMaterial.horizon=color(98, 166, 114, 255)
    
    pt=scene:entity()
    pt.position=vec3(0,0,0)
    pt.model = craft.model.icosphere(1,1)
    pt.material = craft.material("Materials:Specular")
    pt.material.diffuse=color(0,0,255)
end

function draw()
    update(DeltaTime)
    scene:draw()
    v=scene.camera:add(OrbitViewer, vec3(0,0,0), pos, 0, 200)
end

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

@dave1707 - thanks for the feedback, what you presented is just the zoom feature in OrbitViewer() which uses the third parameter to zoom in and out.

What I think I need are the coordinates of the viewer itself which I think is the second parameter a vec3(). I have tried replacing this with a variable vwr and to display vwr.x, vwr.y and vwr.z. This would allow me to place the viewer in 3D space so that I can work out where the object is and the zoom factor needed to display the model directly. In OrbitViewer() the default is vec3(0,0,0). But I couldn’t get it to work. It would have allowed me to search and find the object then read the corresponding location.

It is a tool that is useful when looking at other users code as they set up their own models and environment. Adding my own models, or others I find sometimes presents a problem. I have a viewer derived from code which works fine for several models, add another model and I can’t find it. For instance the cube above is centre screen but almost invisible so your zoom worked for it but rotate the environment slightly and the object is easily lost.

Perhaps I should get better at interpreting 3D positioning from the code so I can set up OrbitViewer() better, or change the coordinates of the model to bring it into a standard view.

Oh, by the way - did you see the missing triangle in the obj model above?

@Bri_G Does this come closer to what you want. Use the sliders to move the camera.

function setup()
    parameter.integer("xpos",-180,180,10)
    parameter.integer("ypos",-180,180,10)
    parameter.integer("zpos",-10,800,200)
    assert(craft, "Please include Craft as a dependency")
    assert(OrbitViewer, "Please include Cameras (not Camera) as a dependency")        
    scene = craft.scene()
    skyMaterial=scene.sky.material
    skyMaterial.sky=color(158, 202, 223, 255)
    skyMaterial.horizon=color(98, 166, 114, 255)
    
    v=scene.camera:add(OrbitViewer, vec3(0,0,0), 100, 0, 200)
    
    -- create a sphere far off in the distance (300)
    create(0,0,300,color(0,0,0),2)
            
    -- create 3 spheres in a line, -3, 0, 3
    create(0,0,-3,color(0,255,0),1)
    create(0,0,0,color(255,255,0),1)
    create(0,0,3,color(0,255,255),1)
    
    -- create 8 spheres at the corners of a cube
    create(5,5,-5,color(255,0,0),1)
    create(5,5,5,color(0,0,255),1)
    create(-5,5,5,color(0,0,255),1)
    create(-5,-5,-5,color(255,0,0),1)
    create(5,-5,5,color(0,0,255),1)
    create(-5,5,-5,color(255,0,0),1)
    create(5,-5,-5,color(255,0,0),1)
    create(-5,-5,5,color(0,0,255),1)
end

function draw()
    update(DeltaTime)
    scene:draw()
    v.rx=xpos
    v.ry=ypos
    v.zoom=zpos
end

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

function create(x,y,z,c,s)
    local pt=scene:entity()
    pt.position=vec3(x,y,z)
    pt.model = craft.model.icosphere(s,1)
    pt.material = craft.material("Materials:Specular")
    pt.material.diffuse=c
end

@dave1707 - yes that gave me what I needed. I can print the camera point up with the v.rx, v.ry and v.zoom. Put my models in and gave me what I wanted.
Thank you.

P.s. Where did you get the v.rx, v.ry and v.zoom from?

@Bri_G v is the variable I use for OrbitViewer and self.rx, self.ry, and self.zoom are variables that are used in the Cameras/OrbitViewer class.

@dave1707 - ahhh, tried to do something similar. Defined vec3() as vwr in setup and used that as vec3() in OrbitViewer assignment. Didn’t work tho could’t print vwr.x, vwr.y and vwr.z.

Then tried to read vwr in OrbitViewer class with vwr = self.t but failed again. This is a neat trick!! Thanks again.

@Bri_G That’s not a neat trick, but the way classes work. v is an instance of OrbitViewer so v has access to all of OrbitViewers self.variables. If you look at the OrbitViewer class, you can access all of the self variables that you see in the OrbitViewer:init() function.