Example #1
0
IgfxObject::IgfxObject(hIMDL mdl)
: m_ref(0), m_flag(0), m_mdl(mdl), m_alpha(1.0f), m_pCalModel(0), m_pObjMats(0),
  m_wrldTrans(0,0,0), m_wrldScl(1,1,1), m_parent(0), m_parentBoneID(-1)
{
	if(!m_mdl) return;

	memset(m_lights, 0, sizeof(m_lights));

	m_mdl->AddRef();

	CalCoreModel *pCalCoreModel = m_mdl->GetCalCoreModel();

	//create Cal Model instance (if we are using Cal3D model)
	if(pCalCoreModel)
	{
		m_pCalModel = new CalModel;

		if(!m_pCalModel)
		{ LogMsg(LOG_FILE, L"OBJCreate", L"Unable to allocate Cal3D Model"); return; }

		if(!m_pCalModel->create(pCalCoreModel))
		{ 
			tCHAR errStr[MAXCHARBUFF]; mbstowcs(errStr, CalError::getLastErrorText().c_str(), MAXCHARBUFF);
			LogMsg(LOG_FILE, L"OBJCreate", errStr); 
			return; 
		}

		// attach all meshes to the model
		s32 meshId;
		for(meshId = 0; meshId < pCalCoreModel->getCoreMeshCount(); meshId++)
		{
			m_pCalModel->attachMesh(meshId);
		}

		// set the material set of the whole model
		m_pCalModel->setMaterialSet(0);

		m_pCalModel->update(0);
	}

	//create object materials and derive them from model
	u32 numMat = m_mdl->GetNumMaterial();

	if(numMat > 0)
	{
		m_pObjMats = (gfxObjMat *)MemAlloc(sizeof(gfxObjMat)*numMat);
		if(!m_pObjMats)
		{ LogMsg(LOG_FILE, L"OBJCreate", L"Unable to allocate Object Materials"); return; }
	}

	ResetMaterial();

	MtxIdentity(&m_axis);
}
Example #2
0
 CoreModel(const std::string& id) {
     _coreModel.create(id);
     _scale = 1.0f;
     // Identity.
     std::fill(_matrix, _matrix + 16, 0.0f);
     for (int i = 0; i < 4; ++i) {
         _matrix[i * 4 + i] = 1;
     }
     loadConfigFile(id, _coreModel);
 }
Example #3
0
CCal3DSceneNode::CCal3DSceneNode( CCal3DModel* model, ISceneNode* parent, ISceneManager* manager, s32 id,
                                  const core::vector3df& position,
                                  const core::vector3df& rotation,
                                  const core::vector3df& scale )
        : ISceneNode( parent, manager, id, position, rotation, scale )
{
    OverrideMaterial = false;
    LastUpdateTime = 0;
    TimeScale = 1.0f;
    
    Model = model;
    
    CalCoreModel* coreModel = 0;
    if ( Model != 0 )
    {
        Model->grab();
        BoundingBox = Model->getBoundingBox();
        coreModel = Model->getCalCoreModel();
    }
    
    if ( coreModel != 0 )
    {
        calModel = new CalModel( coreModel );
        s32 meshCount = coreModel->getCoreMeshCount();
        for ( s32 i=0; i<meshCount; i++ )
        {
            calModel->attachMesh(i);
        }
        calModel->setMaterialSet(0);
        calModel->update(0.0f);
    }
    else
    {
        calModel = 0;
    }

    draw_mode = DM_DEFAULT;
    draw_bbox = false;
}
Example #4
0
bool CSkeletonCandidate::CreateFromSkeletonFile(const std::string& strFilename)
{
	// clear current content
	Clear();

	m_strFilename = strFilename;

	// create a core model instance
	CalCoreModel * coreModel = new CalCoreModel;

	if(!coreModel->createInternal("dummy"))
	{
		theExporter.SetLastErrorFromCal(__FILE__, __LINE__);
		return false;
	}

	// load the core skeleton instance
	if(!coreModel->loadCoreSkeleton(m_strFilename))
	{
		theExporter.SetLastErrorFromCal(__FILE__, __LINE__);
		coreModel->destroy();
		return false;
	}

	// get core skeleton
	CalCoreSkeleton *pCoreSkeleton;
	pCoreSkeleton = coreModel->getCoreSkeleton();
	
	// get core bone vector
	std::vector<CalCoreBone *>& vectorCoreBone = pCoreSkeleton->getVectorCoreBone();

	// loop through all root core bones
	std::list<int>::iterator iteratorRootCoreBoneId;
	for(iteratorRootCoreBoneId = pCoreSkeleton->getListRootCoreBoneId().begin(); iteratorRootCoreBoneId != pCoreSkeleton->getListRootCoreBoneId().end(); ++iteratorRootCoreBoneId)
	{
		// recursively add the core bone to the skeleton candidate
		if(!AddNode(pCoreSkeleton, vectorCoreBone[*iteratorRootCoreBoneId], -1))
		{
			coreModel->destroy();
			return false;
		}
	}

	// destroy core model
	m_coreModel = coreModel;
	return true;
}
Example #5
0
CalCoreModel *CharacterModel::loadConfig(std::string filename)
{
    PathHandler ph;
    std::string pfile;
    
    ph.setBaseFile(filename.c_str());
    
    // open the model configuration file
    std::ifstream file;
    file.open(filename.c_str(), std::ios::in | std::ios::binary);
    if(!file)
    {
        SWARNING << "Failed to open model configuration file '" 
                 << filename << "'." << endLog;
        return NULL;
    }

    CalCoreModel *model = new CalCoreModel("dummy");
    
    // parse all lines from the model configuration file
    int line;
    for(line = 1; ; line++)
    {
        // read the next model configuration line
        std::string strBuffer;
        std::getline(file, strBuffer);

        // stop if we reached the end of file
        if(file.eof()) break;

        // check if an error happend while reading from the file
        if(!file)
        {
            SWARNING << "Error while reading from the model configuration file '" 
                     << filename << "'." << endLog;
            return NULL;
        }

        // find the first non-whitespace character
        std::string::size_type pos;
        pos = strBuffer.find_first_not_of(" \t");

        // check for empty lines
        if((pos == std::string::npos) || (strBuffer[pos] == '\n') || 
           (strBuffer[pos] == '\r') || (strBuffer[pos] == 0)) 
            continue;

        // check for comment lines
        if(strBuffer[pos] == '#') continue;

        // get the key
        std::string strKey;
        strKey = strBuffer.substr(pos, strBuffer.find_first_of(" =\t\n\r", pos) - pos);
        pos += strKey.size();

        // get the '=' character
        pos = strBuffer.find_first_not_of(" \t", pos);
        if((pos == std::string::npos) || (strBuffer[pos] != '='))
        {
            SWARNING << filename << "(" << line << "): Invalid syntax." 
                     << endLog;
            return false;
        }

        // find the first non-whitespace character after the '=' character
        pos = strBuffer.find_first_not_of(" \t", pos + 1);

        // get the data
        std::string strData;
        strData = strBuffer.substr(pos, 
                            strBuffer.find_first_of("\n\r", pos) - pos);

        // handle the model creation
        if(strKey == "scale")
        {
            // set rendering scale factor
            //m_scale = atof(strData.c_str());
        }
        else if(strKey == "skeleton")
        {
            pfile = ph.findFile(strData.c_str());

            // load core skeleton
            SINFO << "Loading skeleton '" << pfile << "'..." << endLog;
            
            if(!model->loadCoreSkeleton(pfile.c_str()))
            {
                CalError::printLastError();
                return false;
            }
        }
        else if(strKey == "animation")
        {
            pfile = ph.findFile(strData.c_str());
            
            // load core animation
            SINFO << "Loading animation '" << pfile 
                  << "'..." << endLog;
            if(model->loadCoreAnimation(pfile.c_str()) == -1)
            {
                CalError::printLastError();
                return false;
            }
        }
        else if(strKey == "mesh")
        {
            pfile = ph.findFile(strData.c_str());

            // load core mesh
            SINFO << "Loading mesh '" << pfile << "'..." << endLog;
            if(model->loadCoreMesh(pfile.c_str()) == -1)
            {
                CalError::printLastError();
                return false;
            }
        }
        else if(strKey == "material")
        {
            pfile = ph.findFile(strData.c_str());

            // load core material
            SINFO << "Loading material '" << pfile << "'..." << endLog;
            if(model->loadCoreMaterial(pfile.c_str()) == -1)
            {
                CalError::printLastError();
                return false;
            }
        }
        else
        {
            // everything else triggers an error message, but is ignored
            SWARNING << filename << "(" << line << "): Invalid syntax." 
                     << endLog;
        }
    }

    // create material threads
    int mid;
    for(mid = 0; mid < model->getCoreMaterialCount(); mid++)
    {
        model->createCoreMaterialThread(mid);
        model->setCoreMaterialId(mid, 0, mid);
    }

    file.close();

    return model;
}
Example #6
0
void Cal3dCore::loadCore(const char *fn)
{
    coreModel = new osgCal::CoreModel();
    animNum = -1;
    meshAdder = new osgCal::DefaultMeshAdder;
    p = new osgCal::MeshParameters;
    p->useDepthFirstMesh = false;
    p->software = false; // default

    try
    {
        std::string ext = osgDB::getLowerCaseFileExtension(fn);
        std::string dir = osgDB::getFilePath(fn);
        std::string name = osgDB::getStrippedName(fn);

        if (dir == "")
        {
            dir = ".";
        }

        if (ext == "caf")
        {
            coreModel->load(dir + "/cal3d.cfg", p.get());

            for (size_t i = 0; i < coreModel->getAnimationNames().size(); i++)
            {
                if (coreModel->getAnimationNames()[i] == name)
                {
                    animNum = i;
                    break;
                }
            }

            if (animNum == -1)
            {
                // animation is absent in cal3d.cfg, so load it manually
                CalCoreModel *cm = coreModel->getCalCoreModel();

                std::cout << coreModel->getScale() << std::endl;
                if (coreModel->getScale() != 1)
                {
                    // to eliminate scaling of the model by non-scaled animation
                    // we scale model back, load animation, and rescale one more time
                    cm->scale(1.0 / coreModel->getScale());
                }

                animNum = cm->loadCoreAnimation(fn);

                if (coreModel->getScale() != 1)
                {
                    cm->scale(coreModel->getScale());
                }
            }
        }
        else if (ext == "cmf")
        {
            coreModel->load(dir + "/cal3d.cfg", p.get());
            meshAdder = new osgCal::OneMeshAdder(osgDB::getStrippedName(fn));
        }
        else
        {
            coreModel->load(fn, p.get());
        }
    }
    catch (std::runtime_error &e)
    {
        std::cout << "runtime error during load:" << std::endl
                  << e.what() << std::endl;
        return;
    }
}