View Issue Details

IDProjectCategoryView StatusLast Update
0002137DarkRadiantModelspublic23.08.2011 11:49
Reportermattn Assigned To 
PrioritynormalSeveritynormalReproducibilitysometimes
Status confirmedResolutionno change required 
Product Version1.1.0 
Fixed in Version1.2.0 
Summary0002137: picomodel md2 texture coords broken
Descriptioni know this is not really a dr issue - as darkmod does not support md2 anymore - but still, loading such a model can result (for some models) in broken texcoords. maybe other models are affected, too - or maybe md2 is affected. haven't investigated any further.

maybe it's an option for you to switch to a model library that is in active development - e.g. something like libg3d, making dr support more model formats or import/export them from several formats into several other formats would be a cool feature imo.
TagsNo tags attached.
Attached Files
truck.md2 (39,088 bytes)
skins.diff (16,543 bytes)   
Index: picomodel/pm_md2.c
===================================================================
--- picomodel/pm_md2.c	(Revision 62)
+++ picomodel/pm_md2.c	(Arbeitskopie)
@@ -1,6 +1,6 @@
 /* -----------------------------------------------------------------------------
 
-PicoModel Library 
+PicoModel Library
 
 Copyright (c) 2002, Randy Reddig & seaw0lf
 All rights reserved.
@@ -17,7 +17,7 @@
 
 Neither the names of the copyright holders nor the names of its contributors may
 be used to endorse or promote products derived from this software without
-specific prior written permission. 
+specific prior written permission.
 
 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
@@ -132,167 +132,167 @@
 float	md2_normals[ MD2_NUMVERTEXNORMALS ][ 3 ] =
 {
 	{ -0.525731f, 0.000000f, 0.850651f },
-	{ -0.442863f, 0.238856f, 0.864188f }, 
-	{ -0.295242f, 0.000000f, 0.955423f }, 
-	{ -0.309017f, 0.500000f, 0.809017f }, 
-	{ -0.162460f, 0.262866f, 0.951056f }, 
+	{ -0.442863f, 0.238856f, 0.864188f },
+	{ -0.295242f, 0.000000f, 0.955423f },
+	{ -0.309017f, 0.500000f, 0.809017f },
+	{ -0.162460f, 0.262866f, 0.951056f },
 	{ 0.000000f, 0.000000f, 1.000000f },
 	{ 0.000000f, 0.850651f, 0.525731f },
 	{ -0.147621f, 0.716567f, 0.681718f },
-	{ 0.147621f, 0.716567f, 0.681718f }, 
-	{ 0.000000f, 0.525731f, 0.850651f }, 
-	{ 0.309017f, 0.500000f, 0.809017f }, 
-	{ 0.525731f, 0.000000f, 0.850651f }, 
-	{ 0.295242f, 0.000000f, 0.955423f }, 
-	{ 0.442863f, 0.238856f, 0.864188f }, 
-	{ 0.162460f, 0.262866f, 0.951056f }, 
-	{ -0.681718f, 0.147621f, 0.716567f }, 
-	{ -0.809017f, 0.309017f, 0.500000f }, 
-	{ -0.587785f, 0.425325f, 0.688191f }, 
-	{ -0.850651f, 0.525731f, 0.000000f }, 
-	{ -0.864188f, 0.442863f, 0.238856f }, 
-	{ -0.716567f, 0.681718f, 0.147621f }, 
-	{ -0.688191f, 0.587785f, 0.425325f }, 
-	{ -0.500000f, 0.809017f, 0.309017f }, 
-	{ -0.238856f, 0.864188f, 0.442863f }, 
-	{ -0.425325f, 0.688191f, 0.587785f }, 
-	{ -0.716567f, 0.681718f, -0.147621f }, 
-	{ -0.500000f, 0.809017f, -0.309017f }, 
-	{ -0.525731f, 0.850651f, 0.000000f }, 
-	{ 0.000000f, 0.850651f, -0.525731f }, 
-	{ -0.238856f, 0.864188f, -0.442863f }, 
-	{ 0.000000f, 0.955423f, -0.295242f }, 
-	{ -0.262866f, 0.951056f, -0.162460f }, 
-	{ 0.000000f, 1.000000f, 0.000000f }, 
-	{ 0.000000f, 0.955423f, 0.295242f }, 
-	{ -0.262866f, 0.951056f, 0.162460f }, 
-	{ 0.238856f, 0.864188f, 0.442863f }, 
-	{ 0.262866f, 0.951056f, 0.162460f }, 
-	{ 0.500000f, 0.809017f, 0.309017f }, 
-	{ 0.238856f, 0.864188f, -0.442863f }, 
-	{ 0.262866f, 0.951056f, -0.162460f }, 
-	{ 0.500000f, 0.809017f, -0.309017f }, 
-	{ 0.850651f, 0.525731f, 0.000000f }, 
-	{ 0.716567f, 0.681718f, 0.147621f }, 
-	{ 0.716567f, 0.681718f, -0.147621f }, 
-	{ 0.525731f, 0.850651f, 0.000000f }, 
-	{ 0.425325f, 0.688191f, 0.587785f }, 
-	{ 0.864188f, 0.442863f, 0.238856f }, 
-	{ 0.688191f, 0.587785f, 0.425325f }, 
-	{ 0.809017f, 0.309017f, 0.500000f }, 
-	{ 0.681718f, 0.147621f, 0.716567f }, 
-	{ 0.587785f, 0.425325f, 0.688191f }, 
-	{ 0.955423f, 0.295242f, 0.000000f }, 
-	{ 1.000000f, 0.000000f, 0.000000f }, 
-	{ 0.951056f, 0.162460f, 0.262866f }, 
-	{ 0.850651f, -0.525731f, 0.000000f }, 
-	{ 0.955423f, -0.295242f, 0.000000f }, 
-	{ 0.864188f, -0.442863f, 0.238856f }, 
-	{ 0.951056f, -0.162460f, 0.262866f }, 
-	{ 0.809017f, -0.309017f, 0.500000f }, 
-	{ 0.681718f, -0.147621f, 0.716567f }, 
-	{ 0.850651f, 0.000000f, 0.525731f }, 
-	{ 0.864188f, 0.442863f, -0.238856f }, 
-	{ 0.809017f, 0.309017f, -0.500000f }, 
-	{ 0.951056f, 0.162460f, -0.262866f }, 
-	{ 0.525731f, 0.000000f, -0.850651f }, 
-	{ 0.681718f, 0.147621f, -0.716567f }, 
-	{ 0.681718f, -0.147621f, -0.716567f }, 
-	{ 0.850651f, 0.000000f, -0.525731f }, 
-	{ 0.809017f, -0.309017f, -0.500000f }, 
-	{ 0.864188f, -0.442863f, -0.238856f }, 
-	{ 0.951056f, -0.162460f, -0.262866f }, 
-	{ 0.147621f, 0.716567f, -0.681718f }, 
-	{ 0.309017f, 0.500000f, -0.809017f }, 
-	{ 0.425325f, 0.688191f, -0.587785f }, 
-	{ 0.442863f, 0.238856f, -0.864188f }, 
-	{ 0.587785f, 0.425325f, -0.688191f }, 
-	{ 0.688191f, 0.587785f, -0.425325f }, 
-	{ -0.147621f, 0.716567f, -0.681718f }, 
-	{ -0.309017f, 0.500000f, -0.809017f }, 
-	{ 0.000000f, 0.525731f, -0.850651f }, 
-	{ -0.525731f, 0.000000f, -0.850651f }, 
-	{ -0.442863f, 0.238856f, -0.864188f }, 
-	{ -0.295242f, 0.000000f, -0.955423f }, 
-	{ -0.162460f, 0.262866f, -0.951056f }, 
-	{ 0.000000f, 0.000000f, -1.000000f }, 
-	{ 0.295242f, 0.000000f, -0.955423f }, 
-	{ 0.162460f, 0.262866f, -0.951056f }, 
-	{ -0.442863f, -0.238856f, -0.864188f }, 
-	{ -0.309017f, -0.500000f, -0.809017f }, 
-	{ -0.162460f, -0.262866f, -0.951056f }, 
-	{ 0.000000f, -0.850651f, -0.525731f }, 
-	{ -0.147621f, -0.716567f, -0.681718f }, 
-	{ 0.147621f, -0.716567f, -0.681718f }, 
-	{ 0.000000f, -0.525731f, -0.850651f }, 
-	{ 0.309017f, -0.500000f, -0.809017f }, 
-	{ 0.442863f, -0.238856f, -0.864188f }, 
-	{ 0.162460f, -0.262866f, -0.951056f }, 
-	{ 0.238856f, -0.864188f, -0.442863f }, 
-	{ 0.500000f, -0.809017f, -0.309017f }, 
-	{ 0.425325f, -0.688191f, -0.587785f }, 
-	{ 0.716567f, -0.681718f, -0.147621f }, 
-	{ 0.688191f, -0.587785f, -0.425325f }, 
-	{ 0.587785f, -0.425325f, -0.688191f }, 
-	{ 0.000000f, -0.955423f, -0.295242f }, 
-	{ 0.000000f, -1.000000f, 0.000000f }, 
-	{ 0.262866f, -0.951056f, -0.162460f }, 
-	{ 0.000000f, -0.850651f, 0.525731f }, 
-	{ 0.000000f, -0.955423f, 0.295242f }, 
-	{ 0.238856f, -0.864188f, 0.442863f }, 
-	{ 0.262866f, -0.951056f, 0.162460f }, 
-	{ 0.500000f, -0.809017f, 0.309017f }, 
-	{ 0.716567f, -0.681718f, 0.147621f }, 
-	{ 0.525731f, -0.850651f, 0.000000f }, 
-	{ -0.238856f, -0.864188f, -0.442863f }, 
-	{ -0.500000f, -0.809017f, -0.309017f }, 
-	{ -0.262866f, -0.951056f, -0.162460f }, 
-	{ -0.850651f, -0.525731f, 0.000000f }, 
-	{ -0.716567f, -0.681718f, -0.147621f }, 
-	{ -0.716567f, -0.681718f, 0.147621f }, 
-	{ -0.525731f, -0.850651f, 0.000000f }, 
-	{ -0.500000f, -0.809017f, 0.309017f }, 
-	{ -0.238856f, -0.864188f, 0.442863f }, 
-	{ -0.262866f, -0.951056f, 0.162460f }, 
-	{ -0.864188f, -0.442863f, 0.238856f }, 
-	{ -0.809017f, -0.309017f, 0.500000f }, 
-	{ -0.688191f, -0.587785f, 0.425325f }, 
-	{ -0.681718f, -0.147621f, 0.716567f }, 
-	{ -0.442863f, -0.238856f, 0.864188f }, 
-	{ -0.587785f, -0.425325f, 0.688191f }, 
-	{ -0.309017f, -0.500000f, 0.809017f }, 
-	{ -0.147621f, -0.716567f, 0.681718f }, 
-	{ -0.425325f, -0.688191f, 0.587785f }, 
-	{ -0.162460f, -0.262866f, 0.951056f }, 
-	{ 0.442863f, -0.238856f, 0.864188f }, 
-	{ 0.162460f, -0.262866f, 0.951056f }, 
-	{ 0.309017f, -0.500000f, 0.809017f }, 
-	{ 0.147621f, -0.716567f, 0.681718f }, 
-	{ 0.000000f, -0.525731f, 0.850651f }, 
-	{ 0.425325f, -0.688191f, 0.587785f }, 
-	{ 0.587785f, -0.425325f, 0.688191f }, 
-	{ 0.688191f, -0.587785f, 0.425325f }, 
-	{ -0.955423f, 0.295242f, 0.000000f }, 
-	{ -0.951056f, 0.162460f, 0.262866f }, 
-	{ -1.000000f, 0.000000f, 0.000000f }, 
-	{ -0.850651f, 0.000000f, 0.525731f }, 
-	{ -0.955423f, -0.295242f, 0.000000f }, 
-	{ -0.951056f, -0.162460f, 0.262866f }, 
-	{ -0.864188f, 0.442863f, -0.238856f }, 
-	{ -0.951056f, 0.162460f, -0.262866f }, 
-	{ -0.809017f, 0.309017f, -0.500000f }, 
+	{ 0.147621f, 0.716567f, 0.681718f },
+	{ 0.000000f, 0.525731f, 0.850651f },
+	{ 0.309017f, 0.500000f, 0.809017f },
+	{ 0.525731f, 0.000000f, 0.850651f },
+	{ 0.295242f, 0.000000f, 0.955423f },
+	{ 0.442863f, 0.238856f, 0.864188f },
+	{ 0.162460f, 0.262866f, 0.951056f },
+	{ -0.681718f, 0.147621f, 0.716567f },
+	{ -0.809017f, 0.309017f, 0.500000f },
+	{ -0.587785f, 0.425325f, 0.688191f },
+	{ -0.850651f, 0.525731f, 0.000000f },
+	{ -0.864188f, 0.442863f, 0.238856f },
+	{ -0.716567f, 0.681718f, 0.147621f },
+	{ -0.688191f, 0.587785f, 0.425325f },
+	{ -0.500000f, 0.809017f, 0.309017f },
+	{ -0.238856f, 0.864188f, 0.442863f },
+	{ -0.425325f, 0.688191f, 0.587785f },
+	{ -0.716567f, 0.681718f, -0.147621f },
+	{ -0.500000f, 0.809017f, -0.309017f },
+	{ -0.525731f, 0.850651f, 0.000000f },
+	{ 0.000000f, 0.850651f, -0.525731f },
+	{ -0.238856f, 0.864188f, -0.442863f },
+	{ 0.000000f, 0.955423f, -0.295242f },
+	{ -0.262866f, 0.951056f, -0.162460f },
+	{ 0.000000f, 1.000000f, 0.000000f },
+	{ 0.000000f, 0.955423f, 0.295242f },
+	{ -0.262866f, 0.951056f, 0.162460f },
+	{ 0.238856f, 0.864188f, 0.442863f },
+	{ 0.262866f, 0.951056f, 0.162460f },
+	{ 0.500000f, 0.809017f, 0.309017f },
+	{ 0.238856f, 0.864188f, -0.442863f },
+	{ 0.262866f, 0.951056f, -0.162460f },
+	{ 0.500000f, 0.809017f, -0.309017f },
+	{ 0.850651f, 0.525731f, 0.000000f },
+	{ 0.716567f, 0.681718f, 0.147621f },
+	{ 0.716567f, 0.681718f, -0.147621f },
+	{ 0.525731f, 0.850651f, 0.000000f },
+	{ 0.425325f, 0.688191f, 0.587785f },
+	{ 0.864188f, 0.442863f, 0.238856f },
+	{ 0.688191f, 0.587785f, 0.425325f },
+	{ 0.809017f, 0.309017f, 0.500000f },
+	{ 0.681718f, 0.147621f, 0.716567f },
+	{ 0.587785f, 0.425325f, 0.688191f },
+	{ 0.955423f, 0.295242f, 0.000000f },
+	{ 1.000000f, 0.000000f, 0.000000f },
+	{ 0.951056f, 0.162460f, 0.262866f },
+	{ 0.850651f, -0.525731f, 0.000000f },
+	{ 0.955423f, -0.295242f, 0.000000f },
+	{ 0.864188f, -0.442863f, 0.238856f },
+	{ 0.951056f, -0.162460f, 0.262866f },
+	{ 0.809017f, -0.309017f, 0.500000f },
+	{ 0.681718f, -0.147621f, 0.716567f },
+	{ 0.850651f, 0.000000f, 0.525731f },
+	{ 0.864188f, 0.442863f, -0.238856f },
+	{ 0.809017f, 0.309017f, -0.500000f },
+	{ 0.951056f, 0.162460f, -0.262866f },
+	{ 0.525731f, 0.000000f, -0.850651f },
+	{ 0.681718f, 0.147621f, -0.716567f },
+	{ 0.681718f, -0.147621f, -0.716567f },
+	{ 0.850651f, 0.000000f, -0.525731f },
+	{ 0.809017f, -0.309017f, -0.500000f },
+	{ 0.864188f, -0.442863f, -0.238856f },
+	{ 0.951056f, -0.162460f, -0.262866f },
+	{ 0.147621f, 0.716567f, -0.681718f },
+	{ 0.309017f, 0.500000f, -0.809017f },
+	{ 0.425325f, 0.688191f, -0.587785f },
+	{ 0.442863f, 0.238856f, -0.864188f },
+	{ 0.587785f, 0.425325f, -0.688191f },
+	{ 0.688191f, 0.587785f, -0.425325f },
+	{ -0.147621f, 0.716567f, -0.681718f },
+	{ -0.309017f, 0.500000f, -0.809017f },
+	{ 0.000000f, 0.525731f, -0.850651f },
+	{ -0.525731f, 0.000000f, -0.850651f },
+	{ -0.442863f, 0.238856f, -0.864188f },
+	{ -0.295242f, 0.000000f, -0.955423f },
+	{ -0.162460f, 0.262866f, -0.951056f },
+	{ 0.000000f, 0.000000f, -1.000000f },
+	{ 0.295242f, 0.000000f, -0.955423f },
+	{ 0.162460f, 0.262866f, -0.951056f },
+	{ -0.442863f, -0.238856f, -0.864188f },
+	{ -0.309017f, -0.500000f, -0.809017f },
+	{ -0.162460f, -0.262866f, -0.951056f },
+	{ 0.000000f, -0.850651f, -0.525731f },
+	{ -0.147621f, -0.716567f, -0.681718f },
+	{ 0.147621f, -0.716567f, -0.681718f },
+	{ 0.000000f, -0.525731f, -0.850651f },
+	{ 0.309017f, -0.500000f, -0.809017f },
+	{ 0.442863f, -0.238856f, -0.864188f },
+	{ 0.162460f, -0.262866f, -0.951056f },
+	{ 0.238856f, -0.864188f, -0.442863f },
+	{ 0.500000f, -0.809017f, -0.309017f },
+	{ 0.425325f, -0.688191f, -0.587785f },
+	{ 0.716567f, -0.681718f, -0.147621f },
+	{ 0.688191f, -0.587785f, -0.425325f },
+	{ 0.587785f, -0.425325f, -0.688191f },
+	{ 0.000000f, -0.955423f, -0.295242f },
+	{ 0.000000f, -1.000000f, 0.000000f },
+	{ 0.262866f, -0.951056f, -0.162460f },
+	{ 0.000000f, -0.850651f, 0.525731f },
+	{ 0.000000f, -0.955423f, 0.295242f },
+	{ 0.238856f, -0.864188f, 0.442863f },
+	{ 0.262866f, -0.951056f, 0.162460f },
+	{ 0.500000f, -0.809017f, 0.309017f },
+	{ 0.716567f, -0.681718f, 0.147621f },
+	{ 0.525731f, -0.850651f, 0.000000f },
+	{ -0.238856f, -0.864188f, -0.442863f },
+	{ -0.500000f, -0.809017f, -0.309017f },
+	{ -0.262866f, -0.951056f, -0.162460f },
+	{ -0.850651f, -0.525731f, 0.000000f },
+	{ -0.716567f, -0.681718f, -0.147621f },
+	{ -0.716567f, -0.681718f, 0.147621f },
+	{ -0.525731f, -0.850651f, 0.000000f },
+	{ -0.500000f, -0.809017f, 0.309017f },
+	{ -0.238856f, -0.864188f, 0.442863f },
+	{ -0.262866f, -0.951056f, 0.162460f },
+	{ -0.864188f, -0.442863f, 0.238856f },
+	{ -0.809017f, -0.309017f, 0.500000f },
+	{ -0.688191f, -0.587785f, 0.425325f },
+	{ -0.681718f, -0.147621f, 0.716567f },
+	{ -0.442863f, -0.238856f, 0.864188f },
+	{ -0.587785f, -0.425325f, 0.688191f },
+	{ -0.309017f, -0.500000f, 0.809017f },
+	{ -0.147621f, -0.716567f, 0.681718f },
+	{ -0.425325f, -0.688191f, 0.587785f },
+	{ -0.162460f, -0.262866f, 0.951056f },
+	{ 0.442863f, -0.238856f, 0.864188f },
+	{ 0.162460f, -0.262866f, 0.951056f },
+	{ 0.309017f, -0.500000f, 0.809017f },
+	{ 0.147621f, -0.716567f, 0.681718f },
+	{ 0.000000f, -0.525731f, 0.850651f },
+	{ 0.425325f, -0.688191f, 0.587785f },
+	{ 0.587785f, -0.425325f, 0.688191f },
+	{ 0.688191f, -0.587785f, 0.425325f },
+	{ -0.955423f, 0.295242f, 0.000000f },
+	{ -0.951056f, 0.162460f, 0.262866f },
+	{ -1.000000f, 0.000000f, 0.000000f },
+	{ -0.850651f, 0.000000f, 0.525731f },
+	{ -0.955423f, -0.295242f, 0.000000f },
+	{ -0.951056f, -0.162460f, 0.262866f },
+	{ -0.864188f, 0.442863f, -0.238856f },
+	{ -0.951056f, 0.162460f, -0.262866f },
+	{ -0.809017f, 0.309017f, -0.500000f },
 	{ -0.864188f, -0.442863f, -0.238856f },
-	{ -0.951056f, -0.162460f, -0.262866f }, 
-	{ -0.809017f, -0.309017f, -0.500000f }, 
-	{ -0.681718f, 0.147621f, -0.716567f }, 
-	{ -0.681718f, -0.147621f, -0.716567f }, 
-	{ -0.850651f, 0.000000f, -0.525731f }, 
-	{ -0.688191f, 0.587785f, -0.425325f }, 
-	{ -0.587785f, 0.425325f, -0.688191f }, 
-	{ -0.425325f, 0.688191f, -0.587785f }, 
-	{ -0.425325f, -0.688191f, -0.587785f }, 
-	{ -0.587785f, -0.425325f, -0.688191f }, 
-	{ -0.688191f, -0.587785f, -0.425325f }, 
+	{ -0.951056f, -0.162460f, -0.262866f },
+	{ -0.809017f, -0.309017f, -0.500000f },
+	{ -0.681718f, 0.147621f, -0.716567f },
+	{ -0.681718f, -0.147621f, -0.716567f },
+	{ -0.850651f, 0.000000f, -0.525731f },
+	{ -0.688191f, 0.587785f, -0.425325f },
+	{ -0.587785f, 0.425325f, -0.688191f },
+	{ -0.425325f, 0.688191f, -0.587785f },
+	{ -0.425325f, -0.688191f, -0.587785f },
+	{ -0.587785f, -0.425325f, -0.688191f },
+	{ -0.688191f, -0.587785f, -0.425325f },
 };
 
 
@@ -308,14 +308,14 @@
 	/* sanity check */
 	if( bufSize < ( sizeof( *md2 ) * 2) )
 		return PICO_PMV_ERROR_SIZE;
-	
+
 	/* set as md2 */
 	md2 = (md2_t*) buffer;
-	
+
 	/* check md2 magic */
-	if( *((int*) md2->magic) != *((int*) MD2_MAGIC) ) 
+	if( *((int*) md2->magic) != *((int*) MD2_MAGIC) )
 		return PICO_PMV_ERROR_IDENT;
-	
+
 	/* check md2 version */
 	if( _pico_little_long( md2->version ) != MD2_VERSION )
 		return PICO_PMV_ERROR_VERSION;
@@ -351,8 +351,8 @@
 	picoVec3_t		xyz, normal;
 	picoVec2_t		st;
 	picoColor_t		color;
-	
 
+
 	/* set as md2 */
 	bb = (picoByte_t*) buffer;
 	md2	= (md2_t*) buffer;
@@ -364,7 +364,7 @@
 		_pico_printf( PICO_ERROR, "%s is not an MD2 File!", fileName );
 		return NULL;
 	}
-	
+
 	// swap md2
 	md2->version = _pico_little_long( md2->version );
 
@@ -392,7 +392,7 @@
 		_pico_printf( PICO_ERROR, "%s has 0 frames!", fileName );
 		return NULL;
 	}
-	
+
 	if( frameNum < 0 || frameNum >= md2->numFrames )
 	{
 		_pico_printf( PICO_ERROR, "Invalid or out-of-range MD2 frame specified" );
@@ -434,10 +434,6 @@
 	// Print out md2 values
 	_pico_printf(PICO_VERBOSE,"Skins: %d  Verts: %d  STs: %d  Triangles: %d  Frames: %d\nSkin Name \"%s\"\n", md2->numSkins, md2->numXYZ, md2->numST, md2->numTris, md2->numFrames, &skinname );
 
-	// detox Skin name
-	_pico_setfext( skinname, "" );
-	_pico_unixify( skinname );
-
 	/* create new pico model */
 	picoModel = PicoNewModel();
 	if( picoModel == NULL )
@@ -452,6 +448,37 @@
 	PicoSetModelName( picoModel, fileName );
 	PicoSetModelFileName( picoModel, fileName );
 
+	for (i = 0; i < md2->numSkins; i++) {
+		char *offsetSkin = (char*) (bb + md2->ofsSkins) + i * MD2_MAX_SKINNAME;
+		/* set Skin Name */
+		strncpy(skinname, offsetSkin, MD2_MAX_SKINNAME);
+
+		/* detox Skin name */
+		if (skinname[0] == '.') {/* special case ufoai skinpath */
+			char path[MD2_MAX_SKINNAME];
+			char skinnameRelative[MD2_MAX_SKINNAME];
+			strncpy(path, fileName, MD2_MAX_SKINNAME);
+			strncpy(skinnameRelative, skinname, MD2_MAX_SKINNAME);
+			_pico_unixify(path);
+			for (j = MD2_MAX_SKINNAME; j--;) {/* skip filename */
+				if (path[j] == '/')
+					break;
+				path[j] = '\0';
+			}
+			snprintf(skinname, MD2_MAX_SKINNAME, "%s%s", path, &skinnameRelative[1]);
+		}
+		_pico_setfext(skinname, "");
+
+		picoShader = PicoNewShader(picoModel);
+		if (picoShader == NULL) {
+			_pico_printf(PICO_ERROR, "Unable to allocate a new model shader");
+			PicoFreeModel(picoModel);
+			return NULL;
+		}
+
+		PicoSetShaderName(picoShader, skinname);
+	}
+
 	// allocate new pico surface
 	picoSurface = PicoNewSurface( picoModel );
 	if( picoSurface == NULL )
skins.diff (16,543 bytes)   
md2.diff (8,224 bytes)   
Index: libs/picomodel/pm_md2.c
===================================================================
--- libs/picomodel/pm_md2.c	(Revision 5190)
+++ libs/picomodel/pm_md2.c	(Arbeitskopie)
@@ -68,8 +68,6 @@
 {
 	short	Vert;
 	short	ST;
-	struct	index_LUT_s	*next;
-
 } index_LUT_t;
 
 typedef struct index_DUP_LUT_s
@@ -432,9 +430,6 @@
 		texCoord->t = _pico_little_short( texCoord->t );
 	}
 
-	// set Skin Name
-	strncpy(skinname, (const char*)(bb + md2->ofsSkins), MD2_MAX_SKINNAME );
-
 	// Print out md2 values
 	_pico_printf(PICO_VERBOSE,"Skins: %d  Verts: %d  STs: %d  Triangles: %d  Frames: %d\nSkin Name \"%s\"\n", md2->numSkins, md2->numXYZ, md2->numST, md2->numTris, md2->numFrames, &skinname );
 
@@ -517,166 +512,55 @@
 		p_index_LUT[i].next = NULL;
 	}
 
-	// Fill in Look Up Table, and allocate/fill Linked List from vert array as needed for dup STs per Vert.
+	/* Fill in Look Up Table, and allocate/fill Linked List from vert array as needed for dup STs per Vert. */
 	tot_numVerts = md2->numXYZ;
-	dups = 0;
-	for(i=0; i<md2->numTris; i++)
-	{
-		p_md2Triangle = (md2Triangle_t *) ( bb + md2->ofsTris + (sizeof(md2Triangle_t)*i));
-		for(j=0; j<3; j++)
-		{
-			if (p_index_LUT[p_md2Triangle->index_xyz[j]].ST == -1) // No Main Entry
+	for (i = 0; i < md2->numTris; i++) {
+		p_md2Triangle = (md2Triangle_t *) (bb + md2->ofsTris + (sizeof(md2Triangle_t) * i));
+		for (j = 0; j < 3; j++) {
+			if (p_index_LUT[p_md2Triangle->index_xyz[j]].ST == -1) /* No Main Entry */
 				p_index_LUT[p_md2Triangle->index_xyz[j]].ST = p_md2Triangle->index_st[j];
-
-			else if (p_md2Triangle->index_st[j] == p_index_LUT[p_md2Triangle->index_xyz[j]].ST ) // Equal to Main Entry
-				continue;
-
-			else if ( (p_index_LUT[p_md2Triangle->index_xyz[j]].next == NULL) )  // Not equal to Main entry, and no LL entry
-			{	// Add first entry of LL from Main
-				p_index_LUT2 = (index_LUT_t *)_pico_alloc(sizeof(index_LUT_t));
-				if (p_index_LUT2 == NULL)
-					_pico_printf( PICO_ERROR," Couldn't allocate memory!\n");
-				p_index_LUT[p_md2Triangle->index_xyz[j]].next = (index_LUT_t *)p_index_LUT2;
-				p_index_LUT2->Vert = dups;
-				p_index_LUT2->ST = p_md2Triangle->index_st[j];
-				p_index_LUT2->next = NULL;
-				p_md2Triangle->index_xyz[j] = dups + md2->numXYZ; // Make change in Tri hunk
-				dups++;
-			}
-			else // Try to find in LL from Main Entry
-			{
-				p_index_LUT3 = p_index_LUT2 = p_index_LUT[p_md2Triangle->index_xyz[j]].next;
-				while ( (p_index_LUT2 != NULL) && (p_md2Triangle->index_xyz[j] != p_index_LUT2->Vert) ) // Walk down LL
-				{
-					p_index_LUT3 = p_index_LUT2;
-					p_index_LUT2 = p_index_LUT2->next;
-				}
-				p_index_LUT2 = p_index_LUT3;
-
-				if ( p_md2Triangle->index_st[j] == p_index_LUT2->ST ) // Found it
-				{
-					p_md2Triangle->index_xyz[j] = p_index_LUT2->Vert + md2->numXYZ; // Make change in Tri hunk
-					continue;
-				}
-
-				if ( p_index_LUT2->next == NULL)  // Didn't find it. Add entry to LL.
-				{
-					// Add the Entry
-					p_index_LUT3 = (index_LUT_t *)_pico_alloc(sizeof(index_LUT_t));
-					if (p_index_LUT3 == NULL)
-						_pico_printf( PICO_ERROR," Couldn't allocate memory!\n");
-					p_index_LUT2->next = (index_LUT_t *)p_index_LUT3;
-					p_index_LUT3->Vert = p_md2Triangle->index_xyz[j];
-					p_index_LUT3->ST = p_md2Triangle->index_st[j];
-					p_index_LUT3->next = NULL;
-					p_md2Triangle->index_xyz[j] = dups + md2->numXYZ; // Make change in Tri hunk
-					dups++;
-				}
-			}
 		}
 	}
 
-	// malloc and build array for Dup STs
-	p_index_LUT_DUPS = (index_DUP_LUT_t *)_pico_alloc(sizeof(index_DUP_LUT_t) * dups);
-	if (p_index_LUT_DUPS == NULL)
-		_pico_printf( PICO_ERROR," Couldn't allocate memory!\n");
-
-	dup_index = 0;
-	for(i=0; i<md2->numXYZ; i++)
-	{
-		p_index_LUT2 = p_index_LUT[i].next;
-		while (p_index_LUT2 != NULL)
-		{
-			p_index_LUT_DUPS[p_index_LUT2->Vert].OldVert = i;
-			p_index_LUT_DUPS[p_index_LUT2->Vert].ST = p_index_LUT2->ST;
-			dup_index++;
-			p_index_LUT2 = p_index_LUT2->next;
-		}
+	/* Build Picomodel */
+	triangle = (md2Triangle_t *) ((picoByte_t *) (bb + md2->ofsTris));
+	for (j = 0; j < md2->numTris; j++, triangle++) {
+		PicoSetSurfaceIndex(picoSurface, j * 3, triangle->index_xyz[0]);
+		PicoSetSurfaceIndex(picoSurface, j * 3 + 1, triangle->index_xyz[1]);
+		PicoSetSurfaceIndex(picoSurface, j * 3 + 2, triangle->index_xyz[2]);
 	}
 
-	// Build Picomodel
-	triangle = (md2Triangle_t *) ((picoByte_t *) (bb + md2->ofsTris) );
-	texCoord = (md2St_t*) ((picoByte_t *) (bb + md2->ofsST) );
-	vertex = (md2XyzNormal_t*) ((picoByte_t*) (frame->verts) );
-	for( j = 0; j < md2->numTris; j++, triangle++ )
-	{
-		PicoSetSurfaceIndex( picoSurface, j*3   , triangle->index_xyz[0] );
-		PicoSetSurfaceIndex( picoSurface, j*3+1 , triangle->index_xyz[1] );
-		PicoSetSurfaceIndex( picoSurface, j*3+2 , triangle->index_xyz[2] );
-	}
+	_pico_set_color(color, 255, 255, 255, 255);
 
-	for(i=0; i< md2->numXYZ; i++, vertex++)
-	{
+	texCoord = (md2St_t*) ((picoByte_t *) (bb + md2->ofsST));
+	vertex = (md2XyzNormal_t*) ((picoByte_t*) (frame->verts));
+	for (i = 0; i < md2->numXYZ; i++, vertex++) {
 		/* set vertex origin */
-		xyz[ 0 ] = vertex->v[0] * frame->scale[0] + frame->translate[0];
-		xyz[ 1 ] = vertex->v[1] * frame->scale[1] + frame->translate[1];
-		xyz[ 2 ] = vertex->v[2] * frame->scale[2] + frame->translate[2];
-		PicoSetSurfaceXYZ( picoSurface, i , xyz );
+		xyz[0] = vertex->v[0] * frame->scale[0] + frame->translate[0];
+		xyz[1] = vertex->v[1] * frame->scale[1] + frame->translate[1];
+		xyz[2] = vertex->v[2] * frame->scale[2] + frame->translate[2];
+		PicoSetSurfaceXYZ(picoSurface, i, xyz);
 
 		/* set normal */
-		normal[ 0 ] = md2_normals[vertex->lightnormalindex][0];
-		normal[ 1 ] = md2_normals[vertex->lightnormalindex][1];
-		normal[ 2 ] = md2_normals[vertex->lightnormalindex][2];
-		PicoSetSurfaceNormal( picoSurface, i , normal );
+		normal[0] = md2_normals[vertex->lightnormalindex][0];
+		normal[1] = md2_normals[vertex->lightnormalindex][1];
+		normal[2] = md2_normals[vertex->lightnormalindex][2];
+		PicoSetSurfaceNormal(picoSurface, i, normal);
 
 		/* set st coords */
-		st[ 0 ] =  ((texCoord[p_index_LUT[i].ST].s) / ((float)md2->skinWidth));
-		st[ 1 ] =  (texCoord[p_index_LUT[i].ST].t / ((float)md2->skinHeight));
-		PicoSetSurfaceST( picoSurface, 0, i , st );
-	}
+		st[0] = (float) texCoord[p_index_LUT[i].ST].s / (float) md2->skinWidth;
+		st[1] = (float) texCoord[p_index_LUT[i].ST].t / (float) md2->skinHeight;
+		PicoSetSurfaceST(picoSurface, 0, i, st);
 
-	if (dups)
-	{
-		for(i=0; i<dups; i++)
-		{
-			j = p_index_LUT_DUPS[i].OldVert;
-			/* set vertex origin */
-			xyz[ 0 ] = frame->verts[j].v[0] * frame->scale[0] + frame->translate[0];
-			xyz[ 1 ] = frame->verts[j].v[1] * frame->scale[1] + frame->translate[1];
-			xyz[ 2 ] = frame->verts[j].v[2] * frame->scale[2] + frame->translate[2];
-			PicoSetSurfaceXYZ( picoSurface, i + md2->numXYZ , xyz );
-
-			/* set normal */
-			normal[ 0 ] = md2_normals[frame->verts[j].lightnormalindex][0];
-			normal[ 1 ] = md2_normals[frame->verts[j].lightnormalindex][1];
-			normal[ 2 ] = md2_normals[frame->verts[j].lightnormalindex][2];
-			PicoSetSurfaceNormal( picoSurface, i + md2->numXYZ , normal );
-
-			/* set st coords */
-			st[ 0 ] =  ((texCoord[p_index_LUT_DUPS[i].ST].s) / ((float)md2->skinWidth));
-			st[ 1 ] =  (texCoord[p_index_LUT_DUPS[i].ST].t / ((float)md2->skinHeight));
-			PicoSetSurfaceST( picoSurface, 0, i + md2->numXYZ , st );
-		}
+		/* set color */
+		PicoSetSurfaceColor(picoSurface, 0, i, color);
 	}
 
-	/* set color */
-	PicoSetSurfaceColor( picoSurface, 0, 0, color );
+	/* Free malloc'ed LUTs */
+	_pico_free(p_index_LUT);
 
-	// Free up malloc'ed LL entries
-	for(i=0; i<md2->numXYZ; i++)
-	{
-		if(p_index_LUT[i].next != NULL)
-		{
-			p_index_LUT2 = p_index_LUT[i].next;
-			do {
-				p_index_LUT3 = p_index_LUT2->next;
-				_pico_free(p_index_LUT2);
-				p_index_LUT2 = p_index_LUT3;
-				dups--;
-			} while (p_index_LUT2 != NULL);
-		}
-	}
-
-	if (dups)
-		_pico_printf(PICO_WARNING, " Not all LL mallocs freed\n");
-
-	// Free malloc'ed LUTs
- 	_pico_free(p_index_LUT);
-	_pico_free(p_index_LUT_DUPS);
-
 	/* return the new pico model */
 	return picoModel;
-
 }
 
 
md2.diff (8,224 bytes)   

Activities

greebo

greebo

07.02.2010 13:24

administrator   ~0002913

Is there any test model I can use to debug this? I don't have any MD2 files lying around.
mattn

mattn

07.02.2010 14:10

updater   ~0002916

attached a model and its texture
mattn

mattn

07.02.2010 14:15

updater   ~0002917

attached a diff that adds support for different skins for md2 models

(if you ignore all those trailing whitespace stuff the patch is at the end of the file ;)
greebo

greebo

07.02.2010 15:16

administrator   ~0002918

This model has a strange appearance in DarkRadiant. When forcing it to load in the ModelSelector, it looks something like this:

http://img697.imageshack.us/img697/6112/trucki.png

It's not just the UV map messed up, the vertices are mangled too. Does this work for you at all?
mattn

mattn

08.02.2010 18:19

updater   ~0002925

attached a new patch that should fix the vertices - but i wasn't able to fix the uv map
mattn

mattn

08.02.2010 18:21

updater   ~0002926

ups - the compile error can be easy fixed with removing the NULL assignment - sorry
greebo

greebo

08.02.2010 19:52

administrator   ~0002927

The patch is there - I haven't looked into the UV issues yet.
greebo

greebo

08.02.2010 20:07

administrator   ~0002928

I see that the skinWidth/skinHeight values in the md2 are set to 256, but the attached image is 512, hence the UV coords are wrongly normalised. Could that be the issue?
mattn

mattn

09.02.2010 08:28

updater   ~0002929

yes, you are right - that sounds reasonable.
greebo

greebo

09.02.2010 10:33

administrator   ~0002930

Ok. I know nothing about MD2, but I assume this is an error happening during MD2 creation?

Feel free to close this issue in that case, if there are no other MD2 (texcoords) problems.
mattn

mattn

19.05.2010 19:57

updater   ~0003012

http://sourceforge.net/apps/trac/ufoai/changeset/30076/

here is a correct fix for the texcoord issue.
greebo

greebo

20.05.2010 12:18

administrator   ~0003013

Hm, the unified DIFF patch is not quite compatible with my SVN version. I tried downloading the entire file from your repo, but it seems to be largely different.

I'm a bit hesitant to just replace the file, as I don't know how if there are any ufo-specific changes in your MD2 loader.

If somebody is willing to merge only the relevant changes into the DarkRadiant codebase, I'm happy to apply that patch to SVN.
mattn

mattn

21.05.2010 06:40

updater   ~0003014

there are no ufo-only changes in that file - but i will try to merge it against the dr codebase to get it in.
greebo

greebo

21.05.2010 11:16

administrator   ~0003016

Ok, thanks in advance. :)
greebo

greebo

22.08.2011 08:08

administrator   ~0003991

Is the texcoord stuff still an issue with DarkRadiant? I'll leave this open for two more weeks or so, I might close this entry after that time.
mattn

mattn

22.08.2011 11:48

updater   ~0003993

if you are still using picomodel and that patch is not applied yet, then this is still an issue.
greebo

greebo

23.08.2011 11:49

administrator   ~0003994

Yup, we're still using picomodel, but the supplied patch was not applicable. If you can provide a patch suitable for the DarkRadiant codebase I'm happy to commit it.

Issue History

Date Modified Username Field Change
06.02.2010 22:53 mattn New Issue
07.02.2010 13:24 greebo Note Added: 0002913
07.02.2010 13:24 greebo Status new => acknowledged
07.02.2010 14:09 mattn File Added: truck.md2
07.02.2010 14:09 mattn File Added: truck.tga
07.02.2010 14:10 mattn Note Added: 0002916
07.02.2010 14:13 mattn File Added: skins.diff
07.02.2010 14:15 mattn Note Added: 0002917
07.02.2010 15:16 greebo Note Added: 0002918
08.02.2010 18:18 mattn File Added: md2.diff
08.02.2010 18:19 mattn Note Added: 0002925
08.02.2010 18:21 mattn Note Added: 0002926
08.02.2010 19:52 greebo Note Added: 0002927
08.02.2010 20:07 greebo Note Added: 0002928
09.02.2010 08:28 mattn Note Added: 0002929
09.02.2010 10:33 greebo Note Added: 0002930
14.02.2010 06:56 greebo Status acknowledged => resolved
14.02.2010 06:56 greebo Fixed in Version => 1.1.1
14.02.2010 06:56 greebo Resolution open => no change required
14.02.2010 06:56 greebo Assigned To => greebo
19.05.2010 19:57 mattn Status resolved => confirmed
19.05.2010 19:57 mattn Note Added: 0003012
20.05.2010 12:18 greebo Note Added: 0003013
21.05.2010 06:40 mattn Note Added: 0003014
21.05.2010 11:16 greebo Note Added: 0003016
30.09.2010 16:35 greebo File Deleted: truck.tga
22.08.2011 08:08 greebo Note Added: 0003991
22.08.2011 08:08 greebo Assigned To greebo =>
22.08.2011 11:48 mattn Note Added: 0003993
23.08.2011 11:49 greebo Note Added: 0003994