Using blender models in KGL (is jfm the best option?)

If you have any questions on programming, this is the place to ask them, whether you're a newbie or an experienced programmer. Discussion on programming in general is also welcome. We will help you with programming homework, but we will not do your work for you! Any porting requests must be made in Developmental Ideas.
User avatar
Dev
DCEmu Fast Newbie
DCEmu Fast Newbie
Posts: 19
https://www.artistsworkshop.eu/meble-kuchenne-na-wymiar-warszawa-gdzie-zamowic/
Joined: Mon Dec 21, 2015 7:35 am
Location: Cyberspace
Has thanked: 0
Been thanked: 0

Re: Using blender models in KGL (is jfm the best option?)

Post by Dev »

Does this look like a valid strip?

Code: Select all

glVertex3f(0.0, 0.2, 0.2);
glVertex3f(0.0, 0.2, 0.0);
glVertex3f(0.0, 0.0, 0.0);
glVertex3f(0.0, 0.0, 0.2);
glVertex3f(0.2, 0.0, 0.0);
glVertex3f(0.2, 0.0, 0.2);
glVertex3f(0.2, 0.2, 0.0);
glVertex3f(0.0, 0.2, 0.0);
glVertex3f(0.2, 0.2, 0.2);
glVertex3f(0.0, 0.2, 0.2);
glVertex3f(0.0, 0.0, 0.2);
glVertex3f(0.2, 0.0, 0.2);
glVertex3f(0.2, 0.2, 0.0);
Full code (Linux)
Spoiler!
#include <GL/glut.h>



void display()
{
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1.0,1.0,0.0);
glBegin(GL_TRIANGLE_STRIP);


glVertex3f(0.0, 0.2, 0.2);
glVertex3f(0.0, 0.2, 0.0);
glVertex3f(0.0, 0.0, 0.0);
glVertex3f(0.0, 0.0, 0.2);
glVertex3f(0.2, 0.0, 0.0);
glVertex3f(0.2, 0.0, 0.2);
glVertex3f(0.2, 0.2, 0.0);
glVertex3f(0.0, 0.2, 0.0);
glVertex3f(0.2, 0.2, 0.2);
glVertex3f(0.0, 0.2, 0.2);
glVertex3f(0.0, 0.0, 0.2);
glVertex3f(0.2, 0.0, 0.2);
glVertex3f(0.2, 0.2, 0.0);



glEnd();
glFlush();
}
void init()
{
glClearColor(0.0,0.5,0.2,0.8);
}
int main(int argc, char** argv)
{

glutInit(&argc, argv);
glutCreateWindow("simple 3D");
glutDisplayFunc(display);
init();
glutMainLoop();
}

Code: Select all

gcc -o game tri_test-strip.c -lX11 -lGL -lglut
I exported full polygon data instead of just vertex, then looked at the data in a spreadsheet. Eventually came up with a series of steps that I guess could be called an algorithm. I pasted the result into the GL template above and it seems to be rendering. I haven't tried rotating the cube though.

Oh, actually... not sure if in correct direction for culling...
Rabot
DCEmu Newbie
DCEmu Newbie
Posts: 6
Joined: Wed Jun 11, 2008 8:14 pm
Has thanked: 0
Been thanked: 0

Re: Using blender models in KGL (is jfm the best option?)

Post by Rabot »

Super interesting thread.
Have been using Blender for a bit now, still haven't properly compiled KOS yet but I'd like to see this go somewhere.
User avatar
bogglez
Moderator
Moderator
Posts: 578
Joined: Sun Apr 20, 2014 9:45 am
Has thanked: 0
Been thanked: 0

Re: Using blender models in KGL (is jfm the best option?)

Post by bogglez »

Dev wrote:Does this look like a valid strip?

Code: Select all

glVertex3f(0.0, 0.2, 0.2);
glVertex3f(0.0, 0.2, 0.0);
glVertex3f(0.0, 0.0, 0.0);
glVertex3f(0.0, 0.0, 0.2);
glVertex3f(0.2, 0.0, 0.0);
glVertex3f(0.2, 0.0, 0.2);
glVertex3f(0.2, 0.2, 0.0);
glVertex3f(0.0, 0.2, 0.0);
glVertex3f(0.2, 0.2, 0.2);
glVertex3f(0.0, 0.2, 0.2);
glVertex3f(0.0, 0.0, 0.2);
glVertex3f(0.2, 0.0, 0.2);
glVertex3f(0.2, 0.2, 0.0);
Full code (Linux)
Spoiler!
#include <GL/glut.h>



void display()
{
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1.0,1.0,0.0);
glBegin(GL_TRIANGLE_STRIP);


glVertex3f(0.0, 0.2, 0.2);
glVertex3f(0.0, 0.2, 0.0);
glVertex3f(0.0, 0.0, 0.0);
glVertex3f(0.0, 0.0, 0.2);
glVertex3f(0.2, 0.0, 0.0);
glVertex3f(0.2, 0.0, 0.2);
glVertex3f(0.2, 0.2, 0.0);
glVertex3f(0.0, 0.2, 0.0);
glVertex3f(0.2, 0.2, 0.2);
glVertex3f(0.0, 0.2, 0.2);
glVertex3f(0.0, 0.0, 0.2);
glVertex3f(0.2, 0.0, 0.2);
glVertex3f(0.2, 0.2, 0.0);



glEnd();
glFlush();
}
void init()
{
glClearColor(0.0,0.5,0.2,0.8);
}
int main(int argc, char** argv)
{

glutInit(&argc, argv);
glutCreateWindow("simple 3D");
glutDisplayFunc(display);
init();
glutMainLoop();
}

Code: Select all

gcc -o game tri_test-strip.c -lX11 -lGL -lglut
I exported full polygon data instead of just vertex, then looked at the data in a spreadsheet. Eventually came up with a series of steps that I guess could be called an algorithm. I pasted the result into the GL template above and it seems to be rendering. I haven't tried rotating the cube though.

Oh, actually... not sure if in correct direction for culling...
Depends on the coordinate system and how you export it in blender.
If the coordinate systems change handedness (https://en.wikipedia.org/wiki/Cartesian ... dimensions), then the winding order might become opposite.

In OpenGL, X-axis should point right, y-Axis up, the Z-axis should point out of the screen towards you.
I provided the code to check winding order. glEnable(GL_CULL_FACE). The default winding order for a face to be considered the front is counter-clockwise. https://www.opengl.org/sdk/docs/man/doc ... ntFace.xml

You can rotate the image by clearing the screen, calling glLoadIdentity(), glRotatef(angle, 1, 0, 0) for the x axis for example.
Just check the result visually.
Wiki & tutorials: http://dcemulation.org/?title=Development
Wiki feedback: viewtopic.php?f=29&t=103940
My libgl playground (not for production): https://bitbucket.org/bogglez/libgl15
My lxdream fork (with small fixes): https://bitbucket.org/bogglez/lxdream
User avatar
Dev
DCEmu Fast Newbie
DCEmu Fast Newbie
Posts: 19
Joined: Mon Dec 21, 2015 7:35 am
Location: Cyberspace
Has thanked: 0
Been thanked: 0

Re: Using blender models in KGL (is jfm the best option?)

Post by Dev »

@bogglez
Thanks for useful info again.

I figured out what the valid order is following vertices on an actual mesh and then coming up with a series of comparisons that give same values. The original method was making full faces but some out of wrong edges. I should have noticed this by following vertices on the actual mesh.

The "algorithm" I designed and manually tested now creates a full CCW strip from any manifold mesh. Each new triangle shares the last edge added to the strip.

At one point I was concerned about every second triangle swapping direction, then read up on the specification and it turns out OpenGL takes this into account by swapping first 2 vertices.

So the "recipe" is:

Code: Select all

Before converting to strips:
- if no object is selected ask the user to select one
- edit the object and convert all quads (if there are any) to tris

Prepare for stripping:
- Take the indexed output of polygons from Blender giving the polygon number, and xyz coordinates. Assign a number to every unique vertex in the array.
- Copy polygon 1 with it's all 3 values in sequence into the strip array
   - Remove this polygon from the list of searchable polygons

Then run loop:
- Search what polygons share the last 2 vertices of the strip array (this will give 3 possible options)
- Find which of the 3 share more then 1 vertex, this will give 1 possible option - now we know what the next polygon is
-Copy the new vertex from the found polygon and add it to the strip array.
   -No longer include the above polygon search.

When you find no polygon with matching 2 vertices then stop.
Now it's just a matter of implementing this into Blender's Python. A lot of work but should be fairly straightforward. I hope I have not overlooked anything.
This program will be dog slow at the start but then as the strip gets longer the speed should exponentially increase.

Now I need to skill up on using arrays in Python...
User avatar
bogglez
Moderator
Moderator
Posts: 578
Joined: Sun Apr 20, 2014 9:45 am
Has thanked: 0
Been thanked: 0

Re: Using blender models in KGL (is jfm the best option?)

Post by bogglez »

What you're doing is called finding a spanning tree by the way. Might be interesting to Google that term :)
Wiki & tutorials: http://dcemulation.org/?title=Development
Wiki feedback: viewtopic.php?f=29&t=103940
My libgl playground (not for production): https://bitbucket.org/bogglez/libgl15
My lxdream fork (with small fixes): https://bitbucket.org/bogglez/lxdream
User avatar
RyoDC
Mental DCEmu
Mental DCEmu
Posts: 366
Joined: Wed Mar 30, 2011 12:13 pm
Has thanked: 2 times
Been thanked: 0

Re: Using blender models in KGL (is jfm the best option?)

Post by RyoDC »

I'm sorry, but why not just export the model to some well-know format, like md2 format, and then parse it on the DC side?
How do I try to build a Dreamcast toolchain:
Image
User avatar
Dev
DCEmu Fast Newbie
DCEmu Fast Newbie
Posts: 19
Joined: Mon Dec 21, 2015 7:35 am
Location: Cyberspace
Has thanked: 0
Been thanked: 0

Re: Using blender models in KGL (is jfm the best option?)

Post by Dev »

All of these "easy" solutions are inefficient and not the correct/intended way to work with the Dreamcast hardware. They're like forcing a square peg into a round hole. It's better to just cut the crap and use what the graphic processor is designed to work with. It doesn't look that hard.
User avatar
RyoDC
Mental DCEmu
Mental DCEmu
Posts: 366
Joined: Wed Mar 30, 2011 12:13 pm
Has thanked: 2 times
Been thanked: 0

Re: Using blender models in KGL (is jfm the best option?)

Post by RyoDC »

So you're rolling down your own format?
How do I try to build a Dreamcast toolchain:
Image
User avatar
bogglez
Moderator
Moderator
Posts: 578
Joined: Sun Apr 20, 2014 9:45 am
Has thanked: 0
Been thanked: 0

Re: Using blender models in KGL (is jfm the best option?)

Post by bogglez »

RyoDC wrote:So you're rolling down your own format?
Ryo, I think you misunderstand this XKCD. Dev is not trying to create a universal standard. This is a proprietary file format only for the Dreamcast and it serves a purpose that is not fulfilled by others.
Wiki & tutorials: http://dcemulation.org/?title=Development
Wiki feedback: viewtopic.php?f=29&t=103940
My libgl playground (not for production): https://bitbucket.org/bogglez/libgl15
My lxdream fork (with small fixes): https://bitbucket.org/bogglez/lxdream
User avatar
RyoDC
Mental DCEmu
Mental DCEmu
Posts: 366
Joined: Wed Mar 30, 2011 12:13 pm
Has thanked: 2 times
Been thanked: 0

Re: Using blender models in KGL (is jfm the best option?)

Post by RyoDC »

bogglez wrote:
RyoDC wrote:So you're rolling down your own format?
Ryo, I think you misunderstand this XKCD. Dev is not trying to create a universal standard. This is a proprietary file format only for the Dreamcast and it serves a purpose that is not fulfilled by others.
I think we misunderstood each other. I got what he wants to do, and his idea is decent. I just don't think it's good idea to roll a new format (yes, XKCD is punning the universal format, but I think that applies to inventing new formats too).
I think it should be better to concentrate on some open-source and well-known format and convert it to triangle strips in runtime (or whatever is better suited for pvr). Not reinventing the wheel by writing your own converter, but using a well-known format and bake it to strips when running code.

Anyway that's not a big deal, and what he wants to do is good too, both from point of 3d tools for Dreamcast, and self-education reasons.
If there will be any done work, I would like to join this work in converting keyframe or even bone animation, to add to this new format.
Maybe there'll be some format specification or whatever.
How do I try to build a Dreamcast toolchain:
Image
User avatar
BlueCrab
The Crabby Overlord
The Crabby Overlord
Posts: 5663
Joined: Mon May 27, 2002 11:31 am
Location: Sailing the Skies of Arcadia
Has thanked: 9 times
Been thanked: 69 times
Contact:

Re: Using blender models in KGL (is jfm the best option?)

Post by BlueCrab »

RyoDC wrote:Anyway that's not a big deal, and what he wants to do is good too, both from point of 3d tools for Dreamcast, and self-education reasons.
If there will be any done work, I would like to join this work in converting keyframe or even bone animation, to add to this new format.
Maybe there'll be some format specification or whatever.
I could get behind a format just for KOS for doing 3D stuff. :wink:
Post Reply