Strange problem with sio2ObjectMapBuffer
3 posters
Strange problem with sio2ObjectMapBuffer
I'm trying to access an objects triangles, like so:
The triangle access basically matches the one in sio2PhysicAddObject, the only difference is that I need to map the buffer again first. But for some reason it gives me a EXC_BAD_ACCESS when j = 18 although n_ind is 60 for this object.
Isn't the mapped buffer data exactly the same as it was before? I'm not familiar with the OpenGL ES methods like glMapBufferOES so maybe someone could enlighten me.
Matt
- Code:
sio2ObjectMapBuffer( obj );
for( int i = 0; i < obj->n_vertexgroup; ++i ) {
unsigned int n_ind = obj->_SIO2vertexgroup[ i ]->n_ind >> 1;
for( unsigned int j = 0; j < n_ind; ++j ) {
int v[ 3 ];
memcpy( &v[ 0 ], &obj->buf[ obj->_SIO2vertexgroup[ i ]->ind[ j ] * 12 ], 12 );
}
}
sio2ObjectUnmapBuffer( obj );
The triangle access basically matches the one in sio2PhysicAddObject, the only difference is that I need to map the buffer again first. But for some reason it gives me a EXC_BAD_ACCESS when j = 18 although n_ind is 60 for this object.
Isn't the mapped buffer data exactly the same as it was before? I'm not familiar with the OpenGL ES methods like glMapBufferOES so maybe someone could enlighten me.
Matt
Re: Strange problem with sio2ObjectMapBuffer
On a side note, sio2ObjectGetNVert seems to be returning strange values, too. It's 28 although the object consists of 5 quads, i.e. 20 vertices. I'm lost. ;-)
Matt
Matt
Re: Strange problem with sio2ObjectMapBuffer
Ok im going to dig on that one, I'll put that on my todo list... however just a quick parenthesis... I see that you are using:
int v[3]
its is not fixed point in the new release its float...
int v[3]
its is not fixed point in the new release its float...
Re: Strange problem with sio2ObjectMapBuffer
I've been on the old release yesterday... not that fast with updating ;-)sio2interactive wrote:its is not fixed point in the new release its float...
I'm using some dummy objects for game logic, in this particular example I've a mesh with 5 quads which represent possible locations for another mesh. I want to go through the triangles in order to find out the center position and the quad normal.
One other thing I'm missing and would be creating using the same approach is a bounding box calculation. I need that because I'm placing objects on each other for random level generation.
I can send you the blend file this evening if you need it.
Thanks,
Matt
Re: Strange problem with sio2ObjectMapBuffer
not that fast with updating ;-)
>> Well I do have a day job, I wish that I could do that full time but I still have to pay the bills you know what Im say'in
I'm using some dummy objects for game logic, in this particular example I've a mesh with 5 quads which represent possible locations for another mesh. I want to go through the triangles in order to find out the center position and the quad normal.
>> Honestly I don't really get what you are trying to do here...
One other thing I'm missing and would be creating using the same approach is a bounding box calculation. I need that because I'm placing objects on each other for random level generation.
>> You already got the Dim XYZ of the object, with that you can easily create a bounding box... If its necessary I can always provide a function to SIO2 that would calculate it from the Dim, or you can send me the one that you are using.
I can send you the blend file this evening if you need it.
>> Sure, and gimme a bit more info cuz sorry but I don't get it
>> Well I do have a day job, I wish that I could do that full time but I still have to pay the bills you know what Im say'in
I'm using some dummy objects for game logic, in this particular example I've a mesh with 5 quads which represent possible locations for another mesh. I want to go through the triangles in order to find out the center position and the quad normal.
>> Honestly I don't really get what you are trying to do here...
One other thing I'm missing and would be creating using the same approach is a bounding box calculation. I need that because I'm placing objects on each other for random level generation.
>> You already got the Dim XYZ of the object, with that you can easily create a bounding box... If its necessary I can always provide a function to SIO2 that would calculate it from the Dim, or you can send me the one that you are using.
I can send you the blend file this evening if you need it.
>> Sure, and gimme a bit more info cuz sorry but I don't get it
Re: Strange problem with sio2ObjectMapBuffer
I meant myself, not you. The new version was released yesterday so I didn't update immediately.sio2interactive wrote:Well I do have a day job, I wish that I could do that full time but I still have to pay the bills you know what Im say'in
Imagine you have a house with a wall and want to place random windows/doors at predefined positions. Such positions are given by a second dummy object which consists of quads which represent the position and orientation where windows/doors could be placed. I want to read these quads and calculate center and face normal in order to randomly place objects there.sio2interactive wrote:Honestly I don't really get what you are trying to do here...
I hope it's clearer now.
Thanks,
Matt
Re: Strange problem with sio2ObjectMapBuffer
I meant myself, not you. The new version was released yesterday so I didn't update immediately.
>> Oupss ma'bad
Couldn't you simply use an object custom property to do that and simply pre-calculate that in blender before export time?
Checkout this link to know how to custom execute and add user properties... by the way this tutorial is not the final one but should give you a good idea...
http://sio2interactive.com/dump/tutorial09.zip
>> Oupss ma'bad
Couldn't you simply use an object custom property to do that and simply pre-calculate that in blender before export time?
Checkout this link to know how to custom execute and add user properties... by the way this tutorial is not the final one but should give you a good idea...
http://sio2interactive.com/dump/tutorial09.zip
Last edited by sio2interactive on Wed Oct 15, 2008 3:39 am; edited 1 time in total (Reason for editing : link error....)
Re: Strange problem with sio2ObjectMapBuffer
The problem is that I'm working with an artist who is not familiar with Blender and neither am I. So we're just exporting static OBJ files from his suite and reimport them into Blender to export the scene with the SIO2 exporter.
Still, it should be possible to access the vertices after calling sio2ObjectMapBuffer, shouldn't it?
Best,
Matt
Still, it should be possible to access the vertices after calling sio2ObjectMapBuffer, shouldn't it?
Best,
Matt
Re: Strange problem with sio2ObjectMapBuffer
Totally, remember that duplicate object method that I basically code for you last time, in the code snippet that I post im using SIO2mapbuffer to get the vertices and send them to Bullet, so its 100% sure that the vertices are available since bullet pick'em up and create a new collision object on the fly...
Re: Strange problem with sio2ObjectMapBuffer
Ok taking a look back at your post sio2ObjectGetNVert is absolutely correct, its the number of unique vertices take a look at the 2 following block taken from sio2_physic.cc
- Code:
case SIO2_PHYSIC_TRIANGLEMESH:
{
unsigned int j,
tri_cnt = 0;
btVector3 tri[ 3 ];
btTriangleMesh *_btTriangleMesh = new btTriangleMesh();
while( i != tmp->n_vgroup )
{
j = 0;
while( j != tmp->_SIO2vertexgroup[ i ]->n_ind )
{
memcpy( &v[ 0 ], &tmp->buf[ tmp->_SIO2vertexgroup[ i ]->ind[ j ] * 12 ], 12 );
tri[ tri_cnt ][ 0 ] = v[ 0 ] * _SIO2object->scl->x;
tri[ tri_cnt ][ 1 ] = v[ 1 ] * _SIO2object->scl->y;
tri[ tri_cnt ][ 2 ] = v[ 2 ] * _SIO2object->scl->z;
++tri_cnt;
if( tri_cnt == 3 )
{
_btTriangleMesh->addTriangle( tri[ 0 ],
tri[ 1 ],
tri[ 2 ] );
tri_cnt = 0;
}
++j;
}
++i;
}
_btCollisionShape = new btBvhTriangleMeshShape( _btTriangleMesh, 1 );
break;
}
case SIO2_PHYSIC_CONVEXHULL:
{
unsigned int n_vert = sio2ObjectGetNVert( tmp );
btPoint3 vert;
btConvexHullShape *_btConvexHullShape = new btConvexHullShape();
_btConvexHullShape->setMargin( (btScalar)0.25 );
while( i != n_vert )
{
memcpy( &v, &tmp->buf[ i * 12 ], 12 );
vert[ 0 ] = v[ 0 ] * _SIO2object->scl->x;
vert[ 1 ] = v[ 1 ] * _SIO2object->scl->y;
vert[ 2 ] = v[ 2 ] * _SIO2object->scl->z;
_btConvexHullShape->addPoint( vert );
++i;
}
btShapeHull _btShapeHull( _btConvexHullShape );
_btShapeHull.buildHull( (btScalar)0.01 );
delete _btConvexHullShape;
_btCollisionShape = new btConvexHullShape( (const btScalar *)_btShapeHull.getVertexPointer(), _btShapeHull.numVertices() );
break;
}
}
Re: Strange problem with sio2ObjectMapBuffer
No no no no, you are right there's something wrong with sio2ObjectGetNVert, it should be divided by 12 and not 36... (I have no idea why its 36 actually...)
- Code:
unsigned int sio2ObjectGetNVert( SIO2object *_SIO2object )
{
SIO2object *tmp = _SIO2object->_SIO2object ? ( SIO2object * )_SIO2object->_SIO2object : _SIO2object;
if( tmp->vbo_offset[ SIO2_OBJECT_VCOLOR ] )
{ return tmp->vbo_offset[ SIO2_OBJECT_VCOLOR ] / 12; }
else if( tmp->vbo_offset[ SIO2_OBJECT_NORMALS ] )
{ return tmp->vbo_offset[ SIO2_OBJECT_NORMALS ] / 12; }
else if( tmp->vbo_offset[ SIO2_OBJECT_TEXUV0 ] )
{ return tmp->vbo_offset[ SIO2_OBJECT_TEXUV0 ] / 12; }
return 0;
}
Re: Strange problem with sio2ObjectMapBuffer
When I get the logic correct, then you're looking for the next offset after the vertex info, which is either the vertex color array or the normals array or the texture coordinates array. You then divide this offset by the amount of bytes a vertex requires. Still, I'm now wondering why twelve, since vertices are 3*3 bytes? Also, I'm wondering what happens if no other information is available, i.e. all other offsets are 0? In that case, 0 is returned, but this seems wrong to me? I currently don't have the code at hand so please bear with me if that's a stupid question.
I hope we can also find a solution to the sio2ObjectMapBuffer issue. I'll provide you with an example ASAP.
Best,
Matt
I hope we can also find a solution to the sio2ObjectMapBuffer issue. I'll provide you with an example ASAP.
Best,
Matt
Re: Strange problem with sio2ObjectMapBuffer
Little update: I just tried to reproduce the problem with V1.2 and it seems that it's gone. One particular difference I saw while debugging was that the number of indices in the vertex group was smaller (60 vs. 25). Probably the old exporter didn't work well with the mesh. I will now upgrade my sources to the new version. Hopefully, everything will run smooth after that.
Best,
Matt
Best,
Matt
Re: Strange problem with sio2ObjectMapBuffer
Still, I'm now wondering why twelve, since vertices are 3*3 bytes?
>> Incorrect: 3 float at 4 bytes each = 1 vertice ( so 12 bytes ) and the optimization process remove any duplicates depending on the threshold set in the exporter.
One particular difference I saw while debugging was that the number of indices in the vertex group was smaller (60 vs. 25).
>> In v1.2 I put that is going to be optimized at 3 digit after the . instead of 6 so that totally possible.
I'm wondering what happens if no other information is available, i.e. all other offsets are 0? In that case, 0 is returned, but this seems wrong to me?
>> You are right again, this should be the right code, sorry for the inconvenience (too tired) I wasn't thinking properly...
>> Incorrect: 3 float at 4 bytes each = 1 vertice ( so 12 bytes ) and the optimization process remove any duplicates depending on the threshold set in the exporter.
One particular difference I saw while debugging was that the number of indices in the vertex group was smaller (60 vs. 25).
>> In v1.2 I put that is going to be optimized at 3 digit after the . instead of 6 so that totally possible.
I'm wondering what happens if no other information is available, i.e. all other offsets are 0? In that case, 0 is returned, but this seems wrong to me?
>> You are right again, this should be the right code, sorry for the inconvenience (too tired) I wasn't thinking properly...
- Code:
unsigned int sio2ObjectGetNVert( SIO2object *_SIO2object )
{
SIO2object *tmp = _SIO2object->_SIO2object ? ( SIO2object * )_SIO2object->_SIO2object : _SIO2object;
if( tmp->vbo_offset[ SIO2_OBJECT_VCOLOR ] )
{ return tmp->vbo_offset[ SIO2_OBJECT_VCOLOR ] / 12; }
else if( tmp->vbo_offset[ SIO2_OBJECT_NORMALS ] )
{ return tmp->vbo_offset[ SIO2_OBJECT_NORMALS ] / 12; }
else if( tmp->vbo_offset[ SIO2_OBJECT_TEXUV0 ] )
{ return tmp->vbo_offset[ SIO2_OBJECT_TEXUV0 ] / 12; }
else if( tmp->vbo_offset[ SIO2_OBJECT_TEXUV1 ] )
{ return tmp->vbo_offset[ SIO2_OBJECT_TEXUV1 ] / 12; }
else
{ return tmp->vbo_offset[ SIO2_OBJECT_SIZE ] / 12; }
return 0;
}
Re: Strange problem with sio2ObjectMapBuffer
LOL. I must have been really tired to think a float is 24 bytes. 19 years programming and now that. OMFG. I'm getting old.sio2interactive wrote:>> Incorrect: 3 float at 4 bytes each = 1 vertice ( so 12 bytes ) and the optimization process remove any duplicates depending on the threshold set in the exporter.
At least one thing I got right so I'm not completely disgraced.sio2interactive wrote:You are right again, this should be the right code, sorry for the inconvenience (too tired) I wasn't thinking properly...
Thanks for the update!
Best,
Matt
Edit: I guess I was thinking of faces (3 points with 3 coords = 9 values) or something like that. I really can't explain it otherwise. I'm seriously embarrassed. :-)
Re: Strange problem with sio2ObjectMapBuffer
Hehe, don't be embarrassed thats what long hours of programming do to your brain... I know the symptoms too
Re: Strange problem with sio2ObjectMapBuffer
Okay, unfortunately the problem isn't really gone. I just tried the following with the latest version:
- created an object A which consists of multiple single-sided quads
- created a second object B which is simply a little cube to mark a corner of the quad
- loaded the scene, accessed the vertices of A like in sio2PhysicsAdd and placed B on each vertex I read
The code looks like that, for simplicty I put this right into the render loop:
And the result looks like that:
The big gray squares are object A, the little white cubes are B (the original one to the left) or clones of B (the three at the corners of two quads of A).
Now what's completely strange is that only three vertices are covered by a cube correctly. So the next thing I did was to dump the vertices to the console. Here's what I got.
As you can see, the indices are obviously wrong. It gets even worse. Whenever I place a breakpoint in the loop, values look even more screwed and it gives me a EXC_BAD_ACCESS because an index is some huge number.
How comes? Any ideas?
Best,
Matt
Edit: I just digged through the code once more and saw that the indices are free'd in sio2VertexGroupGenId... So now I can get the vertices with sio2ObjectMapBuffer but I still need the context, i.e. the indices. :-(
- created an object A which consists of multiple single-sided quads
- created a second object B which is simply a little cube to mark a corner of the quad
- loaded the scene, accessed the vertices of A like in sio2PhysicsAdd and placed B on each vertex I read
The code looks like that, for simplicty I put this right into the render loop:
- Code:
static bool initialized = false;
if( !initialized ) {
SIO2object* obj = ( SIO2object * )sio2ResourceGet( sio2->_SIO2resource,
SIO2_OBJECT,
"object/house_1_windows" );
SIO2object* cube = (SIO2object*) sio2ResourceGet( sio2->_SIO2resource, SIO2_OBJECT, "object/Cube" );
sio2ObjectMapBuffer( obj );
for( int i = 0; i < obj->n_vgroup; ++i ) {
unsigned int n_ind = obj->_SIO2vertexgroup[ i ]->n_ind >> 1;
for( unsigned int j = 0; j < n_ind; j++ ) {
float v[ 3 ];
unsigned short idx = obj->_SIO2vertexgroup[ i ]->ind[ j ];
memcpy( &v[ 0 ], &obj->buf[ idx * 12 ], 12 );
char newname[ 500 ];
sprintf( newname, "%s%d", cube->name, j );
SIO2object* newCube = sio2ObjectDuplicate( cube, newname );
newCube->pos->x = v[ 0 ] * obj->scl->x;
newCube->pos->y = v[ 1 ] * obj->scl->y;
newCube->pos->z = v[ 2 ] * obj->scl->z;
sio2ObjectBindMatrix( newCube );
}
}
sio2ObjectUnmapBuffer( obj );
initialized = true;
}
And the result looks like that:
The big gray squares are object A, the little white cubes are B (the original one to the left) or clones of B (the three at the corners of two quads of A).
Now what's completely strange is that only three vertices are covered by a cube correctly. So the next thing I did was to dump the vertices to the console. Here's what I got.
- Code:
7: 0.045 / -0.006 / 0.146
0: -0.148 / -0.028 / 0.052
1: -0.052 / -0.028 / 0.052
0: -0.148 / -0.028 / 0.052
0: -0.148 / -0.028 / 0.052
0: -0.148 / -0.028 / 0.052
0: -0.148 / -0.028 / 0.052
0: -0.148 / -0.028 / 0.052
0: -0.148 / -0.028 / 0.052
0: -0.148 / -0.028 / 0.052
0: -0.148 / -0.028 / 0.052
0: -0.148 / -0.028 / 0.052
0: -0.148 / -0.028 / 0.052
0: -0.148 / -0.028 / 0.052
As you can see, the indices are obviously wrong. It gets even worse. Whenever I place a breakpoint in the loop, values look even more screwed and it gives me a EXC_BAD_ACCESS because an index is some huge number.
How comes? Any ideas?
Best,
Matt
Edit: I just digged through the code once more and saw that the indices are free'd in sio2VertexGroupGenId... So now I can get the vertices with sio2ObjectMapBuffer but I still need the context, i.e. the indices. :-(
Re: Strange problem with sio2ObjectMapBuffer
So, to make a long matter short: sio2interactive, could you provide means to retrieve index data from the buffers, too?
Thanks,
Matt
Thanks,
Matt
Re: Strange problem with sio2ObjectMapBuffer
It appeared to be pretty trivial even with nearly no OpenGL ES knowledge, so here's what I tried:
With these two methods added, I changed my test code like so:
The result now looks like that:
I believe I'm pretty close to a solution now but I'm way too tired to think of it any longer... Any help appreciated.
Matt
- Code:
unsigned char sio2VertexGroupMapBuffer( SIO2vertexgroup* _SIO2vertexgroup )
{
GLvoid *buf = NULL;
glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, _SIO2vertexgroup->vbo );
glMapBufferOES( GL_ELEMENT_ARRAY_BUFFER, GL_WRITE_ONLY_OES );
glGetBufferPointervOES( GL_ELEMENT_ARRAY_BUFFER, GL_BUFFER_MAP_POINTER_OES, &buf );
_SIO2vertexgroup->ind = ( unsigned short * ) buf;
return _SIO2vertexgroup->ind ? 1 : 0;
}
void sio2VertexGroupUnmapBuffer( SIO2vertexgroup *_SIO2vertexgroup )
{
_SIO2vertexgroup->ind = NULL;
glUnmapBufferOES( GL_ELEMENT_ARRAY_BUFFER );
glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, 0 );
}
With these two methods added, I changed my test code like so:
- Code:
static bool initialized = false;
if( !initialized ) {
SIO2object* obj = ( SIO2object * )sio2ResourceGet( sio2->_SIO2resource,
SIO2_OBJECT,
"object/house_1_windows" );
SIO2object* cube = (SIO2object*) sio2ResourceGet( sio2->_SIO2resource, SIO2_OBJECT, "object/Cube" );
sio2ObjectMapBuffer( obj );
for( int i = 0; i < obj->n_vgroup; ++i ) {
unsigned int n_ind = obj->_SIO2vertexgroup[ i ]->n_ind >> 1;
sio2VertexGroupMapBuffer( obj->_SIO2vertexgroup[ i ] );
for( unsigned int j = 0; j < n_ind; j++ ) {
float v[ 3 ];
unsigned short idx = obj->_SIO2vertexgroup[ i ]->ind[ j ];
memcpy( &v[ 0 ], &obj->buf[ idx * 12 ], 12 );
char newname[ 500 ];
sprintf( newname, "%s%d", cube->name, j );
cout << idx << ": " << v[ 0 ] << " / " << v[ 1 ] << " / " << v[ 2 ] << endl;
SIO2object* newCube = sio2ObjectDuplicate( cube, newname );
newCube->pos->x = v[ 0 ] * obj->scl->x;
newCube->pos->y = v[ 1 ] * obj->scl->y;
newCube->pos->z = v[ 2 ] * obj->scl->z;
sio2ObjectBindMatrix( newCube );
}
sio2VertexGroupUnmapBuffer( obj->_SIO2vertexgroup[ i ] );
}
sio2ObjectUnmapBuffer( obj );
initialized = true;
}
The result now looks like that:
- Code:
0: -0.148 / -0.028 / 0.052
1: -0.052 / -0.028 / 0.052
2: -0.052 / -0.006 / 0.146
3: -0.148 / -0.006 / 0.146
0: -0.148 / -0.028 / 0.052
2: -0.052 / -0.006 / 0.146
4: 0.045 / -0.028 / 0.052
5: 0.141 / -0.028 / 0.052
6: 0.141 / -0.006 / 0.146
7: 0.045 / -0.006 / 0.146
4: 0.045 / -0.028 / 0.052
6: 0.141 / -0.006 / 0.146
8: -0.048 / -0.03 / 0.349
9: 0.048 / -0.03 / 0.349
10: 0.048 / -0.046 / 0.444
I believe I'm pretty close to a solution now but I'm way too tired to think of it any longer... Any help appreciated.
Matt
Re: Strange problem with sio2ObjectMapBuffer
Okay, got it, just when posting it I recognized that the division by two is not necessary any more.
Maybe this little monologue will help somebody else some time... ;-)
Cheers
Matt
Maybe this little monologue will help somebody else some time... ;-)
Cheers
Matt
Re: Strange problem with sio2ObjectMapBuffer
Yeah well I was just about to tell you that this line look suspicious
unsigned int n_ind = obj->_SIO2vertexgroup[ i ]->n_ind >> 1;
Glad you got it up and running!
unsigned int n_ind = obj->_SIO2vertexgroup[ i ]->n_ind >> 1;
Glad you got it up and running!
Similar topics
» strange problem
» md2 problem!
» SIO2Widget area - getting some strange results..
» Quite strange question - how to exit sio manually?
» Strange behavior of object and lamp during rotation
» md2 problem!
» SIO2Widget area - getting some strange results..
» Quite strange question - how to exit sio manually?
» Strange behavior of object and lamp during rotation
Permissions in this forum:
You cannot reply to topics in this forum