Beispiel #1
0
//-----------------------------------------------------------------------------------------------------------
bool RawMesh::read(const char* fileName)
{
    if(fileName == nullptr)
        return false;

    std::ifstream stream(fileName, std::ios::binary);
    if(!stream)
    {
        std::cout << "error: could not open file" << std::endl;
        return false;
    }

    if(!readHeader(stream))
        return false;

    if(!readVertices(stream))
        return false;

    if(!readFaces(stream))
        return false;

    if(!readMaterials(stream))
        return false;

    if(!readBones(stream))
        return false;

    if(stream.fail())
    {
        std::cout << "error: broken file" << std::endl;
        return false;
    }

    return true;
}
// Read in the scene data, and load the necessary resources
scene_data* loadScene(const std::string& fileName)
{
	scene_data* scene = new scene_data;
	boost::property_tree::ptree pt;
	boost::property_tree::read_json(fileName, pt);

	readGeometry(scene, pt.get_child("geometry"));
	readTextures(scene, pt.get_child("textures"));
	readMaterials(scene, pt.get_child("materials"));
	readObjects(scene, pt.get_child("objects"));
	readLighting(scene, pt.get_child("lighting"));
	readDynamicLights(scene, pt.get_child("dynamic_lighting"));

	return scene;
}
Beispiel #3
0
void WldModel::readModel(const char* modelId)
{
    WLD* wld    = m_wld;
    Frag14* f14 = nullptr;
    
    for (Fragment* frag : wld->getFragsByType(0x14))
    {
        const char* name = wld->getFragName(frag->nameRef());
        if (strcmp(name, modelId) == 0)
        {
            f14 = (Frag14*)frag;
            break;
        }
    }
    
    if (!f14)
        throw 1; //fixme
    
    // f14 -> f11 -> f10 -> f13 -> f12
    //                  |-> f2d -> f36
    // OR
    // f14 -> f2d -> f36
    
    // Is this an animated model?
    Fragment* frag = wld->getFrag(f14->firstRef());
    
    if (!frag)
        throw 2; //fixme
    
    if (frag->type() == 0x11)
    {
        readAnimatedModel((Frag11*)frag);
        return;
    }
    else if (frag->type() != 0x2d)
    {
        throw 6; //fixme
    }
    
    Frag2d* f2d = (Frag2d*)frag;
    Frag36* f36 = (Frag36*)wld->getFrag(f2d->ref);
    
    if (!f36 || f36->type() != 0x36)
        throw 7; //fixme
    
    readMaterials(f36);
    readMesh(f36);
}
Beispiel #4
0
void readMtlFile(ObjFile* file, const char* line)
{
    /* add the materials of the material file that is identified by line to
    ** our ObjFile.
    */
    
    // if materials have been allocated already free them and replace them
    if (file->materials != NULL)
    {
        free(file->materials);
        file->numMaterials = 0;
    }

    // get the name of the material file from the line
    char name[MAX_STRING_LENGTH];
    int n = sscanf(line, "mtllib %s", name);
    printf("%s\n", name);

    char fullname[MAX_STRING_LENGTH];

    /* if a path was given include it in the full file name */
    if (path == NULL)
    {
        strcpy(fullname, name);
    }
    else
    {
        fullname[0] = '\0';
        strcat(fullname, path);

        int len = strlen(fullname);

        if (fullname[len - 1] != '/')
        {
            fullname[len] = '/';
            fullname[len + 1] = '\0';
        }

        strcat(fullname, name);
    }
    
    // return if name was not found
    if (n != 1) 
    {
        return;
    }

    // open the file
    FILE* f;
    f = fopen(fullname, "r");

    if (f == NULL)
    {
        return;
    }
  
    // go through the file and count the number of material 
    int matCount = countMaterials(f);

    // alloc memory for material int the ObjFile
    file->materials = (ObjMaterial*)malloc(sizeof(ObjMaterial)*(matCount + 1));

    // actually read int the materials
    readMaterials(file, f);    

    // clean up
    fclose(f);
}
//! Reads the next node
void CSceneLoaderIrr::readSceneNode(io::IXMLReader* reader, ISceneNode* parent,
	ISceneUserDataSerializer* userDataSerializer)
{
	if (!reader)
		return;

	scene::ISceneNode* node = 0;

	if (!parent && IRR_XML_FORMAT_SCENE==reader->getNodeName())
		node = SceneManager->getRootSceneNode();
	else if (parent && IRR_XML_FORMAT_NODE==reader->getNodeName())
	{
		// find node type and create it
		core::stringc attrName = reader->getAttributeValue(IRR_XML_FORMAT_NODE_ATTR_TYPE.c_str());

		node = SceneManager->addSceneNode(attrName.c_str(), parent);

		if (!node)
			os::Printer::log("Could not create scene node of unknown type", attrName.c_str());
	}
	else
		node=parent;

	// read attributes
	while(reader->read())
	{
		bool endreached = false;

		const wchar_t* name = reader->getNodeName();

		switch (reader->getNodeType())
		{
		case io::EXN_ELEMENT_END:
			if ((IRR_XML_FORMAT_NODE  == name) ||
				(IRR_XML_FORMAT_SCENE == name))
			{
				endreached = true;
			}
			break;
		case io::EXN_ELEMENT:
			if (IRR_XML_FORMAT_ATTRIBUTES == name)
			{
				// read attributes
				io::IAttributes* attr = FileSystem->createEmptyAttributes(SceneManager->getVideoDriver());
				attr->read(reader, true);

				if (node)
					node->deserializeAttributes(attr);

				attr->drop();
			}
			else
			if (IRR_XML_FORMAT_MATERIALS == name)
				readMaterials(reader, node);
			else
			if (IRR_XML_FORMAT_ANIMATORS == name)
				readAnimators(reader, node);
			else
			if (IRR_XML_FORMAT_USERDATA  == name)
				readUserData(reader, node, userDataSerializer);
			else
			if ((IRR_XML_FORMAT_NODE  == name) ||
				(IRR_XML_FORMAT_SCENE == name))
			{
				readSceneNode(reader, node, userDataSerializer);
			}
			else
			{
				os::Printer::log("Found unknown element in irrlicht scene file",
						core::stringc(name).c_str());
			}
			break;
		default:
			break;
		}

		if (endreached)
			break;
	}
	if (node && userDataSerializer)
		userDataSerializer->OnCreateNode(node);
}