void StringBuilder::clear() { len = 0; nextchar = 0; if (chunk == NULL) pushChunk(); while (chunk->next != NULL) popChunk(); }
bool Loader3ds::loadFile( const String &filename ) { //Try to open file File module = File::GetModule(); file = module.getRelativeFile( filename ); fileSize = (int) file.getSize(); if( !file.open( "rb" )) return false; //Read main chunk info ChunkInfo mainChunk; readChunkInfo( &mainChunk ); if( mainChunk.id != CHUNK_MAIN ) return false; pushChunk( mainChunk ); //Create root object node root = new Actor3D(); //Process sub-chunks while( !isChunkDone() ) { ChunkInfo subChunk; readChunkInfo( &subChunk ); pushChunk( subChunk ); switch( subChunk.id ){ case CHUNK_EDITOR: chunk_EDITOR(); break; case CHUNK_KEYFRAMER: chunk_KEYFRAMER(); break; default:; } popChunk(); } //End main chunk popChunk(); file.close(); return true; }
void Loader3ds::chunk_MESH (const String &id) { //Create new mesh resource PolyMesh *mesh = new PolyMesh; resources.pushBack(mesh); //Create new shape object PolyMeshActor *shape = new PolyMeshActor; shape->setId (id); shape->setMesh (mesh); objects.pushBack (shape); root->addChild (shape); //Temporary lists VertArray verts; FaceArray faces; UVArray uvcoords; //Process sub-chunks while (!isChunkDone()) { ChunkInfo subChunk; readChunkInfo(&subChunk); pushChunk(subChunk); switch(subChunk.id) { case CHUNK_MESH_VERTEX_LIST: chunk_MESH_VERTEX_LIST (mesh, &verts); break; case CHUNK_MESH_TEX_COORD_LIST: chunk_MESH_TEX_COORD_LIST (mesh, &uvcoords); break; case CHUNK_MESH_FACE_LIST: chunk_MESH_FACE_LIST (mesh, &verts, &uvcoords, &faces); break; default:; } popChunk(); } //Apply tex coords to faces for (UintSize f=0; f<faces.size(); ++f) { } }
void Loader3ds::chunk_EDITOR () { //Process sub-chukns while(!isChunkDone()) { ChunkInfo subChunk; readChunkInfo(&subChunk); pushChunk(subChunk); switch(subChunk.id) { case CHUNK_OBJECT: chunk_OBJECT(); break; default:; } popChunk(); } }
void StringBuilder::append(const wchar* ptr, const wchar* lim) { if (lim == NULL) { lim = ptr; while (*lim != 0) lim++; } while (ptr < lim) { uint32_t avail = SBChunk::chunksize - nextchar; uint32_t need = uint32_t(lim - ptr); uint32_t k = min(need, avail); memcpy(chunk->data + nextchar, ptr, k*sizeof(wchar)); ptr += k; nextchar += k; len += k; if (ptr < lim) { pushChunk(); nextchar = 0; } } }
static bool push(JNIEnv *env, const utf16string &server, jobject notify) { invokeNotify(env, notify, "PUSH_STARTED", nullptr); CLowlaDBPushData::ptr pd = lowladb_collect_push_data(); while (!pd->isComplete() && !env->ExceptionCheck()) { pushChunk(env, server, pd, notify); } // If there's a pending exception, we need to clear it before we can notify PUSH_ENDED if (env->ExceptionCheck()) { jstring msg = clearException(env); invokeNotify(env, notify, "PUSH_ENDED", nullptr); invokeNotify(env, notify, "ERROR", msg); return false; } else { invokeNotify(env, notify, "PUSH_ENDED", nullptr); return true; } }
void Loader3ds::chunk_OBJECT () { //get object name String id = readString(); //Proccess sub-chunks while (!isChunkDone()) { ChunkInfo subChunk; readChunkInfo(&subChunk); pushChunk(subChunk); switch(subChunk.id) { case CHUNK_MESH: chunk_MESH(id); break; default:; } popChunk(); } }
void Loader3ds::chunk_MESH_FACE_LIST (PolyMesh *mesh, VertArray *verts, UVArray *uvcoords, FaceArray *faces) { //Read number of faces Int16 faceCount = 0; if (file.readLE(&faceCount, 2) != 2) return; for (int i=0; i<faceCount; ++i) { //Read vertex indices Int16 i1, i2, i3; Int16 flag; if (file.readLE(&i1, 2) != 2) return; if (file.readLE(&i2, 2) != 2) return; if (file.readLE(&i3, 2) != 2) return; if (file.readLE(&flag, 2) != 2) return; //Make sure indices are in vertex range if (i1 < 0 || i1 >= (Int16) verts->size()) return; if (i2 < 0 || i2 >= (Int16) verts->size()) return; if (i3 < 0 || i3 >= (Int16) verts->size()) return; //Add face to mesh PolyMesh::Vertex* v[3] = { verts->elementAt(i1), verts->elementAt(i2), verts->elementAt(i3) }; PolyMesh::Face* face = mesh->addFace(v, 3); faces->pushBack(face); //Make sure indices are in UV range if (i1 >= (Int16) uvcoords->size()) continue; if (i2 >= (Int16) uvcoords->size()) continue; if (i3 >= (Int16) uvcoords->size()) continue; //Apply UV coordinates //TODO: Add UV face instead //DMesh::HalfEdge *h = face->hedgeTo(v[0]); //if (h == NULL) return; //h->uv = uvcoords->elementAt(i1); //h->nextHedge()->uv = uvcoords->elementAt(i2); //h->nextHedge()->nextHedge()->uv = uvcoords->elementAt(i3); } //Process sub-chunks while (!isChunkDone()) { ChunkInfo subChunk; readChunkInfo(&subChunk); pushChunk(subChunk); switch(subChunk.id) { case CHUNK_MESH_FACE_SMOOTH_GROUP_LIST: chunk_MESH_FACE_SMOOTH_GROUP_LIST(mesh, faces); break; default:; } popChunk(); } }