36 #define WAVEFRONT_DEBUG 0 // 1 = fail on error, 0 = ignore errors
73 static bool parseFloats (
const char*&
ptr,
F32* values,
int num);
97 bool FW::parseFloats(
const char*&
ptr,
F32* values,
int num)
100 const char* tmp =
ptr;
101 for (
int i = 0; i < num; i++)
144 if (!parseFloats(ptr, tmp, 2))
169 while (*ptr && (*ptr !=
'-' || !name.
endsWith(
' ')))
190 #if (!WAVEFRONT_DEBUG)
201 for (
int lineNum = 1;; lineNum++)
203 const char* line = mtlIn.
readLine(
true,
true);
204 if (!line || ((lineNum & 0xFF) == 0 &&
hasError()))
207 const char* ptr = line;
227 setError(
"No current material in Wavefront MTL: '%s'!", line);
235 else if (parseFloats(ptr, tmp, 3) &&
parseSpace(ptr) && !*ptr)
270 valid = parseTexture(ptr, tex, dirName);
276 valid = parseTexture(ptr, tex, dirName);
282 valid = parseTexture(ptr, tex, dirName);
290 valid = parseTexture(ptr, tex, dirName);
296 valid = parseTexture(ptr, tex, dirName);
353 setError(
"Invalid line %d in Wavefront MTL: '%s'!", lineNum, line);
363 int defaultSubmesh = -1;
365 for (
int lineNum = 1;; lineNum++)
367 const char* line = objIn.
readLine(
true,
true);
368 if (!line || ((lineNum & 0xFF) == 0 &&
hasError()))
371 const char* ptr = line;
430 for (
int i = 0; i < 3; i++)
437 if (ptn[i] < 0 || ptn[i] >=
size[i])
457 if (defaultSubmesh == -1)
458 defaultSubmesh = s.
mesh->addSubmesh();
459 submesh = defaultSubmesh;
499 #if (!WAVEFRONT_DEBUG)
542 setError(
"Invalid line %d in Wavefront OBJ: '%s'!", lineNum, line);
556 int vertexCapacity = 4 << 10;
557 int indexCapacity = 4 << 10;
561 s.
mesh->resizeVertices(vertexCapacity);
562 s.
mesh->clearVertices();
565 s.
normals.setCapacity(vertexCapacity);
567 s.
indexTmp.setCapacity(indexCapacity);
585 int idx = baseName.
indexOf(
'.');
600 stream.
writef(
"v %g %g %g\n", v.
p.x, v.
p.y, v.
p.z);
607 stream.
writef(
"vt %g %g\n", v.
t.x, 1.0f - v.
t.y);
614 stream.
writef(
"vn %g %g %g\n", v.
n.x, v.
n.y, v.
n.z);
621 stream.
writef(
"usemtl %d\n", i);
624 for (
int j = 0; j < tris.
getSize(); j++)
626 Vec3i v = tris[j] + 1;
627 stream.
writef(
"f %d/%d/%d %d/%d/%d %d/%d/%d\n",
668 for (
int k = 0; texNameSet.
contains(name); k++)
678 texNameSet.
add(name);
692 mtlOut.
writef(
"newmtl %d\n", i);
693 mtlOut.
writef(
"Ka 0 0 0\n");
706 mtlOut.
writef(
"disp -mm %g %g %s\n",
void exportImage(const String &fileName, const Image *image)
int nextSlot(int slot) const
String & append(char chr)
bool contains(const K &key) const
String substring(int start, int end) const
bool endsWith(const String &str) const
const char * getPtr(void) const
String getFileName(void) const
FW_CUDA_FUNC const F32 * getPtr(void) const
int indexOf(char chr) const
const Image * getImage(void) const
void setError(const char *fmt,...)
FW_CUDA_FUNC const F32 * getPtr(void) const
int numSubmeshes(void) const
const Material & material(int submesh) const
void exportWavefrontMesh(BufferedOutputStream &stream, const MeshBase *mesh, const String &fileName)
Mesh< VertexPNT > * importWavefrontMesh(BufferedInputStream &stream, const String &fileName)
bool parseLiteral(const char *&ptr, const char *str)
const Entry & getSlot(int slot) const
bool contains(const T &value) const
CUdevice int ordinal char int CUdevice dev CUdevprop CUdevice dev CUcontext ctx CUcontext ctx CUcontext pctx CUmodule const void image CUmodule const void fatCubin CUfunction CUmodule const char name void p CUfunction unsigned int bytes CUtexref pTexRef CUtexref CUarray unsigned int Flags CUtexref int CUaddress_mode am CUtexref unsigned int Flags CUaddress_mode CUtexref int dim CUarray_format int CUtexref hTexRef CUfunction unsigned int numbytes CUfunction int float value CUfunction int CUtexref hTexRef CUfunction int int grid_height CUevent unsigned int Flags CUevent hEvent CUevent hEvent CUstream unsigned int Flags CUstream hStream GLuint bufferobj unsigned int CUdevice dev CUdeviceptr unsigned int CUmodule const char name CUdeviceptr unsigned int bytesize CUdeviceptr dptr void unsigned int bytesize void CUdeviceptr unsigned int ByteCount CUarray unsigned int CUdeviceptr unsigned int ByteCount CUarray unsigned int const void unsigned int ByteCount CUarray unsigned int CUarray unsigned int unsigned int ByteCount void CUarray unsigned int unsigned int CUstream hStream const CUDA_MEMCPY2D pCopy CUdeviceptr const void unsigned int CUstream hStream const CUDA_MEMCPY2D CUstream hStream CUdeviceptr unsigned char unsigned int N CUdeviceptr unsigned int unsigned int N CUdeviceptr unsigned int unsigned short unsigned int unsigned int Height CUarray const CUDA_ARRAY_DESCRIPTOR pAllocateArray CUarray const CUDA_ARRAY3D_DESCRIPTOR pAllocateArray unsigned int CUtexref CUdeviceptr unsigned int bytes CUcontext unsigned int CUdevice device GLenum texture GLenum GLuint buffer GLenum GLuint renderbuffer GLenum GLsizeiptr const GLvoid GLenum usage GLuint shader GLenum type GLsizei const GLuint framebuffers GLsizei const GLuint renderbuffers GLuint v
static Texture import(const String &fileName)
Hash< Vec3i, S32 > vertexHash
const V & vertex(int idx) const
int getLength(void) const
bool equals< Vec3f >(const Vec3f &a, const Vec3f &b)
FW_CUDA_FUNC void setZero(void)
String getDirName(void) const
String sprintf(const char *fmt,...)
bool parseInt(const char *&ptr, S32 &value)
bool equals(const T &a, const T &b)
FW_CUDA_FUNC const F32 * getPtr(void) const
V & add(const K &key, const V &value)
int numVertices(void) const
U32 hashBits(U32 a, U32 b=FW_HASH_MAGIC, U32 c=0)
CUdevice int ordinal char int CUdevice dev CUdevprop CUdevice dev CUcontext ctx CUcontext ctx CUcontext pctx CUmodule const void image CUmodule const void fatCubin CUfunction CUmodule const char name void p CUfunction unsigned int bytes CUtexref pTexRef CUtexref CUarray unsigned int Flags CUtexref int CUaddress_mode am CUtexref unsigned int Flags CUaddress_mode CUtexref int dim CUarray_format int CUtexref hTexRef CUfunction unsigned int numbytes CUfunction int float value CUfunction int CUtexref hTexRef CUfunction f
const Array< Vec3i > & indices(int submesh) const
CUdevice int ordinal char int CUdevice dev CUdevprop CUdevice dev CUcontext ctx CUcontext ctx CUcontext pctx CUmodule const void image CUmodule const void fatCubin CUfunction CUmodule const char name void p CUfunction unsigned int bytes CUtexref pTexRef CUtexref CUarray unsigned int Flags CUtexref int CUaddress_mode am CUtexref unsigned int Flags CUaddress_mode CUtexref int dim CUarray_format int CUtexref hTexRef CUfunction unsigned int numbytes CUfunction int float value
Texture textures[TextureType_Max]
bool parseFloat(const char *&ptr, F32 &value)
bool startsWith(const String &str) const
bool parseSpace(const char *&ptr)
U32 hash< Vec3f >(const Vec3f &value)
void writef(const char *fmt,...)
U32 hash< Vec2f >(const Vec2f &value)
CUdevice int ordinal char int CUdevice dev CUdevprop CUdevice dev CUcontext ctx CUcontext ctx CUcontext pctx CUmodule const void image CUmodule const void fatCubin CUfunction CUmodule const char name void p CUfunction unsigned int bytes CUtexref pTexRef CUtexref CUarray unsigned int Flags CUtexref int CUaddress_mode am CUtexref unsigned int Flags CUaddress_mode CUtexref int dim CUarray_format int CUtexref hTexRef CUfunction unsigned int numbytes CUfunction int float value CUfunction int CUtexref hTexRef CUfunction int int grid_height CUevent unsigned int Flags CUevent hEvent CUevent hEvent CUstream unsigned int Flags CUstream hStream GLuint bufferobj unsigned int CUdevice dev CUdeviceptr unsigned int CUmodule const char name CUdeviceptr unsigned int bytesize CUdeviceptr dptr void unsigned int bytesize void CUdeviceptr unsigned int ByteCount CUarray unsigned int CUdeviceptr unsigned int ByteCount CUarray unsigned int const void unsigned int ByteCount CUarray unsigned int CUarray unsigned int unsigned int ByteCount void CUarray unsigned int unsigned int CUstream hStream const CUDA_MEMCPY2D pCopy CUdeviceptr const void unsigned int CUstream hStream const CUDA_MEMCPY2D CUstream hStream CUdeviceptr unsigned char unsigned int N CUdeviceptr unsigned int unsigned int N CUdeviceptr unsigned int unsigned short unsigned int unsigned int Height CUarray const CUDA_ARRAY_DESCRIPTOR pAllocateArray CUarray const CUDA_ARRAY3D_DESCRIPTOR pAllocateArray unsigned int CUtexref CUdeviceptr unsigned int bytes CUcontext unsigned int CUdevice device GLenum texture GLenum GLuint buffer GLenum GLuint renderbuffer GLenum GLsizeiptr size
Hash< String, Material > materialHash
bool equals< Vec2f >(const Vec2f &a, const Vec2f &b)
int firstSlot(void) const