Home
JAQForum Ver 20.06
Log In or Join  
Active Topics
Local Time 21:12 29 Mar 2024 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : CMM2: 3D Object Viewer

Author Message
vegipete

Guru

Joined: 29/01/2013
Location: Canada
Posts: 1081
Posted: 06:35am 30 Nov 2020
Copy link to clipboard 
Print this post

Peter Mather is doing amazing work building a 3D engine for our beloved Colour Maximite 2 computer.

To help in a small way with this 3D work, here is a program for looking at 3D objects. This program does not use any of the new DRAW3D commands, so it should work on older firmware just fine. And it shows just how blazing fast this 'retro' computer is. If I tried to run this sort of stuff on my Apple//, I would have quit long ago and gone back to chewing on my wife's shoes.

An interesting side effect of this program is that it has shown 'data errors' in the eliteships zip file PeteCotton posted on page 11 of The Great Colour Maximite 2 Octahedron Prize Challenge thread. Object 4 in my program is a shape from that file, the 'e2drake' spaceship. The vertices of some of the faces in that file are not in counter-clockwise order. But my program made it mush easier to find the problems and correct them. (Hint: much toggling between wireframe and hidden line removal :-)

' 3D Object Viewer
' by vegipete, November, 2020
'
' This program allows the user to examine 3D objects from different angles
' and at different zoom levels and perspective settings. Hidden lines can
' be toggled on and off, as can be vertex and face labelling.
' Objects are defined by some number of faces. (max 50, untested)
' Each face is defined by some number of vertices. (max 8)
' Each vertex is defined by (x,y,z) coordinates, normalized.
' This means that all vertices should be within a unit sphere.
' Adjust the value of 'size' to change this.
' For example, set size = 1 to use 'full sized' model data
'
' A Painter's algorithm is used to draw the object faces in order from
' farthest (visible) face to nearest, allowing both convex and simpler
' concave objects to be drawn correctly. No doubt extreme concave objects
' can cause display problems. This also results in some vertex labels
' being shown even if the vertex is hidden by a nearer face.
'
' The object is placed according to its vertex data. Typically an object
' would be centered at the origin but this is not required.
' The user is free to move in polar coordinates around the object.
'
' keys: (all in lower case only)
' l:   (lower case L) toggle vertex and face labels on and off
' f:   toggle fill on and off
' (j/k) Roll:  adjust viewer roll around the line of sight
' (w/x) Pitch: adjust viewer angle down from positive Z axis
' (a/d) Yaw:   adjust viewer angle around Z axis, from positive X axis
' (i/m) Rho:   change distance of viewer from origin
' (u/n) View:  change distance of projection plane from viewer
' (y/b) Both:  linked change both Rho and View simultaneously
' (0-9)   display selected model number, if available (default is 2)
'         study the data statements at the end of the program, plus the
'         last subroutine LoadShape to add more shapes.


Hopefully some of you will find this useful.


ObjectView3D.zip
Visit Vegipete's *Mite Library for cool programs.
 
LeoNicolas

Guru

Joined: 07/10/2020
Location: Canada
Posts: 433
Posted: 07:16am 30 Nov 2020
Copy link to clipboard 
Print this post

Amazing job VegiPete

Very clear code, so well organized and commented.
 
jirsoft

Guru

Joined: 18/09/2020
Location: Czech Republic
Posts: 532
Posted: 10:19am 30 Nov 2020
Copy link to clipboard 
Print this post

  vegipete said  Peter Mather is doing amazing work building a 3D engine for our beloved Colour Maximite 2 computer.

To help in a small way with this 3D work, here is a program for looking at 3D objects. This program does not use any of the new DRAW3D commands, so it should work on older firmware just fine. And it shows just how blazing fast this 'retro' computer is. If I tried to run this sort of stuff on my Apple//, I would have quit long ago and gone back to chewing on my wife's shoes.


Hi vegipete,
I was planned to incorporate simple 3D viewer into Napoleon Commander, may I reuse your code (and maybe simplify it, I don't need big functionality)?
Another question is, if does exist some universal format for file with CMM2 3D obejct (.PLY?), when not, it make sense to design it...
Jiri
Napoleon Commander and SimplEd for CMM2 (GitHub),  CMM2.fun
 
vegipete

Guru

Joined: 29/01/2013
Location: Canada
Posts: 1081
Posted: 05:40pm 30 Nov 2020
Copy link to clipboard 
Print this post

@Leo, thanks. Writing this stuff has been a great way to learn the ins and outs of 3D programming. Clear and commented code helps me, and hopefully can help others too.

@Jiri, you certainly can use it as you see fit. Keep in mind though that much of the code will disappear when it gets re-written to use the new 3D engine.

No standard CMM2 file format has been defined yet. There is some appeal to the old VRML format. Object files in this format already exist out there and there are existing Windows/Mac/Linux programs that understand it. PeteCotton is writing a vrml loader.
Visit Vegipete's *Mite Library for cool programs.
 
vegipete

Guru

Joined: 29/01/2013
Location: Canada
Posts: 1081
Posted: 02:51am 04 Dec 2020
Copy link to clipboard 
Print this post

Here is an update to ObjectView3D.
Version 02

N E W   A N D   I M P R O V E D ! ! ! !

Added faces with more than 3 edges.
Improved hidden line mode.
Added support for concave shapes.
Added more built-in shapes.
   Now includes tetrahedron, cube, octahedron, dodecahedron,
   icosahedron, brick arc, E2drake ship from Elite
Added *.ply file loading.
Added object scaling.
Added face reversing. (For shapes with clockwise faces)
Added smoother rotation.
Changed some notation.

Key commands are extensive, so pay attention:
' keys: (all in lower case only)
' l:   (lower case L) toggle vertex and face labels on and off
' s:   toggle fill on and off
' r:   reverse all face vertex order
' f:   load a *.PLY file from disk
' c:   scale object ( >1 to increase, <1 to shrink, negative to invert)
' (j/k) Roll:      adjust viewer roll around the line of sight
' (w/x) Latitude:  adjust viewer angle down from positive Z axis
' (a/d) Longitude: adjust viewer angle around Z axis, from positive X axis
' (i/m) Rho:       change distance of viewer from origin
' (u/n) View:      change distance of projection plane from viewer
' (y/b) Both:      linked change both Rho and View simultaneously
' (0-9)   display selected model number, if available (default is 2)


Some notes about 'r', face reversing.
Mathematical convention says that the vertices of a face should be given in counter-clockwise order. This is used to determine visibility. However, there are models out there that have face vertices in clockwise order. These display most strangely. You can fix this with the 'r' command, or by scaling the object by -1.

Sources of *.PLY files:
They can be found on the internet.
Mauro's DemoX has a bunch. Check his github repository.
Very large files can become unwieldy. If you get an index out of bounds error when loading something, try increasing the value of 'maxelements', line 71.

ObjectView3D_v02.zip
Visit Vegipete's *Mite Library for cool programs.
 
MauroXavier
Guru

Joined: 06/03/2016
Location: Brazil
Posts: 303
Posted: 05:51pm 04 Dec 2020
Copy link to clipboard 
Print this post

Here is some PLY files that I converted from some places, but I turned many of them more simplified removing colours and textures:
PLY.zip
 
Print this page


To reply to this topic, you need to log in.

© JAQ Software 2024