It looks like you're new here. If you want to get involved, click one of these buttons!
I've hacked together a .ply importer as an extension to the .obj 3D model viewer/ importer that @Ignatz made.
.ply (aka Stanford) is, like .obj, a plaintext, easily parse-able 3D model format, supported by many 3D programs, including Blender.
So why bother adding support for it on top of .obj?
One advantage that .ply has over .obj, is that it can store colour information for each individual vertex, whereas .obj files only store colour values for each material that you use.1 This means that you can use Blender's rather nice "vertex painting" mode. When you import the model into Codea, Open GL takes over and shades each face of the model by smoothly interpolating between the colours for each point on the face.
This is useful if you have a model that would just look better with very smooth, resolution-independent shading, or you can't be bothered to add a texture, or you're running into memory/processor constraints and want to cut down on textures. You could also combine the vertex painting with a texture. This again could be useful if you want to reuse the same texture image over and over, but make it look a little different each time (and add some resolution-independence to how the object is rendered). eg:
I'm going to clean up the code a little before I post it. It works as a sub-class of @Ignatz 's OBJ class, so it uses all of the I/O code that @Ignatz wrote. The .ply parser is modified from the code posted a couple of years back by @aciolino . Thanks/ apologies to both of them, I hope neither of them mind me mashing their projects together like this!
There is apparently a flavour of .obj that does support having colour information for each vertex, but I think that's a somewhat non-standard version of .obj, and Blender cannot export those kind of .obj files. You could also "bake" the vertex painting into a raster image and export it as a texture, but that would defeeat the purpose somewhat. ↩
Comments
No problem, this is what our community is all about, helping and sharing, thanks for your efforts
Here's the code. This is to be added to @Ignatz 's 3D model viewer v5: code, blog post with documentation
Compared to .obj:
Pros
supports colour-per-vertex and therefore vertex-painting (this was the main reason I added it)
.ply is held in a single file (.obj is split across two) and therefore less file wrangling needed. If there is no texture, you can just use the .ply file as is. Moreover, adding the URL to the .ply file doesn't break the .ply syntax, as it uses a "comment" field. So the workflow between Codea and Blender is a little simpler.
Cons
.ply (or at least the .ply Blender exports) doesn't seem to store data for various material properties such as reflectivity etc.
This only supports single objects with single textures. The .ply that Blender exports doesn't seem to acknowledge multi-object or multi-texture scenes at all. For complex rigs, .obj is the way to go
The .ply exporter in Blender is a little less fully featured. It doesn't have a triangulate option like the .obj exporter has, so you have to add a Triangulate modifier before you export (you don't have to click "apply" on the modifier though).
OK, I've added a gist here that has everything you need to test it, including the "vertex painting" object used for the screen shot above. Just download the "3D Model Importer", you don't need to download the .ply file, as the Importer will automatically download it to your global data.
https://gist.github.com/Oliver-D/49460797dbc81b24e33d
@yojimbo2000 when i choose the object and press load, there is a brief change in the output panel (orange text) then the program seems to restart and nothing is showing on the screen.
I guess there is an error but i cant read it because the message is erased.
Did you get the code from the gist I posted?
https://gist.github.com/Oliver-D/49460797dbc81b24e33d
This one, not the links at the top of the post. I made a couple of changes to the gist right after I posted, which you might not have if you downloaded it right away.
Are you selecting the last model, "vertex paint"? (Choose slider all the way to the right)
It would be great if you could Comment out the two lines towards the end of
configureModel()
and let me know what the error isi get a 'shader compile error' with last model
I tried to download again, but still get bad result.
Thanks for helping me out!
That's weird. I redownloaded the code from the gist into a separate project to check, I don't get any of those errors. The "attempt to redeclare reflect as a variable" error is odd, reflect is only declared once in the shader. Is it possible that the code got messed up in the paste into project somehow? How did you get the code into Codea? (ie was it with the in-app browser "copy" button from the gist, or some other method?)
It loads ok for me. But for some reason no models show up.
It looks like this, no matter which model i choose:
http://s15.postimg.org/pedgnauh7/image.jpg
The more complex models (like the shuttle) will take a few seconds to download the first time you load them. 6, the vertex painting example, should be quick, because there's no texture, so it only has to request a few kb from GitHub. @juce you don't see anything when you load number 6?
@yojimbo2000, sorry, i spoke too soon. If i comment out lines 64 and 65, then i see the same error as @Jmv38 for model 6:
It seems that reflect is a reserved word, and perhaps cannot be used as a variable. I did a global replace of it with reflectx and now it all works like a charm. Very cool! Awesome 3D models too.
@juce glad you got it working and thanks for the bug report. I wonder why I don't have that issue? Are you a Codea beta tester? I'm on Codea 2.2(35) and iOS 8.1.3. Did I read somewhere that the shader specification changed at some point? @Jmv38 could you also try to do a search replace on reflect?
I made the vertex painting model very quickly in Blender, and it has some overlapping faces because the handwriting-style fonts overlap, so it does flicker a bit. Probably best to use a non-joined-up typeface for that kind of thing
@yojimbo2000 @Juce the trick worked great. I wonder how it could work on your side with the reserved word? Anyway, these models are AWSOME. Thanks for sharing.
@yojimbo2000 maybe you could update the gist with the new code?
I haven't run it yet, but I saw the models include the space shuttle, ME262, spitfire etc that I put together a while back. As I recall, the Merc(edes) model was broken.
There is a bit of an art in selecting models that work well in Codea. I generally looked for models that weren't too large (eg files size below 1 nb), didn't have complex texturing, and didn't require animation. And then not all models work, for one reason or another.
I've since added quite a few more models for use in my 3D dungeon, including weapons, a metal cage, a couple of nasty spiders and zombies etc.
OK, the gist has been updated. Does the totalColor error also disappear once you change the name of the reflect variable? I wonder why I don't get that error.... Do different iPads run slightly different versions of Open GL ES? I'm on an iPad Air
totalColor error disappears because it used reflect in its definition, so once that was sorted out, totalColor was good too. I am on iPad 2, btw. (The old one, not Retina). iOS 7.1.2
Actually, I think the reflect error was caused by either a Codea or iOS update a while back. That old code hasn't been updated.
I think I might have found the answer here:
http://codea.io/talk/discussion/comment/39186/#Comment_39186
Thanks to all for the bug reports. The .ply parsing code has not been plumbed in in a very elegant way (my bad) but it seems to work
As long as it works that's all that matters =D>
Do you mind if I name the villain in my next game Zordon?
He's gone so he won't mind
@Ignatz, did you have to delete his posts by hand, or does Vanilla do that now when you delete a user?
Vanilla gives you a choice of deleting posts or not.
In this case, I went for the head shot.