? Poly3D ● SmileBASIC Source

Sign In

Register
*Usernames are case-sensitive
Forgot my password
[Help Wanted] SmileBASIC Documentation Project

Poly3D

Submitted
Updated
Author
kevinfoley
Public Key
4KE3N396
Min. Compat.
All
Version
1.1.0
Size
263 KB
Rating
20 votes
Description Poly3D is a flat-shaded 3D engine for SmileBASIC. The engine supports flat-shaded polygonal 3D models defined with triangles (no lighting support). It is a lightweight engine optimized for performance. This engine evolved from my earlier Wire3D engine. Performance tests (New 3DS, rendering rotating models, no gameplay code): 0 - 190 triangles onscreen: 60fps 190 - 390 triangles onscreen: 30fps 390 - 630 triangles onscreen: 20fps 660 triangles onscreen: 15fps Version 1.1.0 (13 December 2018)
  1. Added FIRSTPERSON example game. Move around and shoot targets as fast as possible. Demonstrates depth-sorting, 3D camera movement and rotation, and basic collision detection. 60 fps on a New 3DS
  2. (No engine changes)
Version 1.1.0 (2 November 2018)
  1. Added STARBLITZ example game. Fly your spaceship and avoid the obstacles. Demonstrates depth-sorting, 3D movement and rotation, and basic collision detection. 60 fps on a New 3DS
  2. Engine, Model Editor: Fixed numerous issues with axes being double-or-triple reversed
  3. Model Editor: Fixed vertex movement controls sometimes being reversed
  4. Model Editor: Reversed the z-axis. Now the coordinate system behaves like Blender 3D, as I had originally intended
  5. Model Editor: Added some parsing code for OBJ files (not tested; how would I get an OBJ file into SB in the first place?)
  6. Model Editor: Added buttons for copying and pasting face colors
  7. Many other minor bug fixes
Version 1.0.1 (24 October 2018)
  1. Fixed error if you deleted all faces from a model
  2. Fixed slider values being constantly reapplied until you tapped somewhere else on the touch screen
  3. Save/Load remembers the last file name you entered, so that you don't have to keep re-typing it each time you save
  4. Added an example model Pumpkin.3D
Version 1.0 (24 October 2018):
  1. Rewrote Poly3D into a compact common library that can be easily used by other programs
  2. Added Poly3D Model Editor v1.0 (compatible with New 3DS or Circle Pad Pro). This is a simple model editor with limited features, but should be good enough for creating simple models. - Create 3D models with colored faces - Save / Load 3D model files - Camera controls - In addition to the main camera, the model is displayed as a wireframe in three orthogonal views (Front, Left, Top) on the touch screen - Undo / Redo functionality
  3. Added a GUI library which can be used to draw interactive buttons, checkboxes, and sliders on the touch screen Note: I released this latest update much earlier than I was planning, so that others can use the included model editor. This version does not contain any other example projects. I am hoping to release another update sometime in the next month or so with additional examples of the engine in use, but can't make any promises. Hopefully I won't disappear for 3 years again! :)
Version 0.8 update: *Supports rotation on all 3 axes (uses Euler rotation and suffers from gimbal lock, so I don't recommend rotating on all 3 axes at the same time) *Uses GPAGE buffer to eliminate draw flicker (thanks Trinitro!) *Fixed support for multiple models in a single scene *Added two new models, a cube and a Starwing, which definitely isn't borrowed from any old Nintendo games *Added more models and animations to the sample scene to better demonstrate the engine. The sample scene includes over 200 polys and runs at 60fps on a New 3DS Version 0.7 (initial): *Supports 3D models with per-face coloration *Supports instancing models, reducing memory usage *Models can be translated and rotated *Depth-sorting so faces are rendered in the correct order *Screen-space culling - models that lie outside the screen coordinates are not processed, reducing render time *User can walk around with D-pad or analog stick and aim with touch-screen or gyro controls *Faces darken with distance, so models gradually fade into background *Radar on lower screen shows player position in relation to models *Code is reasonably well-documented *Sample scene included Planned features for the future: *Support for lighting *Scaling support for models *Actual gameplay features Known issues: *There is some distortion to the models when rotating on X and Y axis at the same time; I'm looking into it
Instructions Controls for Starblitz: D-Pad moves camera, Circle Pad moves ship Controls for FirstPerson: Circle-pad to move, touch-screen to aim, L or R to shoot Instructions for using the model editor: Load P3DModelEditor into Slot 0, and press Start. The model editor launches with a default cube model. The general idea is that you position points, called "vertices", and then connect them with triangles, called "faces". For example, a cube has 8 corners, so it has 8 vertices. Each side of a cube is a square, which requires two triangles to draw, so 12 faces in total. Controls: - A: Start moving vertex; confirm vertex position (Vertex mode). Confirm selected vertex (Add Face mode) - B: Cancel moving vertex (Vertex mode) - X: Select next vertex/face - Y: Select previous vertex/face - L: (hold) Increase movement speed (while moving vertex in Vertex mode) - R: (hold) Decrease movement speed (while moving vertex in Vertex mode) Touch screen controls should be mostly self-explanatory.
  1. To create new vertices, press "Add Vert" while in Vertex mode.
  2. To create new faces, press "Add Face". Select the first vertex and press "A". Repeat for two more vertices. When three have been selected, a new face (triangle) is created that connects the three selected vertices.
  3. The RGB sliders can be used to edit the color of the selected face in Face mode. They have no effect in other modes.
Note: this engine is unrelated to the P3D engine; the "P3D" in "P3DModelEditor" is short for "Poly3D".
Notes Includes: - POLY3D.LIB: Engine library - GUILIB.LIB: Touchscreen GUI library - P3DMODELEDITOR: Model editor for Poly3D - STARBLITZ: simple example game, fly your ship and avoid crashing into obstacles
Categories
Keywords
  • 3d
  • engine
  • render
  • model
  • editor
83 Comment(s) kevinfoley kevinfoley I've added a simple first-person shooter demo where you can move around and shoot missiles at targets (it re-uses the models from the Starblitz demo). Real life has me pretty busy, but if I have time I'll eventually expand the demo into something a little fancier. Shelly Shelly Would you please consider adding support for different types of shading? kevinfoley kevinfoley Lighting is not a high priority for me; it would also probably require keeping track of face normals, which I don't do right now and wasn't planning on doing. However, there may be some simple way to BS lighting based on the model's rotation. I'll mull it over. Simeon Simeon Scholar Received for knowing a great deal about programming topics Achievements Amazing Page Hidden Achievements Drawing I like to draw! Hobbies Sometimes triangles disappear when they are near-orthogonal to the camera. Your code currently draws the backfaces of models which means that when you have perspective and you sort, the back faces will sometimes be closer than the front when near-orthogonal to the camera. Adding this line of code will only draw one side of triangles, meaning the back faces will be skipped. It should also greatly boost your performance. Inside of the site's most up-to-date POLY3D.LIB file, consider adding the following to line 124 (maybe line 165 too). IF ((POINTS[E2,0] -POINTS[E1,0]) *(POINTS[E3,1] -POINTS[E1,1]) -(POINTS[E2,1] -POINTS[E1,1]) *(POINTS[E3,0] -POINTS[E1,0])) >=0 THEN CONTINUEThe only issue is that this requires you to update all of your models, since there are inconsistencies in defining clockwise/counterclockwise triangles, so the models are a bit jumbled up, but only one side of them now gets drawn. I guess this also depends on how you want it to be, since your STARBLITZ demo (which is really awesome btw) has one-triangle-wide wings, which behaves wrong with this change. So, just consider it. kevinfoley kevinfoley I've never noticed triangles to disappear completely, but I'll keep an eye out for that. I thought about trying to incorporate normals for the purpose of backface culling and potentially lighting, but I didn't think it would be worth the tradeoffs and performance overhead. I like being able to use the two-sided triangles for flat details, like the wings that you mentioned. Another benefit is that you can make a line by connecting two of the three corners of a triangle to the same vertex, thus not requiring any extra code or edge cases to support lines. I've noticed that SIM.3D also has issues with occasionally drawing triangles out of order, causing similar flickering near corners. Thanks, I'm glad you enjoyed the STARBLITZ demo. I may expand it more after I add a few additional demos. Were you able to adapt the model editor for SIM.3D? DFrost DFrost Expert Programmer Programming no longer gives me any trouble. Come to me for help, if you like! Programming Strength once this is like SANIC, you make is even faster by using sprites instead of GTRI, since you would be using sprites, it would be twice as fast when rendering a triangles. This also brings in textures to the mix. We might actually get an engine capable of running games like Crash Bandicoot(1996) at 30FPS Also I have noticed an exceptional difference of rendering speed when you constrain it all to the screen(s). Here is what I used(roughly): VAR M%,IT% 'draw IT% times because it is less noticable on small scale applications FOR I = 1 TO IT% GFILL 0,0,511,511 NEXT ?MILLISEC - M% GCLIP 0,0,399,239 M% = MILLISEC FOR I = 1 TO IT% GFILL 0,0,511,511 NEXT ?MILLISEC-M% if this doesn't produce usable results, just increase IT% this also takes care of off - screen culling, too. The culling only actually helps if a part of a triangle is on - screen. If not even a single pixel of a triangle is onscreen, the culling becomes ineffective. GCLIP actually is really useful in this scenario, but even SPCLIP and BGCLIP help, accordingly to what is being rendered. kevinfoley kevinfoley I do not think rendering with sprites is practical. I already have a fast screen culling method in Poly3D. My culling method skips not only the drawing, but also many of the 3D calculations. Maybe I'm just not following you, but I don't see how your example code would help. kevinfoley kevinfoley As far as I can tell, the Givers P3D game only uses triangle sprites for rendering the intro animation, and the result is an ugly mess of misaligned sprites. The rest of the gameplay seems to use flat-colored faces probably drawn with graphics commands. If you think you can make a 3D engine with sprites, go ahead, but I personally have no interest in trying to rewrite my engine to use sprites. DFrost DFrost Expert Programmer Programming no longer gives me any trouble. Come to me for help, if you like! Programming Strength let's say we have a triangle that is partially off - screen. It would draw the rest of the triangle(offscreen) anyway. All I'm doing with this code is showing how GCLIP can improve performance by making it check "is this pixel I'm about to draw past the boundaries? Yes, so I can skip this one" this code proves sprites are faster to draw: VAR M%,I% M% = MILLISEC WHILE MILLISEC-M%<1001:GFILL I,0,15,15:INC I%:WEND ?"a moving box can be drawed",I%,"times a second" I% = 0'reset it from our last test SPSET 0,0'16x16 size 'since we are only [i]moving[/i] the sprite anddrawing it, don't include initialization of it. M% = MILLISEC WHILE MILLISEC - M%<1001: SPOFS 0,I%,0:INC I%:WEND ?"a moving sprite can be drawed",I%,"times a second" DFrost DFrost Expert Programmer Programming no longer gives me any trouble. Come to me for help, if you like! Programming Strength also P3D has unaligned sprites because of the trashy way SB scales sprites. Shelly Shelly Could you release some information on the kind of speed we can expect? What is the maximum number of triangles it can render per frame? kevinfoley kevinfoley Here's what I see from simple tests, rendering multiple copies of the 39-poly pumpkin: 0 - 190 triangles: 60fps 190- 390 triangles: 30fps 390 - 630 triangles: 20fps 660 triangles: 15fps This is with a simple scene rendering rotating models and doing a few input calculations. In a game, performance may be slowed down by gameplay code. You may also get better performance when rendering fewer models with more polygons per model, because there's some overhead for each additional model. Simeon Simeon Scholar Received for knowing a great deal about programming topics Achievements Amazing Page Hidden Achievements Drawing I like to draw! Hobbies I may be able to help you add DLC support as well, since that would boost performance through the roof... and since I can possibly reuse old code. I really hope this project continues development, it will be very useful. Shelly Shelly Hmm... not bad at all. That's not that much slower than SIM.3d, and SIM.3d uses ARYOP too. Is that old or new 3ds? kevinfoley kevinfoley New 3DS; sorry for not clarifying. Simeon Simeon Scholar Received for knowing a great deal about programming topics Achievements Amazing Page Hidden Achievements Drawing I like to draw! Hobbies It's a bit difficult to control. but I can see this being really handy for 3D model making! The code is pretty straightforward, and well documented. Can you possibly add an export-to-text option, or a better way to access .3D/.3DM files? If I could have access to every triangle point, then this would be really convenient for me, and other developers here too! Thanks for making this! kevinfoley kevinfoley Thanks! The code for exporting and importing models is at the bottom of P3DMODELEDITOR. That should give you all the information you need to access the data, and is much faster to work with than text. The save format is really very straightforward, and it should be easy to write a parser (or copy and modify my own parsing code). Is there a reason you wanted text rather than an array of numbers? I am working on an update that fixes some issues with coordinates being double-or-triple-reversed, and will probably release that in the next few days. 12Me21 12Me21 Head Admin Second Year My account is over 2 years old Website Syntax Highlighter Received for creating the code syntax highlighter on SBS Night Person I like the quiet night and sleep late. Express Yourself .obj is extremely simple and widely used, so it might be worth adding a way to import/export files in this format. kevinfoley kevinfoley Hmm, good suggestion. I think I could do an OBJ import/exporter without too much trouble. kevinfoley kevinfoley @12Me21 Well, I wrote some simple code that could hopefully parse an OBJ file, but how would I get an OBJ file from my PC into SmileBASIC? 12Me21 12Me21 Head Admin Second Year My account is over 2 years old Website Syntax Highlighter Received for creating the code syntax highlighter on SBS Night Person I like the quiet night and sleep late. Express Yourself http://smilebasicsource.com/page?pid=812 random_god random_god Intermediate Programmer I can make programs, but I still have trouble here and there. Programming Strength Zelda Is Awesome! I love The Legend Of Zelda! Express Yourself Video Games I like to play video games! Hobbies lol yeah kevinfoley kevinfoley I've released an update with general improvements and fixes to how axes/coordinates are handled, and a new demo game. The update also has the OBJ parsing code that I haven't tested. I'll need to copy a model file onto my 3DS using the modem app in order to try that. kevinfoley kevinfoley Several years after the last release, I finally got the urge to start working on this project again. I have completely overhauled the original messy code into a highly streamlined common library. I've also developed a simple 3D model editor to go with the engine. I haven't uploaded the new code yet, but will do so in the next week or two. Simeon Simeon Scholar Received for knowing a great deal about programming topics Achievements Amazing Page Hidden Achievements Drawing I like to draw! Hobbies That's exciting! I'll be sure to be one of the first to check it out. No rush! kevinfoley kevinfoley I've uploaded the new version with model editor, and updated the download key. Shelly Shelly How does it work? kevinfoley kevinfoley This is a rather broad question. Models are defined as vertices (points in space with x, y, and z coordinates), faces (triangles that connect vertices), and colors (each face has a color). Given a 3D model and transformation properties (position, rotation, and scale) the engine uses trigonometry to determine where and how to draw the 3D model on the screen. h267 h267 RNG Hidden Easter Eggs Pokemon Is Awesome! I love Pokemon! Express Yourself Good Page Hidden Achievements You should make a custom model creator. Depending on the scale of this, this could be used to make 3D game pieces in SmileBASIC. Comboned with the raycaster, you have a full 3D game. 12Me21 12Me21 Head Admin Second Year My account is over 2 years old Website Syntax Highlighter Received for creating the code syntax highlighter on SBS Night Person I like the quiet night and sleep late. Express Yourself I think someone is working on one now Super_Defaultio Super_Defaultio Video Games I like to play video games! Hobbies Day Person I like the warm sunshine and wake up early! Express Yourself Zelda Is Awesome! I love The Legend Of Zelda! Express Yourself Well it might be too slow for a 3d polygon and a raycaster all at once. SB can only do so much. ThatStupidGuy ThatStupidGuy Avatar Taboo I didn't change my avatar for 180 days Website Avatar Embargo I didn't change my avatar for 90 days Website Avatar Block I didn't change my avatar for 30 days. Website Ahem: BBW3E88V https://twitter.com/Bug_taro/status/691996196626272257 Super_Defaultio Super_Defaultio Video Games I like to play video games! Hobbies Day Person I like the warm sunshine and wake up early! Express Yourself Zelda Is Awesome! I love The Legend Of Zelda! Express Yourself Where is this program, what happened to it and how? YOU REALLY PROVED ME WRONG.... OMG I WUV DIS ThatStupidGuy ThatStupidGuy Avatar Taboo I didn't change my avatar for 180 days Website Avatar Embargo I didn't change my avatar for 90 days Website Avatar Block I didn't change my avatar for 30 days. Website Ha. Guzzler Guzzler First Week Joined in the very first week of SmileBASIC Source Website Drawing I like to draw! Hobbies Intermediate Programmer I can make programs, but I still have trouble here and there. Programming Strength Yes make it please! kevinfoley kevinfoley I have developed a simple 3D model editor and will release it soon. Minxrod Minxrod Summer 2016 Contest Participant I participated in the SmileBASIC Source Summer 2016 Contest! Programming Contest Expert Programmer Programming no longer gives me any trouble. Come to me for help, if you like! Programming Strength Pokemon Is Awesome! I love Pokemon! Express Yourself This is so neat :D But I have no idea how the models are made. I don't understand how they are defined... if someone knows can they explain to me please? kevinfoley kevinfoley They're defined in data at the bottom of the program. Each model consists of a set of vertices and a set of faces that connect the vertices. The way I bundled them together is kind of messy and hard to follow, but I'm hoping to improve it in the next version. If you don't know what "vertices" or "faces" are, you might want to do some research on 3D modelling in general. Minxrod Minxrod Summer 2016 Contest Participant I participated in the SmileBASIC Source Summer 2016 Contest! Programming Contest Expert Programmer Programming no longer gives me any trouble. Come to me for help, if you like! Programming Strength Pokemon Is Awesome! I love Pokemon! Express Yourself Oh, you define vertices and then basically sets of those vertices? DasEtwas DasEtwas What happens if two polys overlap? Super_Defaultio Super_Defaultio Video Games I like to play video games! Hobbies Day Person I like the warm sunshine and wake up early! Express Yourself Zelda Is Awesome! I love The Legend Of Zelda! Express Yourself its just an overlaping polygon. 12Me21 12Me21 Head Admin Second Year My account is over 2 years old Website Syntax Highlighter Received for creating the code syntax highlighter on SBS Night Person I like the quiet night and sleep late. Express Yourself possibly z fighting kevinfoley kevinfoley There's an algorithm to determine the draw order of polygons; if two overlap, it's going to draw one of them on top of the other based on that algorithm. That can look weird but doesn't come up very often. Super_Defaultio Super_Defaultio Video Games I like to play video games! Hobbies Day Person I like the warm sunshine and wake up early! Express Yourself Zelda Is Awesome! I love The Legend Of Zelda! Express Yourself What's the syntax for creating a polygon? PixelStudio PixelStudio "*Actual gameplay features" Hype hype hype kevinfoley kevinfoley Er, okay? kldck_hul kldck_hul First Month Joined in the very first month of SmileBASIC Source Website Scholar Received for knowing a great deal about programming topics Achievements Zelda Is Awesome! I love The Legend Of Zelda! Express Yourself *Actual gameplay features What does this include? Are we going to get any scene graphs etc? I'm also curious if this does any back-face culling? kevinfoley kevinfoley Actual gameplay features would include things such as collision detection and maybe a pooling system. I'm working on a demo game that uses a refined version of the engine, but had to take a break due to the holidays. I'll be starting on it again soon. Super_Defaultio Super_Defaultio Video Games I like to play video games! Hobbies Day Person I like the warm sunshine and wake up early! Express Yourself Zelda Is Awesome! I love The Legend Of Zelda! Express Yourself Model maker? PixelStudio PixelStudio On line 537 change data to DATA 50,32,24 and it looks like the ships are firing at the tie fighters Ptcguy Ptcguy First Week Joined in the very first week of SmileBASIC Source Website Minecraft Is Awesome! I love Minecraft! Express Yourself Beginner Programmer I'm just starting out! I'm still trying to grasp the basics. Programming Strength cool PixelStudio PixelStudio This is amazing! Imagine one of these bad boys flying into a fps map and idk, drops supplies or something? Even if it can't be physically there it will sure add a neat effect to the game :) although I can be taking it too far... Super_Defaultio Super_Defaultio Video Games I like to play video games! Hobbies Day Person I like the warm sunshine and wake up early! Express Yourself Zelda Is Awesome! I love The Legend Of Zelda! Express Yourself 1 word: a person. Just a person. Do it. kevinfoley kevinfoley What do you mean? Are you asking me to model a person, or what? Super_Defaultio Super_Defaultio Video Games I like to play video games! Hobbies Day Person I like the warm sunshine and wake up early! Express Yourself Zelda Is Awesome! I love The Legend Of Zelda! Express Yourself Yes, make a person.. like a polygonal model of a person. doesn't have to be good. kevinfoley kevinfoley Sorry, this sounds like a waste of time. A person isn't very interesting unless it's animated, and animating a person in code would be hell. Super_Defaultio Super_Defaultio Video Games I like to play video games! Hobbies Day Person I like the warm sunshine and wake up early! Express Yourself Zelda Is Awesome! I love The Legend Of Zelda! Express Yourself It doesn't seem boring to me.... Y_ack Y_ack How many polygons is that in the first (second uploaded) image? Maybe I underestimated Smilebasic. blizord blizord Day Person I like the warm sunshine and wake up early! Express Yourself Night Person I like the quiet night and sleep late. Express Yourself Ten I think. They move quickly and in many directions too. kevinfoley kevinfoley Lol. Ten models, not ten faces. There are about 220 faces in this scene. kevinfoley kevinfoley I'm used to saying faces, which is really 3D modelling lingo - polygons and faces are the same thing here. Guzzler Guzzler First Week Joined in the very first week of SmileBASIC Source Website Drawing I like to draw! Hobbies Intermediate Programmer I can make programs, but I still have trouble here and there. Programming Strength Wow, this is really "shaping" up! 1 2