Log In  


Cart [#34798#] | Copy | Code | 2017-01-02 | Link

old version:

Cart [#32573#] | Copy | Code | 2016-11-17 | Link

Here is a cleaned up version of the 3D library that I put together for the Pico Fox game.

The demo code is commented in more detail, but here is the basic gist.

Copy the code between Begin Cut and End Cut. (It's a big chunk.)

In _init() function include:
--init_3d() --Need to call init_3d() to set up player, camera and lights
--use load_object(object_vertices,object_faces,x,y,z,ax,ay,az,obstacle,color_mode,color) to load 3D models into the world
--use read_vector_string and read_face_string to generate vertex list and face list from string data

In _update() function include:
--handle_buttons() -- handle default buttons for player-- this can be overwritten obviously.
--update_player() -- update the player with default movement, stopping at obstacles
--update_camera() -- update the camera based on player location and direction
--update_particles() --update 3D particles if used. (I didn't add any for this demo.)
--update_3d() -- call update_3d() at the end of the _update() function to transform etc.

in _draw() function include:
--draw_3d() --render objects into triangles, sort the triangles and draw them onto the screen

Please feel free to use this in your projects as well as to update it and make it work better.

New features for version 2:
--Significant speed increase (2X!)
--Load models from strings to save token space
--Python script to translate from ".obj" files to compressed string

Run the script in the folder with the files that you are converting.
python low_poly_compress-01.py filename.obj

Detailed instructions and script found on GitHub.

3d library
P#32574 2016-11-17 01:56


awesome! thanks so much for sharing!

P#32577 2016-11-17 06:13


Great stuff! Thanks for that

P#32578 2016-11-17 08:22


This is fantastic. Thanks!

P#32579 2016-11-17 09:29


Tremendous stuff.

P#32586 2016-11-17 15:19


Thanks for the share, looking forward to seeing some projects using this.

P#32632 2016-11-19 18:11


Thanks for sharing! I made a tiny game with this. https://www.lexaloffle.com/bbs/?tid=28139

P#32960 2016-12-03 07:16


I optimized the rendering of the engine--more than double the speed for dynamically shaded models.

The most significant tweaks were:
--New triangle rendering code based on the results of the triangle thunderdome thread
--Faster quicksort replaces bubblesort
--Projecting points more efficiently (I was projecting the same vertex multiple times previously

These, combined with some in-lining and other optimizations pushed the speed up quite a bit so that "large=338 faces" models can be rendered in real time with shading.

I also added functions to load objects from strings as opposed to massive arrays of numbers. Those arrays are nice and readable, but they chew through tokens.
The conversion script can be downloaded here: https://github.com/electricgryphon/Pico-8-Gryphon-3D-Engine-Library

P#34802 2017-01-02 21:48


How do you do that? Seriously, how do you make a 3D engine? I realize this is probably a really broad question, but I wouldn't even know where to start :o

Also, if you can't tell, I'm super impressed. @.@

P#34865 2017-01-03 15:25


@electricGryphon: Great job! I loved this before, and this is a huge improvement!

@Lumiette: Definitely check out the code; it's well commented and messing with it a bit should help you start to understand how it works.

P#34870 2017-01-03 16:45


Great work! Want to try and make something with this library but the link to the Python script is broken. Could you please reupload it? Thanks!

P#35047 2017-01-05 21:54


Try this: http://s000.tinyupload.com/index.php?file_id=56902566375777023329
I updated the link in the description as well.

P#35053 2017-01-06 01:22


Thank you, link works now.

Haven't been able to succesfully convert an .obj though.
Tried running the script with Python 2.7 and 3.6 but both don't work. I'm trying to convert a basic cube. (The one you get when you open Blender) I get two errors at the parts when num_text is stored in val. In the model_v line there is an "n" that can't be converted to float and in the model_f line all data looks like "1//2" and thus can't be converted to int.

Have tried simply filtering the n and // out but that doesn't work obviously. :-) Not really familiar with the .obj file structure so not sure what I'm doing wrong.

P#35154 2017-01-07 10:09


Thanks for the heads up--I may have tweaked some blender settings.

I'll put together a proper tutorial.

P#35167 2017-01-07 12:55


Here's a link to a tutorial on how to convert files using the script:
(This is also added to the cart description.)

Let me know if anything is unclear or if you have problems and I will update the document.


P#35175 2017-01-07 16:07


Thank you for the tutorial and the fast response! :) Works perfectly and have already started working on some simple player stuff. (Thinking of making a simple shooting gallery)

P#35199 2017-01-07 19:29


Hey this is great! I got some models loaded and it's pretty fast! What would be the best way to set the color of the individual faces?

P#38812 2017-03-28 10:18


Hey electricgryphon, I'd love to see copies of the .obj files used for these demos and/or picofox as well if you've still got them. Do you think you could put them on Github? I'm new to blender, and it'd be cool to have something to play around with so I know I'm on the right track with the model creation. Thanks!

EDIT: previously, this said I couldn't access any of the tinyupload URLs, the issue has since resolved itself.

P#38873 2017-03-30 03:24


Awesome stuff.

P#38921 2017-03-31 15:31


Tools and instructions are loaded on GitHub.


I have also included a demo blender file for a basic animal.

Currently there is no support for automatic importing blender files with individual face colors. (On the PicoFox program, I did this by hand :-/ ) This is definitely on the list of features to be added in the next version.

-Electric Gryphon

P#38981 2017-04-01 12:49


best doggo

P#39009 2017-04-02 14:56


Hi electricgryphon,

I'm trying to port the lib to C, and I'm running into a problem with some of the bitwise operations. Here in particular: https://github.com/computermouth/eg3d/blob/master/render.c#L2020

I can't quite figure out what value this is supposed to be retrieving. I wonder if it's some sort of floating point magic? I tweeted at zep here https://twitter.com/ComputerMouth/status/854203622095077378

At first I thought it was a bug, but the more I look at it, the more it seems like the library actually depends on this behaviour. Any tips?

-- Ben

P#39756 2017-04-18 13:12


Hi Computermouth,

Pico 8 stores numbers in a fixed point format of 0xFFFF.FFFF.
In this case, I'm using band(val,0xffff) as a way to speed up floor().

Zep reduced the function overhead CPU cost of bitwise operations so one way to speed up programs is to use these operations whenever possible.


P#39767 2017-04-18 22:10


electricgryphon, I've kept forgetting to reference something I've did months ago, was to work on something with your lib but sadly pico-8 is too limited for it and kinda moved to other non-pico8 related stuff =/
You can have a look at the converter for blender: https://github.com/justburn/EGryphon3DLibPanel

Oh... and as a bonus (Inspired by Picofox):

Cart [#39790#] | Copy | Code | 2017-04-20 | Link

Cart [#39791#] | Copy | Code | 2017-04-20 | Link

P#39792 2017-04-20 02:56


Hi JustBurner,

Your arrangements of the StarFox songs are great! Could I pull them into the game? Some proper menu music, like you provided, will work wonders.

The blender export will also come in handy--i've been writing offline conversion scripts, but this could save some steps.


P#39802 2017-04-20 16:54


Sure, I'll be glad if you use them into your game! (Corneria is 3 channels instead of 4 for a reason), it will need some tweak to join them together and add sfx.

If you're going to update your game don't forget to fix a bug in the center_text function and "cornerea" typo... could say to upgrade for v2 of the engine but that's asking too much ;)

P#39803 2017-04-21 03:12

Log in to post a comment


New User | Account Help
:: New User
About | Contact | Updates | Terms of Use
Follow Lexaloffle:        
Generated 2017-04-26 19:29 | 0.203s | 1835k | Q:54