AbstractModel* WavefrontLoader::load(const char* str) {
	WavefrontModel* m = new WavefrontModel();

	m->setName(str);
#ifndef SERVER
	std::ifstream file;

	file.open(str);

	std::stringstream ss(std::stringstream::in | std::stringstream::out);
	std::string line;
	std::string value;

	if (file.is_open()) {
		//std::cout << "file is open" << std::endl;
		while (!file.eof()) {
			getline(file, line);
			ss.clear();
			ss.str(line);
			value = "";
			ss >> value;

			//std::cout << "line is " << value << std::endl;
			//std::cout << "ss is " << ss.str() << std::endl;

			if (value.compare("mtllib") == 0) {
				//std::cout << "mtllib not supported yet" << std::endl;
			} else if (value.compare("o") == 0) {
				//std::cout << "o not supported yet" << std::endl;
			} else if (value.compare("#") == 0) {
				//std::cout << "# not supported yet" << std::endl;
			} else if (value.compare("usemtl") == 0) {
				//std::cout << "usemtl not supported yet" << std::endl;
			} else if (value.compare("s") == 0) {
				//std::cout << "s not supported yet" << std::endl;
			} else if (value.compare("v") == 0) {
				//std::cout << "adding vertex" << std::endl;
				std::string tmp = ss.str().substr(2);
				handleVertex(m, tmp);
			} else if (value.compare("f") == 0) {
				//std::cout << "adding face" << std::endl;
				std::string tmp = ss.str().substr(2);
				handleFace(m, tmp);
			} else if (value.compare("vn") == 0) {
				//std::cout << "adding face" << std::endl;
				std::string tmp = ss.str().substr(2);
				handleNormal(m, tmp);
			} else if (value.compare("vt") == 0) {
				//std::cout << "adding face" << std::endl;
				std::string tmp = ss.str().substr(2);
				handleTexture(m, tmp);
			}
		}
	}
#endif
	//m->print();

	AbstractModel* a = m;
	return a;
}
    //------------------------------
	bool LibraryEffectsLoader::begin__texture( const texture__AttributeData& attributeData )
	{
        mInTexture = true;

		return handleTexture( attributeData);
	}
void ADBCallback(ADB_CHANNEL_HANDLE handle, const void* data, UINT32 data_len) {
    // Ignore empty messages
    if (data_len < 1) {
        return;
    }


    //DEBUGLED = 0;

    // Get data without the first byte
    //BYTE raw_data[data_len - 1];
    //memmove(raw_data, data + 1, data_len - 1);

    // First byte identifies the data
    BYTE* id = (BYTE*) data;

    if (data_len > 5) {

        switch (*id) {
            case COMMAND_TEXT:

                handleTexture(((BYTE*) data) + 1, data_len - 1);

                break;

            default:
                break;
        }
        return;


    }
    switch (*id) {

        case COMMAND_FREQ:

            incoming = intFromBytes(((BYTE*) data) + 1);
            PR2 = (SYS_FREQ / incoming) - 1;
            TMR2 = 0; // reset the Timer2 count
            

            break;

        case COMMAND_MAG:

            tpadMAG = (int)*(((BYTE*) data) + 1);
            PWM_Set_DC(tpadMAG / 255.0 * 50); //scale incoming magnitude to a duty cycle 0-50
            pauseTimer3();
            tBuff.On = 0x0;

            break;

        case COMMAND_ALIVE:
            WriteCoreTimer(0);
            break;

        default:
            break;
    }
    return;

}
UInt32 CubeTextureObjChunk::handleGL(DrawEnv                 *pEnv, 
                                     UInt32                   osgid, 
                                     Window::GLObjectStatusE  mode,
                                     UInt32                   uiOptions)
{
    GLuint  id;

    Window *win = pEnv->getWindow();

    // does the window support cubemaps?
    if(win->hasExtension(_arbCubeTex) == false)
        return 0;

    id = win->getGLObjectId(osgid);

    if(mode == Window::initialize || mode == Window::reinitialize)
    {
        if(mode == Window::initialize)
        {
            glGenTextures(1, &id);

            win->setGLObjectId(osgid, id);
        }

        handleTexture(win, id, 
                      GL_TEXTURE_CUBE_MAP_ARB, 
                      GL_TEXTURE_CUBE_MAP_ARB, 
                      GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB, 
                      mode, getImage());        
        handleTexture(win, id, 
                      GL_TEXTURE_CUBE_MAP_ARB, 
                      GL_NONE, 
                      GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB, 
                      Window::initialize, getPosZImage());        
        handleTexture(win, id, 
                      GL_TEXTURE_CUBE_MAP_ARB, 
                      GL_NONE, 
                      GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB, 
                      Window::initialize, getNegYImage());        
        handleTexture(win, id, 
                      GL_TEXTURE_CUBE_MAP_ARB, 
                      GL_NONE, 
                      GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB, 
                      Window::initialize, getPosYImage());        
        handleTexture(win, id, 
                      GL_TEXTURE_CUBE_MAP_ARB, 
                      GL_NONE, 
                      GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB, 
                      Window::initialize, getNegXImage());        
        handleTexture(win, id, 
                      GL_TEXTURE_CUBE_MAP_ARB, 
                      GL_NONE, 
                      GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB, 
                      Window::initialize, getPosXImage());        
    }
    else if(mode == Window::needrefresh)
    {
        handleTexture(win, id, 
                      GL_TEXTURE_CUBE_MAP_ARB, 
                      GL_TEXTURE_CUBE_MAP_ARB, 
                      GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB, 
                      mode, getImage());        
        handleTexture(win, id, 
                      GL_TEXTURE_CUBE_MAP_ARB, 
                      GL_NONE, 
                      GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB, 
                      mode, getPosZImage());        
        handleTexture(win, id, 
                      GL_TEXTURE_CUBE_MAP_ARB, 
                      GL_NONE, 
                      GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB, 
                      mode, getNegYImage());        
        handleTexture(win, id, 
                      GL_TEXTURE_CUBE_MAP_ARB, 
                      GL_NONE, 
                      GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB, 
                      mode, getPosYImage());        
        handleTexture(win, id, 
                      GL_TEXTURE_CUBE_MAP_ARB, 
                      GL_NONE, 
                      GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB, 
                      mode, getNegXImage());        
        handleTexture(win, id, 
                      GL_TEXTURE_CUBE_MAP_ARB, 
                      GL_NONE, 
                      GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB, 
                      mode, getPosXImage());        
    }
    else
    {
        SWARNING << "Win:" << win << "TextureObjChunk(" << this 
                 << "::handleGL: Illegal mode: "
                 << mode << " for id " << id << std::endl;
    }

    return 0;
}