3d model help

Hey guys I’m new,and I got some questions regarding 3d models and how to implement them into Codea, I made an obj and got it into Dropbox and using it in the Learn craft example and I load the viewers scene with the obj and while I don’t get any errors I don’t see the model. Any ideas? I read one member had to use a png and mtl file to get his to work but I don’t know how to sync Dropbox into letting me use a png and mtl file into the same place as the obj and then how would Codea know how to combine them? Any help would be appreciated:)

@CodeLearnerMike - best thing to do is to copy your obj and mtl files into the Codea document file. When there they should show up as a valid textured model if your model complied with the Wavefront spec (within reason).

Alternatively, if you place the files in the root of your Dropbox Codea directory (Dropbox/Apps/Codea/) and sync your Dropbox they should be loaded into your local Dropbox folder.

All you have to do then is to load the obj file into your project with the path you have chosen I.e. Dropbox:etc or Documents:etc.

Thanks for your help, now I can see a preview for the 3d model in the Dropbox file chooser, however I’m now getting an error when I try to load the 3d model in the Learn craft viewers scene, If you or someone could make a code to load any 3d model with out having to edit anything I’d appreciate it, unless you have to change the code every time to change the 3d model

@Bri_G also do you have any idea why you can’t edit add or make materials? Or am I doing something wrong, because wouldn’t you need to make a material for some 3d models?

I think I figured it out :# , the mtl file wasn’t completed probably which caused the error, I got a 3d model to load, however I’m still perplexed on why I can’t make materials…

Couple more questions. Is there a way use obj files without mtl? Or would that be a fbx?

@CodeLearnerMike - complete and accurate files can be generated with Blender and exported as a number of file types. You can load different model file types into it and export them as obj and mtl files. Loading 3D models into Codea is fine if the files comply with the Wavefront format. The obj file describes the vertices of the object and the mtl file describes the surface and textures during rendering. Pardon me if you know all this. I have played around editing obj and mtl files but struggled myself to get compliant files. The Loader in Codea seems quite strict on using compliant files,

There are a couple of file loaders that Codea users have written which does not use Craft, try searching for Ignatz code - look on his website CoolCodea. I,ll see what I can dig out.

You can incorporate colours for vertices in the model and not use an mtl file but surfaces are then just plain coloured or gradient coloured. Again I’ll look for examples.

Models without mtl file or colour data are displayed as white (show up grey).

@Bri_G thanks for your help, while I got you here can I pick your brain on a few more topics? My first question is with the AR example , I’m on the cube page and I was able to load my 3d model into the app , however it loads it into the air ands it’s enormous , but when I use DYNAMIC it loads it cube sized and floats down untill it disappears. So I’m asking if you would please write me some code to fix this lol , or at least explain what I got to do , thanks

@CodeLeanerMike you can set the scale of the model to adjust its size.

By the way, there is currently a limit to number of vertices in the model that can handled by Codea. if the model is too big it won`t display. (I have been waiting a long, long, long time for this to be fixed).

@piinthesky could you edit my code to do that? I tried but the scaling method I tried wouldn’t load the 3d model

Cube = class()

function Cube:init(entity, position, size)
self.entity = entity
self.entity.model = craft.model.cube(vec3(1.0,2.0,3.0))
self.entity.model = craft.model(“Blocky Characters:Orc”)
self.entity.position = position
self.entity:add(craft.rigidbody, STATIC, 1)
self.entity:add(craft.shape.box, vec3(1.0,2.0,3.0))
end

@CodeLearnerMike try…

Cube = class()

function Cube:init(position, size)
self.entity = scene:entity()
-- self.entity.model = craft.model.cube(vec3(1.0,2.0,3.0))
self.entity.model = craft.model("Blocky Characters:Orc")
self.entity.position = position
self.entity.scale=vec3(1,1,1)*size
self.entity:add(craft.rigidbody, STATIC, 1)
self.entity:add(craft.shape.box, vec3(1.0,2.0,3.0))
end

@piinthesky Thanks! A few changes and it now scales well using the entity.scale ,here’s the code that will load your 3d model into AR

Cube = class()

function Cube:init(entity,position, size)
self.entity = scene:entity()
self.entity.model = craft.model(“Blocky Characters:Orc”)
self.entity.position = position
self.entity.scale=vec3(.5,.5,.5)*size
self.entity:add(craft.rigidbody, STATIC, 1)
end

However it still floats in the air, any idea on how to make it DYNAMIC and stick to the ground/plane? I’m sure we’re helping somebody with he same questions lol

@piinthesky How many vertices are you trying to load in Codea. I have a 3D object with 13,824 vertices that shows OK in Codea.

@dave1707 idk about how many, but I downloaded a highly detailed 3d model and it loads in the asset previewer, but I end up getting an error so I’m not sure if it’s because of the number of vertices , or just a bad mtl file.

@dave1707 see the Codea 106 thread…the current limit is 64k vertices. @John did release a beta with essentially no limit. But unfortunately in the current beta @simeon accidently regressed back to the 64k limit! They stated the next beta will fix it again, but unfortunately i guess they are too busy with Shade at the moment.

@CodeLearnerMike replace STATIC with DYNAMIC when you add the rigidbody. You will need to set the gravity for it to move downwards. Put ‘~~~’ at the start and end of your code in your post to format it correctly.

@piinthesky Thanks. I guess my 13,824 is a long way from 64K and even farther from the 4 billion that it’s supposed to be.