| 1 |
bearsoft |
1.1 |
#include <stdio.h>
|
| 2 |
|
|
#include "LwoLoader.h"
|
| 3 |
|
|
#include "../ImageFormat/SGI.h"
|
| 4 |
|
|
#include "math.h"
|
| 5 |
|
|
#include "../String/String.h"
|
| 6 |
|
|
#include "../System/System.h"
|
| 7 |
|
|
#include "../System/SystemDefine.h"
|
| 8 |
|
|
|
| 9 |
|
|
|
| 10 |
|
|
LwoLoader::LwoLoader(Object3dList **iobjekt3dlist_, ObjectLinkedList<SGI> *iTextureList)
|
| 11 |
|
|
{
|
| 12 |
|
|
objekt3dlist_[0]=iobjekt3dlist_[0];
|
| 13 |
|
|
textureList=iTextureList;
|
| 14 |
|
|
}
|
| 15 |
|
|
|
| 16 |
|
|
LwoLoader::~LwoLoader()
|
| 17 |
|
|
{
|
| 18 |
|
|
}
|
| 19 |
|
|
|
| 20 |
|
|
void LwoLoader::remove()
|
| 21 |
|
|
{
|
| 22 |
|
|
if (textureNameList!=null)
|
| 23 |
|
|
{
|
| 24 |
|
|
delete textureNameList;
|
| 25 |
|
|
}
|
| 26 |
|
|
|
| 27 |
|
|
if (binaryInput!=null)
|
| 28 |
|
|
{
|
| 29 |
|
|
delete binaryInput;
|
| 30 |
|
|
}
|
| 31 |
|
|
|
| 32 |
|
|
if (xVerticesArray!=null)
|
| 33 |
|
|
{
|
| 34 |
|
|
delete xVerticesArray;
|
| 35 |
|
|
}
|
| 36 |
|
|
|
| 37 |
|
|
if (yVerticesArray!=null)
|
| 38 |
|
|
{
|
| 39 |
|
|
delete yVerticesArray;
|
| 40 |
|
|
}
|
| 41 |
|
|
|
| 42 |
|
|
if (zVerticesArray!=null)
|
| 43 |
|
|
{
|
| 44 |
|
|
delete zVerticesArray;
|
| 45 |
|
|
}
|
| 46 |
|
|
|
| 47 |
|
|
if (polygonPoints!=null)
|
| 48 |
|
|
{
|
| 49 |
|
|
delete polygonPoints;
|
| 50 |
|
|
}
|
| 51 |
|
|
|
| 52 |
|
|
if (polygonSurfaces!=null)
|
| 53 |
|
|
{
|
| 54 |
|
|
delete polygonSurfaces;
|
| 55 |
|
|
}
|
| 56 |
|
|
|
| 57 |
|
|
if (surfaceMappingMethod!=null)
|
| 58 |
|
|
{
|
| 59 |
|
|
delete surfaceMappingMethod;
|
| 60 |
|
|
}
|
| 61 |
|
|
|
| 62 |
|
|
if (surfaceColourArray!=null)
|
| 63 |
|
|
{
|
| 64 |
|
|
delete surfaceColourArray;
|
| 65 |
|
|
}
|
| 66 |
|
|
|
| 67 |
|
|
if (surfaceTransparentArray!=null)
|
| 68 |
|
|
{
|
| 69 |
|
|
delete surfaceTransparentArray;
|
| 70 |
|
|
}
|
| 71 |
|
|
|
| 72 |
|
|
if (surfaceTextureWrappingXArray!=null)
|
| 73 |
|
|
{
|
| 74 |
|
|
delete surfaceTextureWrappingXArray;
|
| 75 |
|
|
}
|
| 76 |
|
|
|
| 77 |
|
|
if (surfaceTextureWrappingYArray!=null)
|
| 78 |
|
|
{
|
| 79 |
|
|
delete surfaceTextureWrappingYArray;
|
| 80 |
|
|
}
|
| 81 |
|
|
|
| 82 |
|
|
if (surfaceXYZAxleArray!=null)
|
| 83 |
|
|
{
|
| 84 |
|
|
delete surfaceXYZAxleArray;
|
| 85 |
|
|
}
|
| 86 |
|
|
|
| 87 |
|
|
if (surfaceTextureSizeXArray!=null)
|
| 88 |
|
|
{
|
| 89 |
|
|
delete surfaceTextureSizeXArray;
|
| 90 |
|
|
}
|
| 91 |
|
|
|
| 92 |
|
|
if (surfaceTextureSizeYArray!=null)
|
| 93 |
|
|
{
|
| 94 |
|
|
delete surfaceTextureSizeYArray;
|
| 95 |
|
|
}
|
| 96 |
|
|
|
| 97 |
|
|
if (surfaceTextureSizeZArray!=null)
|
| 98 |
|
|
{
|
| 99 |
|
|
delete surfaceTextureSizeZArray;
|
| 100 |
|
|
}
|
| 101 |
|
|
|
| 102 |
|
|
if (surfaceTextureCenterXArray!=null)
|
| 103 |
|
|
{
|
| 104 |
|
|
delete surfaceTextureCenterXArray;
|
| 105 |
|
|
}
|
| 106 |
|
|
|
| 107 |
|
|
if (surfaceTextureCenterYArray!=null)
|
| 108 |
|
|
{
|
| 109 |
|
|
delete surfaceTextureCenterYArray;
|
| 110 |
|
|
}
|
| 111 |
|
|
|
| 112 |
|
|
if (surfaceTextureCenterZArray!=null)
|
| 113 |
|
|
{
|
| 114 |
|
|
delete surfaceTextureCenterZArray;
|
| 115 |
|
|
}
|
| 116 |
|
|
|
| 117 |
|
|
if (polygonPoint1UArray!=null)
|
| 118 |
|
|
{
|
| 119 |
|
|
delete polygonPoint1UArray;
|
| 120 |
|
|
}
|
| 121 |
|
|
|
| 122 |
|
|
if (polygonPoint1VArray!=null)
|
| 123 |
|
|
{
|
| 124 |
|
|
delete polygonPoint1VArray;
|
| 125 |
|
|
}
|
| 126 |
|
|
|
| 127 |
|
|
if (polygonPoint2UArray!=null)
|
| 128 |
|
|
{
|
| 129 |
|
|
delete polygonPoint2UArray;
|
| 130 |
|
|
}
|
| 131 |
|
|
|
| 132 |
|
|
if (polygonPoint2VArray!=null)
|
| 133 |
|
|
{
|
| 134 |
|
|
delete polygonPoint2VArray;
|
| 135 |
|
|
}
|
| 136 |
|
|
|
| 137 |
|
|
if (polygonPoint3UArray!=null)
|
| 138 |
|
|
{
|
| 139 |
|
|
delete polygonPoint3UArray;
|
| 140 |
|
|
}
|
| 141 |
|
|
|
| 142 |
|
|
if (polygonPoint3VArray!=null)
|
| 143 |
|
|
{
|
| 144 |
|
|
delete polygonPoint3VArray;
|
| 145 |
|
|
}
|
| 146 |
|
|
}
|
| 147 |
|
|
|
| 148 |
|
|
//*********************************************************
|
| 149 |
|
|
//compute the data you want from a lwo file
|
| 150 |
|
|
//*********************************************************
|
| 151 |
|
|
|
| 152 |
|
|
void LwoLoader::scanLwoFile(String &fileName)
|
| 153 |
|
|
{
|
| 154 |
|
|
textureNameList=new StringLinkedList();
|
| 155 |
|
|
binaryInput=new BinaryInput();
|
| 156 |
|
|
xVerticesArray=null;
|
| 157 |
|
|
yVerticesArray=null;
|
| 158 |
|
|
zVerticesArray=null;
|
| 159 |
|
|
polygonPoints=null;
|
| 160 |
|
|
polygonSurfaces=null;
|
| 161 |
|
|
surfaceMappingMethod=null;
|
| 162 |
|
|
surfaceColourArray=null;
|
| 163 |
|
|
surfaceTransparentArray=null;
|
| 164 |
|
|
surfaceTextureWrappingXArray=null;
|
| 165 |
|
|
surfaceTextureWrappingYArray=null;
|
| 166 |
|
|
surfaceXYZAxleArray=null;
|
| 167 |
|
|
surfaceTextureSizeXArray=null;
|
| 168 |
|
|
surfaceTextureSizeYArray=null;
|
| 169 |
|
|
surfaceTextureSizeZArray=null;
|
| 170 |
|
|
surfaceTextureCenterXArray=null;
|
| 171 |
|
|
surfaceTextureCenterYArray=null;
|
| 172 |
|
|
surfaceTextureCenterZArray=null;
|
| 173 |
|
|
polygonPoint1UArray=null;
|
| 174 |
|
|
polygonPoint1VArray=null;
|
| 175 |
|
|
polygonPoint2UArray=null;
|
| 176 |
|
|
polygonPoint2VArray=null;
|
| 177 |
|
|
polygonPoint3UArray=null;
|
| 178 |
|
|
polygonPoint3VArray=null;
|
| 179 |
|
|
|
| 180 |
|
|
binaryInput->readFile(fileName);
|
| 181 |
|
|
|
| 182 |
|
|
binaryInput->setBigEndian(true);
|
| 183 |
|
|
System::println(binaryInput->getWord(4));
|
| 184 |
|
|
System::println(binaryInput->getInt());
|
| 185 |
|
|
System::println(binaryInput->getWord(4));
|
| 186 |
|
|
bool diffJumpValue=false;
|
| 187 |
|
|
|
| 188 |
|
|
while (binaryInput->getBinaryStatus())
|
| 189 |
|
|
{
|
| 190 |
|
|
int jumpValue=0;
|
| 191 |
|
|
|
| 192 |
|
|
String chunk=binaryInput->getWord(4);
|
| 193 |
|
|
System::println(chunk);
|
| 194 |
|
|
|
| 195 |
|
|
if (chunk.equals("SURF"))
|
| 196 |
|
|
{
|
| 197 |
|
|
jumpValue=binaryInput->getInt();
|
| 198 |
|
|
System::println(binaryInput->getWord());
|
| 199 |
|
|
binaryInput->getChar();
|
| 200 |
|
|
diffJumpValue=true;
|
| 201 |
|
|
}
|
| 202 |
|
|
else
|
| 203 |
|
|
{
|
| 204 |
|
|
if (diffJumpValue)
|
| 205 |
|
|
{
|
| 206 |
|
|
jumpValue=(int)binaryInput->getShort();
|
| 207 |
|
|
}
|
| 208 |
|
|
else
|
| 209 |
|
|
{
|
| 210 |
|
|
jumpValue=binaryInput->getInt();
|
| 211 |
|
|
}
|
| 212 |
|
|
|
| 213 |
|
|
bool notJump=false;
|
| 214 |
|
|
|
| 215 |
|
|
notJump=computeChunkPNTS(chunk, jumpValue);
|
| 216 |
|
|
|
| 217 |
|
|
if (!notJump)
|
| 218 |
|
|
{
|
| 219 |
|
|
notJump=computeChunkSRFS(chunk, jumpValue);
|
| 220 |
|
|
}
|
| 221 |
|
|
|
| 222 |
|
|
if (!notJump)
|
| 223 |
|
|
{
|
| 224 |
|
|
notJump=computeChunkPOLS(chunk, jumpValue);
|
| 225 |
|
|
}
|
| 226 |
|
|
|
| 227 |
|
|
if (!notJump)
|
| 228 |
|
|
{
|
| 229 |
|
|
notJump=computeChunkCOLR(chunk, jumpValue);
|
| 230 |
|
|
}
|
| 231 |
|
|
|
| 232 |
|
|
if (!notJump)
|
| 233 |
|
|
{
|
| 234 |
|
|
notJump=computeChunkVTRN(chunk, jumpValue);
|
| 235 |
|
|
}
|
| 236 |
|
|
|
| 237 |
|
|
if (!notJump)
|
| 238 |
|
|
{
|
| 239 |
|
|
notJump=computeChunkCTEX(chunk, jumpValue);
|
| 240 |
|
|
}
|
| 241 |
|
|
|
| 242 |
|
|
if (!notJump)
|
| 243 |
|
|
{
|
| 244 |
|
|
notJump=computeChunkTIMG(chunk, jumpValue);
|
| 245 |
|
|
}
|
| 246 |
|
|
|
| 247 |
|
|
if (!notJump)
|
| 248 |
|
|
{
|
| 249 |
|
|
notJump=computeChunkTWRP(chunk, jumpValue);
|
| 250 |
|
|
}
|
| 251 |
|
|
|
| 252 |
|
|
if (!notJump)
|
| 253 |
|
|
{
|
| 254 |
|
|
notJump=computeChunkTFLG(chunk, jumpValue);
|
| 255 |
|
|
}
|
| 256 |
|
|
|
| 257 |
|
|
if (!notJump)
|
| 258 |
|
|
{
|
| 259 |
|
|
notJump=computeChunkTSIZ(chunk, jumpValue);
|
| 260 |
|
|
}
|
| 261 |
|
|
|
| 262 |
|
|
if (!notJump)
|
| 263 |
|
|
{
|
| 264 |
|
|
notJump=computeChunkTCTR(chunk, jumpValue);
|
| 265 |
|
|
}
|
| 266 |
|
|
|
| 267 |
|
|
if (!notJump)
|
| 268 |
|
|
{
|
| 269 |
|
|
binaryInput->jumpForward(jumpValue);
|
| 270 |
|
|
}
|
| 271 |
|
|
}
|
| 272 |
|
|
}
|
| 273 |
|
|
|
| 274 |
|
|
calcTextureMapping();
|
| 275 |
|
|
|
| 276 |
|
|
Object3d *objekt3d_ = objekt3dlist_[0]->add(xVerticesArray->size, polygonSurfaces->size,polygonPoints->size,textureNameList->size());
|
| 277 |
|
|
|
| 278 |
|
|
readttpoints(objekt3d_);
|
| 279 |
|
|
|
| 280 |
|
|
if (textureNameList->size()!=0)
|
| 281 |
|
|
{
|
| 282 |
|
|
for ( int t=0; t<textureNameList->size() ; t++ )
|
| 283 |
|
|
{
|
| 284 |
|
|
String filePath=textureNameList->getElement(t);
|
| 285 |
|
|
// System::println(filePath);
|
| 286 |
|
|
objekt3d_->settexturep((int)textureList->addLastWithNoDoubleName(new SGI(filePath),filePath.buffer),t);
|
| 287 |
|
|
}
|
| 288 |
|
|
}
|
| 289 |
|
|
|
| 290 |
|
|
readvertices(objekt3d_);
|
| 291 |
|
|
readprepareuv2(objekt3d_);
|
| 292 |
|
|
readvpoints(objekt3d_);
|
| 293 |
|
|
// readcolour(objekt3d_);
|
| 294 |
|
|
// readtransparent(objekt3d_);
|
| 295 |
|
|
|
| 296 |
|
|
objekt3d_->makenormtab();
|
| 297 |
|
|
|
| 298 |
|
|
remove();
|
| 299 |
|
|
}
|
| 300 |
|
|
|
| 301 |
|
|
|
| 302 |
|
|
bool LwoLoader::computeChunkPNTS(String &chunk, int chunkValue)
|
| 303 |
|
|
{
|
| 304 |
|
|
if (chunk.equals("PNTS"))
|
| 305 |
|
|
{
|
| 306 |
|
|
int numberOfVertices=(chunkValue/12);
|
| 307 |
|
|
System::println(numberOfVertices);
|
| 308 |
|
|
|
| 309 |
|
|
xVerticesArray = new FloatArray(numberOfVertices);
|
| 310 |
|
|
yVerticesArray = new FloatArray(numberOfVertices);
|
| 311 |
|
|
zVerticesArray = new FloatArray(numberOfVertices);
|
| 312 |
|
|
|
| 313 |
|
|
for ( int v=0 ; v<numberOfVertices ; v++ )
|
| 314 |
|
|
{
|
| 315 |
|
|
xVerticesArray->setFloat(binaryInput->getFloat(),v);
|
| 316 |
|
|
yVerticesArray->setFloat(binaryInput->getFloat(),v);
|
| 317 |
|
|
zVerticesArray->setFloat(binaryInput->getFloat(),v);
|
| 318 |
|
|
}
|
| 319 |
|
|
|
| 320 |
|
|
return true;
|
| 321 |
|
|
}
|
| 322 |
|
|
|
| 323 |
|
|
return false;
|
| 324 |
|
|
}
|
| 325 |
|
|
|
| 326 |
|
|
bool LwoLoader::computeChunkSRFS(String &chunk, int chunkValue)
|
| 327 |
|
|
{
|
| 328 |
|
|
if (chunk.equals("SRFS"))
|
| 329 |
|
|
{
|
| 330 |
|
|
numberOfSurfaces=0;
|
| 331 |
|
|
|
| 332 |
|
|
binaryInput->resetCharCounter();
|
| 333 |
|
|
|
| 334 |
|
|
while (binaryInput->getCharCounter() < chunkValue)
|
| 335 |
|
|
{
|
| 336 |
|
|
String surfaceName=binaryInput->getWord();
|
| 337 |
|
|
System::println(surfaceName);
|
| 338 |
|
|
if ((surfaceName.length&1) == 1)
|
| 339 |
|
|
{
|
| 340 |
|
|
binaryInput->getChar();
|
| 341 |
|
|
}
|
| 342 |
|
|
numberOfSurfaces++;
|
| 343 |
|
|
}
|
| 344 |
|
|
|
| 345 |
|
|
surfaceColourArray = new IntArray(numberOfSurfaces);
|
| 346 |
|
|
surfaceTransparentArray = new FloatArray(numberOfSurfaces);
|
| 347 |
|
|
surfaceMappingMethod = new IntArray(numberOfSurfaces);
|
| 348 |
|
|
surfaceTextureWrappingXArray = new IntArray(numberOfSurfaces);
|
| 349 |
|
|
surfaceTextureWrappingYArray = new IntArray(numberOfSurfaces);
|
| 350 |
|
|
surfaceXYZAxleArray = new IntArray(numberOfSurfaces);
|
| 351 |
|
|
surfaceTextureSizeXArray = new FloatArray(numberOfSurfaces);
|
| 352 |
|
|
surfaceTextureSizeYArray = new FloatArray(numberOfSurfaces);
|
| 353 |
|
|
surfaceTextureSizeZArray = new FloatArray(numberOfSurfaces);
|
| 354 |
|
|
surfaceTextureCenterXArray = new FloatArray(numberOfSurfaces);
|
| 355 |
|
|
surfaceTextureCenterYArray = new FloatArray(numberOfSurfaces);
|
| 356 |
|
|
surfaceTextureCenterZArray = new FloatArray(numberOfSurfaces);
|
| 357 |
|
|
return true;
|
| 358 |
|
|
}
|
| 359 |
|
|
|
| 360 |
|
|
return false;
|
| 361 |
|
|
}
|
| 362 |
|
|
|
| 363 |
|
|
bool LwoLoader::computeChunkPOLS(String &chunk, int chunkValue)
|
| 364 |
|
|
{
|
| 365 |
|
|
if (chunk.equals("POLS"))
|
| 366 |
|
|
{
|
| 367 |
|
|
int numberOfPoints=0;
|
| 368 |
|
|
int numberOfPolygonSurfaces=0;
|
| 369 |
|
|
int numberOfPolygons=0;
|
| 370 |
|
|
|
| 371 |
|
|
polygonPoints = new IntArray((int)(binaryInput->getInternBufferSize()/sizeof(int)));
|
| 372 |
|
|
polygonSurfaces = new IntArray((int)(binaryInput->getInternBufferSize()/sizeof(int)));
|
| 373 |
|
|
|
| 374 |
|
|
binaryInput->resetCharCounter();
|
| 375 |
|
|
|
| 376 |
|
|
while (binaryInput->getCharCounter() < chunkValue)
|
| 377 |
|
|
{
|
| 378 |
|
|
int numberOfFaces=(int)binaryInput->getShort();
|
| 379 |
|
|
numberOfFaces-=2;
|
| 380 |
|
|
numberOfPolygons+=numberOfFaces;
|
| 381 |
|
|
//System::println(numberOfPolygons);
|
| 382 |
|
|
short firstPoint=binaryInput->getShort();
|
| 383 |
|
|
|
| 384 |
|
|
for ( int p=0 ; p<numberOfFaces ; p++ )
|
| 385 |
|
|
{
|
| 386 |
|
|
polygonPoints->setInt((int)firstPoint,numberOfPoints);
|
| 387 |
|
|
numberOfPoints++;
|
| 388 |
|
|
|
| 389 |
|
|
polygonPoints->setInt((int)binaryInput->getShort(),numberOfPoints);
|
| 390 |
|
|
numberOfPoints++;
|
| 391 |
|
|
|
| 392 |
|
|
polygonPoints->setInt((int)binaryInput->getShortButGoNotFoward(),numberOfPoints);
|
| 393 |
|
|
numberOfPoints++;
|
| 394 |
|
|
}
|
| 395 |
|
|
|
| 396 |
|
|
binaryInput->getShort();
|
| 397 |
|
|
int surfaceID=(int)(binaryInput->getShort()-1);
|
| 398 |
|
|
|
| 399 |
|
|
for ( int p2=0 ; p2<numberOfFaces ; p2++ )
|
| 400 |
|
|
{
|
| 401 |
|
|
polygonSurfaces->setInt(surfaceID,numberOfPolygonSurfaces);
|
| 402 |
|
|
numberOfPolygonSurfaces++;
|
| 403 |
|
|
}
|
| 404 |
|
|
|
| 405 |
|
|
}
|
| 406 |
|
|
|
| 407 |
|
|
// System::println(binaryInput->getCharCounter()-chunkValue);
|
| 408 |
|
|
|
| 409 |
|
|
polygonPoints->size=numberOfPoints;
|
| 410 |
|
|
polygonSurfaces->size=numberOfPolygons;
|
| 411 |
|
|
|
| 412 |
|
|
String numberOfPolysName="numberOfPolys: ";
|
| 413 |
|
|
// System::println(numberOfPolysName + numberOfPolygons);
|
| 414 |
|
|
|
| 415 |
|
|
return true;
|
| 416 |
|
|
}
|
| 417 |
|
|
|
| 418 |
|
|
return false;
|
| 419 |
|
|
}
|
| 420 |
|
|
|
| 421 |
|
|
//*********************************************************
|
| 422 |
|
|
//colour
|
| 423 |
|
|
//*********************************************************
|
| 424 |
|
|
|
| 425 |
|
|
bool LwoLoader::computeChunkCOLR(String &chunk, int chunkValue)
|
| 426 |
|
|
{
|
| 427 |
|
|
if (chunk.equals("COLR"))
|
| 428 |
|
|
{
|
| 429 |
|
|
if (surfaceColourArray->getInternIndex() < numberOfSurfaces)
|
| 430 |
|
|
{
|
| 431 |
|
|
surfaceColourArray->setInt((binaryInput->getInt()));
|
| 432 |
|
|
System::println(surfaceColourArray->getInt());
|
| 433 |
|
|
surfaceColourArray->internIndexForward();
|
| 434 |
|
|
return true;
|
| 435 |
|
|
}
|
| 436 |
|
|
}
|
| 437 |
|
|
|
| 438 |
|
|
return false;
|
| 439 |
|
|
}
|
| 440 |
|
|
|
| 441 |
|
|
//*********************************************************
|
| 442 |
|
|
//transparent??
|
| 443 |
|
|
//*********************************************************
|
| 444 |
|
|
|
| 445 |
|
|
bool LwoLoader::computeChunkVTRN(String &chunk, int chunkValue)
|
| 446 |
|
|
{
|
| 447 |
|
|
if (chunk.equals("VTRN"))
|
| 448 |
|
|
{
|
| 449 |
|
|
if (surfaceTransparentArray->getInternIndex() < numberOfSurfaces)
|
| 450 |
|
|
{
|
| 451 |
|
|
surfaceTransparentArray->setFloat((binaryInput->getFloat()));
|
| 452 |
|
|
System::println(surfaceTransparentArray->getFloat());
|
| 453 |
|
|
surfaceTransparentArray->internIndexForward();
|
| 454 |
|
|
return true;
|
| 455 |
|
|
}
|
| 456 |
|
|
}
|
| 457 |
|
|
|
| 458 |
|
|
return false;
|
| 459 |
|
|
}
|
| 460 |
|
|
|
| 461 |
|
|
//*********************************************************
|
| 462 |
|
|
//planar cylindric or spherilic
|
| 463 |
|
|
//*********************************************************
|
| 464 |
|
|
|
| 465 |
|
|
bool LwoLoader::computeChunkCTEX(String &chunk, int chunkValue)
|
| 466 |
|
|
{
|
| 467 |
|
|
if (chunk.equals("CTEX"))
|
| 468 |
|
|
{
|
| 469 |
|
|
if (surfaceMappingMethod->getInternIndex() < numberOfSurfaces)
|
| 470 |
|
|
{
|
| 471 |
|
|
String mappingMethodName=binaryInput->getWord();
|
| 472 |
|
|
if ((mappingMethodName.length&1) == 1)
|
| 473 |
|
|
{
|
| 474 |
|
|
binaryInput->getChar();
|
| 475 |
|
|
}
|
| 476 |
|
|
|
| 477 |
|
|
bool statement=true;
|
| 478 |
|
|
|
| 479 |
|
|
if (mappingMethodName.equals("Planar Image Map"))
|
| 480 |
|
|
{
|
| 481 |
|
|
surfaceMappingMethod->setInt(1);
|
| 482 |
|
|
statement=false;
|
| 483 |
|
|
}
|
| 484 |
|
|
|
| 485 |
|
|
if (mappingMethodName.equals("Cylindric Image Map"))
|
| 486 |
|
|
{
|
| 487 |
|
|
surfaceMappingMethod->setInt(2);
|
| 488 |
|
|
statement=false;
|
| 489 |
|
|
}
|
| 490 |
|
|
|
| 491 |
|
|
if (mappingMethodName.equals("Spherelic Image Map"))
|
| 492 |
|
|
{
|
| 493 |
|
|
surfaceMappingMethod->setInt(3);
|
| 494 |
|
|
statement=false;
|
| 495 |
|
|
}
|
| 496 |
|
|
|
| 497 |
|
|
if (statement)
|
| 498 |
|
|
{
|
| 499 |
|
|
surfaceMappingMethod->setInt(0);
|
| 500 |
|
|
}
|
| 501 |
|
|
|
| 502 |
|
|
System::println(surfaceMappingMethod->getInt());
|
| 503 |
|
|
|
| 504 |
|
|
surfaceMappingMethod->internIndexForward();
|
| 505 |
|
|
|
| 506 |
|
|
return true;
|
| 507 |
|
|
}
|
| 508 |
|
|
}
|
| 509 |
|
|
|
| 510 |
|
|
return false;
|
| 511 |
|
|
}
|
| 512 |
|
|
|
| 513 |
|
|
|
| 514 |
|
|
//*********************************************************
|
| 515 |
|
|
//read texture name
|
| 516 |
|
|
//*********************************************************
|
| 517 |
|
|
|
| 518 |
|
|
bool LwoLoader::computeChunkTIMG(String &chunk, int chunkValue)
|
| 519 |
|
|
{
|
| 520 |
|
|
if (chunk.equals("TIMG"))
|
| 521 |
|
|
{
|
| 522 |
|
|
String word=binaryInput->getWord();
|
| 523 |
|
|
|
| 524 |
|
|
if ((word.length&1) == 1)
|
| 525 |
|
|
{
|
| 526 |
|
|
binaryInput->getChar();
|
| 527 |
|
|
}
|
| 528 |
|
|
|
| 529 |
|
|
word.cutTheBack(92);
|
| 530 |
|
|
word.cutTheBegining('.');
|
| 531 |
|
|
|
| 532 |
|
|
String filePath="data/texturer/";
|
| 533 |
|
|
String fulFilePath=filePath + word + ".rgb";
|
| 534 |
|
|
textureNameList->addLast(fulFilePath);
|
| 535 |
|
|
System::println(fulFilePath);
|
| 536 |
|
|
|
| 537 |
|
|
return true;
|
| 538 |
|
|
}
|
| 539 |
|
|
|
| 540 |
|
|
return false;
|
| 541 |
|
|
}
|
| 542 |
|
|
|
| 543 |
|
|
//*********************************************************
|
| 544 |
|
|
//texture wrapping
|
| 545 |
|
|
//*********************************************************
|
| 546 |
|
|
|
| 547 |
|
|
bool LwoLoader::computeChunkTWRP(String &chunk, int chunkValue)
|
| 548 |
|
|
{
|
| 549 |
|
|
if (chunk.equals("TWRP"))
|
| 550 |
|
|
{
|
| 551 |
|
|
if (surfaceTextureWrappingXArray->getInternIndex() < numberOfSurfaces)
|
| 552 |
|
|
{
|
| 553 |
|
|
surfaceTextureWrappingXArray->setInt((int)binaryInput->getShort());
|
| 554 |
|
|
surfaceTextureWrappingYArray->setInt((int)binaryInput->getShort());
|
| 555 |
|
|
System::println(surfaceTextureWrappingXArray->getInt());
|
| 556 |
|
|
System::println(surfaceTextureWrappingYArray->getInt());
|
| 557 |
|
|
surfaceTextureWrappingXArray->internIndexForward();
|
| 558 |
|
|
surfaceTextureWrappingYArray->internIndexForward();
|
| 559 |
|
|
|
| 560 |
|
|
return true;
|
| 561 |
|
|
}
|
| 562 |
|
|
}
|
| 563 |
|
|
|
| 564 |
|
|
return false;
|
| 565 |
|
|
}
|
| 566 |
|
|
|
| 567 |
|
|
//*********************************************************
|
| 568 |
|
|
//x or y or z axles
|
| 569 |
|
|
//*********************************************************
|
| 570 |
|
|
|
| 571 |
|
|
bool LwoLoader::computeChunkTFLG(String &chunk, int chunkValue)
|
| 572 |
|
|
{
|
| 573 |
|
|
if (chunk.equals("TFLG"))
|
| 574 |
|
|
{
|
| 575 |
|
|
if (surfaceXYZAxleArray->getInternIndex() < numberOfSurfaces)
|
| 576 |
|
|
{
|
| 577 |
|
|
int axle=(int)binaryInput->getShort();
|
| 578 |
|
|
|
| 579 |
|
|
int outPutAxle=0;
|
| 580 |
|
|
|
| 581 |
|
|
if( (axle&1) == 1)
|
| 582 |
|
|
{
|
| 583 |
|
|
outPutAxle=1;
|
| 584 |
|
|
}
|
| 585 |
|
|
|
| 586 |
|
|
if(((axle>>1)&1) == 1)
|
| 587 |
|
|
{
|
| 588 |
|
|
outPutAxle=2;
|
| 589 |
|
|
}
|
| 590 |
|
|
|
| 591 |
|
|
if(((axle>>2)&1) == 1)
|
| 592 |
|
|
{
|
| 593 |
|
|
outPutAxle=3;
|
| 594 |
|
|
}
|
| 595 |
|
|
|
| 596 |
|
|
surfaceXYZAxleArray->setInt(outPutAxle);
|
| 597 |
|
|
System::println(surfaceXYZAxleArray->getInt());
|
| 598 |
|
|
surfaceXYZAxleArray->internIndexForward();
|
| 599 |
|
|
return true;
|
| 600 |
|
|
}
|
| 601 |
|
|
}
|
| 602 |
|
|
|
| 603 |
|
|
return false;
|
| 604 |
|
|
}
|
| 605 |
|
|
|
| 606 |
|
|
|
| 607 |
|
|
//*********************************************************
|
| 608 |
|
|
//texture size x,y,z
|
| 609 |
|
|
//*********************************************************
|
| 610 |
|
|
|
| 611 |
|
|
bool LwoLoader::computeChunkTSIZ(String &chunk, int chunkValue)
|
| 612 |
|
|
{
|
| 613 |
|
|
if (chunk.equals("TSIZ"))
|
| 614 |
|
|
{
|
| 615 |
|
|
if (surfaceTextureSizeXArray->getInternIndex() < numberOfSurfaces)
|
| 616 |
|
|
{
|
| 617 |
|
|
surfaceTextureSizeXArray->setFloat(binaryInput->getFloat());
|
| 618 |
|
|
surfaceTextureSizeYArray->setFloat(binaryInput->getFloat());
|
| 619 |
|
|
surfaceTextureSizeZArray->setFloat(binaryInput->getFloat());
|
| 620 |
|
|
System::println(surfaceTextureSizeXArray->getFloat());
|
| 621 |
|
|
System::println(surfaceTextureSizeYArray->getFloat());
|
| 622 |
|
|
System::println(surfaceTextureSizeZArray->getFloat());
|
| 623 |
|
|
surfaceTextureSizeXArray->internIndexForward();
|
| 624 |
|
|
surfaceTextureSizeYArray->internIndexForward();
|
| 625 |
|
|
surfaceTextureSizeZArray->internIndexForward();
|
| 626 |
|
|
|
| 627 |
|
|
return true;
|
| 628 |
|
|
}
|
| 629 |
|
|
}
|
| 630 |
|
|
|
| 631 |
|
|
return false;
|
| 632 |
|
|
}
|
| 633 |
|
|
|
| 634 |
|
|
//*********************************************************
|
| 635 |
|
|
//texture center x,y,z
|
| 636 |
|
|
//*********************************************************
|
| 637 |
|
|
|
| 638 |
|
|
bool LwoLoader::computeChunkTCTR(String &chunk, int chunkValue)
|
| 639 |
|
|
{
|
| 640 |
|
|
if (chunk.equals("TCTR"))
|
| 641 |
|
|
{
|
| 642 |
|
|
if (surfaceTextureCenterXArray->getInternIndex() < numberOfSurfaces)
|
| 643 |
|
|
{
|
| 644 |
|
|
surfaceTextureCenterXArray->setFloat(binaryInput->getFloat());
|
| 645 |
|
|
surfaceTextureCenterYArray->setFloat(binaryInput->getFloat());
|
| 646 |
|
|
surfaceTextureCenterZArray->setFloat(binaryInput->getFloat());
|
| 647 |
|
|
System::println(surfaceTextureCenterXArray->getFloat());
|
| 648 |
|
|
System::println(surfaceTextureCenterYArray->getFloat());
|
| 649 |
|
|
System::println(surfaceTextureCenterZArray->getFloat());
|
| 650 |
|
|
surfaceTextureCenterXArray->internIndexForward();
|
| 651 |
|
|
surfaceTextureCenterYArray->internIndexForward();
|
| 652 |
|
|
surfaceTextureCenterZArray->internIndexForward();
|
| 653 |
|
|
|
| 654 |
|
|
return true;
|
| 655 |
|
|
}
|
| 656 |
|
|
}
|
| 657 |
|
|
|
| 658 |
|
|
return false;
|
| 659 |
|
|
}
|
| 660 |
|
|
|
| 661 |
|
|
//*********************************************************
|
| 662 |
|
|
// calculate texturemapping
|
| 663 |
|
|
//*********************************************************
|
| 664 |
|
|
|
| 665 |
|
|
void LwoLoader::calcTextureMapping()
|
| 666 |
|
|
{
|
| 667 |
|
|
polygonPoint1UArray = new FloatArray(polygonSurfaces->size);
|
| 668 |
|
|
polygonPoint1VArray = new FloatArray(polygonSurfaces->size);
|
| 669 |
|
|
polygonPoint2UArray = new FloatArray(polygonSurfaces->size);
|
| 670 |
|
|
polygonPoint2VArray = new FloatArray(polygonSurfaces->size);
|
| 671 |
|
|
polygonPoint3UArray = new FloatArray(polygonSurfaces->size);
|
| 672 |
|
|
polygonPoint3VArray = new FloatArray(polygonSurfaces->size);
|
| 673 |
|
|
|
| 674 |
|
|
for ( int p=0; p<polygonSurfaces->size ; p++ )
|
| 675 |
|
|
{
|
| 676 |
|
|
int whichPolygonPoint=0;
|
| 677 |
|
|
float u=0;
|
| 678 |
|
|
float v=0;
|
| 679 |
|
|
|
| 680 |
|
|
calcUVForAVertices(p, whichPolygonPoint, &u, &v);
|
| 681 |
|
|
|
| 682 |
|
|
polygonPoint1UArray->setFloat(u,p);
|
| 683 |
|
|
polygonPoint1VArray->setFloat(v,p);
|
| 684 |
|
|
|
| 685 |
|
|
whichPolygonPoint++;
|
| 686 |
|
|
u=0;
|
| 687 |
|
|
v=0;
|
| 688 |
|
|
|
| 689 |
|
|
calcUVForAVertices(p, whichPolygonPoint, &u, &v);
|
| 690 |
|
|
|
| 691 |
|
|
polygonPoint2UArray->setFloat(u,p);
|
| 692 |
|
|
polygonPoint2VArray->setFloat(v,p);
|
| 693 |
|
|
|
| 694 |
|
|
whichPolygonPoint++;
|
| 695 |
|
|
u=0;
|
| 696 |
|
|
v=0;
|
| 697 |
|
|
|
| 698 |
|
|
calcUVForAVertices(p, whichPolygonPoint, &u, &v);
|
| 699 |
|
|
|
| 700 |
|
|
polygonPoint3UArray->setFloat(u,p);
|
| 701 |
|
|
polygonPoint3VArray->setFloat(v,p);
|
| 702 |
|
|
|
| 703 |
|
|
}
|
| 704 |
|
|
}
|
| 705 |
|
|
|
| 706 |
|
|
|
| 707 |
|
|
void LwoLoader::calcUVForAVertices(int whichPolygon, int whichPolygonPoint, float *u, float *v)
|
| 708 |
|
|
{
|
| 709 |
|
|
int whichSurface=polygonSurfaces->getInt(whichPolygon);
|
| 710 |
|
|
|
| 711 |
|
|
float x=xVerticesArray->getFloat(polygonPoints->getInt(whichPolygon*3+whichPolygonPoint))-surfaceTextureCenterXArray->getFloat(whichSurface);
|
| 712 |
|
|
float y=yVerticesArray->getFloat(polygonPoints->getInt(whichPolygon*3+whichPolygonPoint))-surfaceTextureCenterYArray->getFloat(whichSurface);
|
| 713 |
|
|
float z=zVerticesArray->getFloat(polygonPoints->getInt(whichPolygon*3+whichPolygonPoint))-surfaceTextureCenterZArray->getFloat(whichSurface);
|
| 714 |
|
|
|
| 715 |
|
|
|
| 716 |
|
|
float xTextureSize=surfaceTextureSizeXArray->getFloat(whichSurface);
|
| 717 |
|
|
float yTextureSize=surfaceTextureSizeYArray->getFloat(whichSurface);
|
| 718 |
|
|
float zTextureSize=surfaceTextureSizeZArray->getFloat(whichSurface);
|
| 719 |
|
|
int axle=surfaceXYZAxleArray->getInt(whichSurface);
|
| 720 |
|
|
|
| 721 |
|
|
if (surfaceMappingMethod->getInt(whichSurface) == 1)
|
| 722 |
|
|
{
|
| 723 |
|
|
if (axle==3)
|
| 724 |
|
|
{
|
| 725 |
|
|
u[0]=(x/xTextureSize+0.5f);
|
| 726 |
|
|
v[0]=(-y/yTextureSize+0.5f);
|
| 727 |
|
|
}
|
| 728 |
|
|
|
| 729 |
|
|
if (axle==1)
|
| 730 |
|
|
{
|
| 731 |
|
|
u[0]=(-z/zTextureSize+0.5f);
|
| 732 |
|
|
v[0]=(-y/yTextureSize+0.5f);
|
| 733 |
|
|
}
|
| 734 |
|
|
|
| 735 |
|
|
if (axle==2)
|
| 736 |
|
|
{
|
| 737 |
|
|
u[0]=(z/zTextureSize+0.5f);
|
| 738 |
|
|
v[0]=(x/xTextureSize+0.5f);
|
| 739 |
|
|
}
|
| 740 |
|
|
}
|
| 741 |
|
|
|
| 742 |
|
|
/*
|
| 743 |
|
|
if ( ctex[whichSurface] == 2)
|
| 744 |
|
|
{
|
| 745 |
|
|
float rz;
|
| 746 |
|
|
|
| 747 |
|
|
if ( tflg[whichSurface] == 3 )
|
| 748 |
|
|
{
|
| 749 |
|
|
u=(x/tsiz[whichSurface*3+0]);
|
| 750 |
|
|
v=(-y/tsiz[whichSurface*3+1]);
|
| 751 |
|
|
rz=(-z/tsiz[whichSurface*3+2]);
|
| 752 |
|
|
}
|
| 753 |
|
|
|
| 754 |
|
|
|
| 755 |
|
|
if ( tflg[whichSurface] == 1 )
|
| 756 |
|
|
{
|
| 757 |
|
|
rz=(x/tsiz[whichSurface*3+0]);
|
| 758 |
|
|
v=(y/tsiz[whichSurface*3+1]);
|
| 759 |
|
|
u=(z/tsiz[whichSurface*3+2]);
|
| 760 |
|
|
}
|
| 761 |
|
|
|
| 762 |
|
|
if ( tflg[whichSurface] == 2 )
|
| 763 |
|
|
{
|
| 764 |
|
|
u=(z/tsiz[whichSurface*3+2]);
|
| 765 |
|
|
v=(x/tsiz[whichSurface*3+0]);
|
| 766 |
|
|
rz=(y/tsiz[whichSurface*3+1]);
|
| 767 |
|
|
}
|
| 768 |
|
|
|
| 769 |
|
|
//twrp[tpoints[v2]*2+0]
|
| 770 |
|
|
u=1.0f-((float)(((atan2(v,u)/2)*2)/3.14)+0.25f);
|
| 771 |
|
|
v=0.5f+(float)(rz);
|
| 772 |
|
|
}
|
| 773 |
|
|
|
| 774 |
|
|
|
| 775 |
|
|
if ( ctex[whichSurface] == 3)
|
| 776 |
|
|
{
|
| 777 |
|
|
|
| 778 |
|
|
if ( tflg[whichSurface] == 2 )
|
| 779 |
|
|
{
|
| 780 |
|
|
u=(z/tsiz[whichSurface*3+2]+0.5f);
|
| 781 |
|
|
v=(x/tsiz[whichSurface*3+0]+0.5f);
|
| 782 |
|
|
}
|
| 783 |
|
|
|
| 784 |
|
|
if ( tflg[whichSurface] == 1 )
|
| 785 |
|
|
{
|
| 786 |
|
|
u=(-z/tsiz[whichSurface*3+2]+0.5f);
|
| 787 |
|
|
v=(-y/tsiz[whichSurface*3+1]+0.5f);
|
| 788 |
|
|
}
|
| 789 |
|
|
|
| 790 |
|
|
if ( tflg[whichSurface] == 3 )
|
| 791 |
|
|
{
|
| 792 |
|
|
u=(x/tsiz[whichSurface*3+0]+0.5f);
|
| 793 |
|
|
v=(-y/tsiz[whichSurface*3+1]+0.5f);
|
| 794 |
|
|
}
|
| 795 |
|
|
//lon*=twrp[tpoints[v2]*2+0];
|
| 796 |
|
|
//lon*=twrp[tpoints[v2]*2+1];
|
| 797 |
|
|
}
|
| 798 |
|
|
*/
|
| 799 |
|
|
if ( u[0] < 0 )
|
| 800 |
|
|
{
|
| 801 |
|
|
u[0]*=-1;
|
| 802 |
|
|
}
|
| 803 |
|
|
|
| 804 |
|
|
if ( v[0] < 0 )
|
| 805 |
|
|
{
|
| 806 |
|
|
v[0]*=-1;
|
| 807 |
|
|
}
|
| 808 |
|
|
|
| 809 |
|
|
|
| 810 |
|
|
if ( u[0] > 1 )
|
| 811 |
|
|
{
|
| 812 |
|
|
u[0]=1;
|
| 813 |
|
|
}
|
| 814 |
|
|
|
| 815 |
|
|
if ( v[0] > 1)
|
| 816 |
|
|
{
|
| 817 |
|
|
v[0]=1;
|
| 818 |
|
|
}
|
| 819 |
|
|
}
|
| 820 |
|
|
|
| 821 |
|
|
|
| 822 |
|
|
|
| 823 |
|
|
//vertices
|
| 824 |
|
|
|
| 825 |
|
|
void LwoLoader::readvertices(Object3d *out)
|
| 826 |
|
|
{
|
| 827 |
|
|
for ( int n=0 ; n<xVerticesArray->size ; n++ )
|
| 828 |
|
|
{
|
| 829 |
|
|
out->setvx(xVerticesArray->getFloat(n),n);
|
| 830 |
|
|
out->setvy(yVerticesArray->getFloat(n),n);
|
| 831 |
|
|
out->setvz(zVerticesArray->getFloat(n),n);
|
| 832 |
|
|
}
|
| 833 |
|
|
}
|
| 834 |
|
|
|
| 835 |
|
|
// u,v cordinates
|
| 836 |
|
|
|
| 837 |
|
|
void LwoLoader::readprepareuv2(Object3d *out)
|
| 838 |
|
|
{
|
| 839 |
|
|
for ( int n=0 ; n<polygonSurfaces->size ; n++ )
|
| 840 |
|
|
{
|
| 841 |
|
|
out->setvu(polygonPoint1UArray->getFloat(n),n*3+0);
|
| 842 |
|
|
out->setvv(polygonPoint1VArray->getFloat(n),n*3+0);
|
| 843 |
|
|
out->setvu(polygonPoint2UArray->getFloat(n),n*3+1);
|
| 844 |
|
|
out->setvv(polygonPoint2VArray->getFloat(n),n*3+1);
|
| 845 |
|
|
out->setvu(polygonPoint3UArray->getFloat(n),n*3+2);
|
| 846 |
|
|
out->setvv(polygonPoint3VArray->getFloat(n),n*3+2);
|
| 847 |
|
|
}
|
| 848 |
|
|
}
|
| 849 |
|
|
|
| 850 |
|
|
// transparent
|
| 851 |
|
|
|
| 852 |
|
|
void LwoLoader::readtransparent(Object3d *out)
|
| 853 |
|
|
{
|
| 854 |
|
|
for ( int p=0; p<polygonSurfaces->size ; p++ )
|
| 855 |
|
|
{
|
| 856 |
|
|
// out->settransparent(transparent[p],p);
|
| 857 |
|
|
}
|
| 858 |
|
|
|
| 859 |
|
|
}
|
| 860 |
|
|
|
| 861 |
|
|
// colour
|
| 862 |
|
|
|
| 863 |
|
|
void LwoLoader::readcolour(Object3d *out)
|
| 864 |
|
|
{
|
| 865 |
|
|
for ( int p=0; p<polygonSurfaces->size ; p++ )
|
| 866 |
|
|
{
|
| 867 |
|
|
// out->setcolour(colour[p],p);
|
| 868 |
|
|
}
|
| 869 |
|
|
}
|
| 870 |
|
|
|
| 871 |
|
|
// vertices points
|
| 872 |
|
|
|
| 873 |
|
|
void LwoLoader::readvpoints(Object3d *out)
|
| 874 |
|
|
{
|
| 875 |
|
|
for ( int s=0 ; s<polygonPoints->size ; s++ )
|
| 876 |
|
|
{
|
| 877 |
|
|
out->setpoints(polygonPoints->getInt(s),s);
|
| 878 |
|
|
}
|
| 879 |
|
|
}
|
| 880 |
|
|
|
| 881 |
|
|
// texture address
|
| 882 |
|
|
|
| 883 |
|
|
void LwoLoader::readttpoints(Object3d *out)
|
| 884 |
|
|
{
|
| 885 |
|
|
for ( int s=0 ; s<polygonSurfaces->size ; s++ )
|
| 886 |
|
|
{
|
| 887 |
|
|
out->settpoints(polygonSurfaces->getInt(s),s);
|
| 888 |
|
|
}
|
| 889 |
|
|
}
|