Exemple #1
0
EditData& TFlyObjectEdit::createActor( char const* name , unsigned modelID )
{
	EditData data;
	data.flag |= EF_SAVE_XFORM | EF_CREATE;

	TCamera& cam = m_game->getCamControl();

	Vec3D pos = cam.getCameraPos() + 500 * cam.getViewDir();

	XForm trans;
	trans.setIdentity();

	TActor* entity = new TActor( modelID ,trans );
	data.type = EOT_TNPC;
	m_curLevel->addEntity( entity );
	data.flag |= EF_LOAD_MODEL;

	FnObject obj;
	obj.Object(  entity->getFlyActor().GetBaseObject() );

	obj.SetPosition( pos );
	obj.SetDirection( Vec3D(1,0,0) , Vec3D(0,0,1) );
	obj.SetName( (char*) name );
	entity->getFlyActor().SetName((char*) name);

	data.id     = obj.Object();
	data.entity = entity;

	g_editDataVec.push_back( data );

	return g_editDataVec.back();

}
Exemple #2
0
 void polygonize(const XForm& xform, const RGrid<float>& grid, std::vector<CGLA::Vec3d>& quad_vertices, float tau)
 {
     quad_vertices.clear();
     for(int i=0;i<xform.get_dims()[0];++i)
         for(int j=0;j<xform.get_dims()[1];++j)
             for(int k=0;k<xform.get_dims()[2];++k)
             {
                 Vec3i vox(i,j,k);
                 if(grid[vox] <= tau)
                 {
                     if(grid.in_domain(Vec3i(i+1,j,k)) && grid[Vec3i(i+1,j,k)] > tau)
                         for(int n=0;n<4;++n)
                             quad_vertices.push_back(xform.inverse(Vec3d(i+0.5, j,k) + xpf[n]));
                     if(grid.in_domain(Vec3i(i-1,j,k)) && grid[Vec3i(i-1,j,k)] > tau)
                         for(int n=0;n<4;++n)
                             quad_vertices.push_back(xform.inverse(Vec3d(i-0.5, j,k) + xmf[n]));
                     if(grid.in_domain(Vec3i(i,j+1,k)) && grid[Vec3i(i,j+1,k)] > tau)
                         for(int n=0;n<4;++n)
                             quad_vertices.push_back(xform.inverse(Vec3d(i, j+0.5,k) + ypf[n]));
                     if(grid.in_domain(Vec3i(i,j-1,k)) && grid[Vec3i(i,j-1,k)] > tau)
                         for(int n=0;n<4;++n)
                             quad_vertices.push_back(xform.inverse(Vec3d(i, j-0.5,k) + ymf[n]));
                     if(grid.in_domain(Vec3i(i,j,k+1)) && grid[Vec3i(i,j,k+1)] > tau)
                         for(int n=0;n<4;++n)
                             quad_vertices.push_back(xform.inverse(Vec3d(i, j,k+0.5) + zpf[n]));
                     if(grid.in_domain(Vec3i(i,j,k-1)) && grid[Vec3i(i,j,k-1)] > tau)
                         for(int n=0;n<4;++n)
                             quad_vertices.push_back(xform.inverse(Vec3d(i, j,k-0.5) + zmf[n]));
                     
                 }
             }
     
 }
Exemple #3
0
TChestTrigger::TChestTrigger() :TBoxTrigger( Vec3D( 100 , 100 , 100 ) )
	,m_items( new TItemStorage(MaxItemNum) )
{
	m_DTime = 0.0f;

	OBJECTid objID = TResManager::instance().cloneModel( "bag" , true );

	modelObj.Object( objID );
	float scale = 20;
	modelObj.Scale( scale , scale , scale , LOCAL  );
	modelObj.Rotate( X_AXIS , 90 , LOCAL );
	modelObj.XForm();

	XForm trans;
	trans.setIdentity();
	TObjMotionState* motionState = new TObjMotionState( trans , objID );
	setMotionState( motionState );
}
Exemple #4
0
	void load(EditData& data , TLevel* level )
	{
		FnScene& scene = level->getFlyScene();
		data.type  = type;
		data.flag  = flag;

		switch( data.type )
		{
		case EOT_TOBJECT:
			if  ( data.flag & EF_LOAD_MODEL )
			{
				TObject* tObj = new TObject( modelID );
				level->addEntity( tObj );
				data.id = tObj->getFlyObj().Object();
				data.entity = tObj;
			}
			break;
		case EOT_TNPC:
			{
				XForm trans; trans.setIdentity();
				TActor* actor = new TActor(  modelID , trans );
				level->addEntity( actor );
				data.id = actor->getFlyActor().GetBaseObject();
				data.entity = actor;
			}
			break;
		case EOT_TERRAIN:
		case EOT_FLY_OBJ:
		case EOT_OTHER:
			data.id = scene.GetObjectByName( (char*) name.c_str() );
			break;
		}

		FnObject obj; obj.Object( data.id );
		obj.SetName( (char*) name.c_str() );

		if ( data.flag & EF_SAVE_XFORM )
		{
			obj.SetWorldPosition( pos );
			obj.SetWorldDirection( front , up );
		}
	}
bool load_frame( int frame_num, bool &stop ){

	int n_meshes = meshes.size();
	int n_obs = obstacles.size();

	// Winding order matters for whatever is reading in the abc file.
	bool ccw_output = false;

	std::string framestr = pad_leading_zeros(6,frame_num);

	// Load all deforming meshes
	for( int m=0; m<n_meshes; ++m ){
		std::string meshstr = pad_leading_zeros(2,m);
		std::string objfile = dir + framestr + '_' + meshstr + ".obj";

		// If the file doesn't exists, we have reached the end of the sim
		if( !file_exists(objfile) ){ 
			stop = true;
			break;
		}

		// Load the deforming mesh
		TriangleMesh *mesh = meshes[m].get();
		if( !meshio::load_obj( mesh, objfile, false, false, false ) ){
			std::cerr << "\n**arcsimeToAlembic Error: Failed to load " << objfile << "\n" << std::endl;
			return false;
		}
		mesh->need_normals();

		// Add it to the exporter
		exporter.add_frame( deform_handles[m], &mesh->vertices[0][0], mesh->vertices.size(),
			&mesh->faces[0][0], mesh->faces.size(), ccw_output );

	} // end loop meshes

	// Load all obstacle transforms
	for( int o=0; o<n_obs && !stop; ++o ){
		std::string meshstr = pad_leading_zeros(2,o);
		std::string xformfile = dir + framestr + "obs" + meshstr + ".txt";
		pugi::xml_document doc;
		pugi::xml_parse_result result = doc.load_file(xformfile.c_str());
		if( !result ){
			std::cerr << "\n**arcsimeToAlembic Error: Unable to load " << xformfile << std::endl;
			return false;
		}

		TriangleMesh *mesh = obstacles[o].get();
		Eigen::AlignedBox<float,3> aabb = obs_aabb[o];
		Vec3f obs_center = aabb.center();

		pugi::xml_node::iterator node_iter = doc.first_child();
		for( ; node_iter != doc.end(); node_iter++ ){
			pugi::xml_node curr_node = *node_iter;
			std::string name = curr_node.name();
			XForm<float> xf; xf.setIdentity();
			if( name == "rotate" ){
				float angle = curr_node.attribute("angle").as_float() * (180.f/M_PI);
				float x = curr_node.attribute("x").as_float();
				float y = curr_node.attribute("y").as_float();
				float z = curr_node.attribute("z").as_float();

				// Translate obs to origin before rotation
				XForm<float> xf0 = xform::make_trans<float>(-obs_center);
				XForm<float> xf1 = xform::make_rot<float>( angle, Vec3f(x,y,z) );
				XForm<float> xf2 = xform::make_trans<float>(obs_center);
				xf = xf2 * xf1 * xf0;
			}
			else if( name == "scale" ){
				float s = curr_node.attribute("value").as_float();
				xf = xform::make_scale<float>(s,s,s);
			}
			else if( name == "translate" ){
				float x = curr_node.attribute("x").as_float();
				float y = curr_node.attribute("y").as_float();
				float z = curr_node.attribute("z").as_float();
				xf = xform::make_trans<float>(x,y,z);
			}
			mesh->apply_xform(xf);
		} // end load xform

		// Add it to the exporter
		exporter.add_frame( obs_handles[o], &mesh->vertices[0][0], mesh->vertices.size(),
			&mesh->faces[0][0], mesh->faces.size(), ccw_output );

	} // end loop obstacles

	return true;
}
Exemple #6
0
void XMLSchema::writeXml(xmlTextWriterPtr w) const
{
    int pos = 0;
    for (auto di = m_dims.begin(); di != m_dims.end(); ++di, ++pos)
    {
        xmlTextWriterStartElementNS(w, (const xmlChar*)"pc",
            (const xmlChar*)"dimension", NULL);

        std::ostringstream position;
        position << (pos + 1);
        xmlTextWriterWriteElementNS(w, (const xmlChar*)"pc",
            (const xmlChar*)"position", NULL,
            (const xmlChar*)position.str().c_str());

        std::ostringstream size;
        size << Dimension::size(di->m_dimType.m_type);
        xmlTextWriterWriteElementNS(w, (const xmlChar*)"pc",
            (const xmlChar*)"size", NULL, (const xmlChar*)size.str().c_str());

        std::string description = Dimension::description(di->m_dimType.m_id);
        if (description.size())
            xmlTextWriterWriteElementNS(w, (const xmlChar*)"pc",
                (const xmlChar*)"description", NULL,
                (const xmlChar*)description.c_str());

        XForm xform = di->m_dimType.m_xform;
        if (xform.nonstandard())
        {
            std::ostringstream out;
            out.precision(15);

            out << xform.m_scale.m_val;
            std::string scale = out.str();

            out.str(std::string());
            out << xform.m_offset.m_val;
            std::string offset = out.str();

            out << xform.m_scale.m_val;
            xmlTextWriterWriteElementNS(w, (const xmlChar*)"pc",
                (const xmlChar *)"scale", NULL,
                (const xmlChar *)scale.data());
            xmlTextWriterWriteElementNS(w, (const xmlChar*)"pc",
                (const xmlChar *)"offset", NULL,
                (const xmlChar *)offset.data());
        }

        std::string name = di->m_name;
        if (name.size())
            xmlTextWriterWriteElementNS(w, (const xmlChar*)"pc",
                (const xmlChar*)"name", NULL, (const xmlChar*)name.c_str());

        xmlTextWriterWriteElementNS(w, (const xmlChar*)"pc",
            (const xmlChar*)"interpretation", NULL,
            (const xmlChar*)
                Dimension::interpretationName(di->m_dimType.m_type).c_str());

        xmlTextWriterWriteElementNS(w, (const xmlChar*)"pc",
            (const xmlChar*)"active", NULL, (const xmlChar*)"true");

        xmlTextWriterEndElement(w);
        xmlTextWriterFlush(w);
    }
    std::ostringstream orientation;
    if (m_orientation == Orientation::PointMajor)
        orientation << "point";
    if (m_orientation == Orientation::DimensionMajor)
        orientation << "dimension";
    if (!m_metadata.empty())
    {
        addMetadataEntry(w, m_metadata);
    }
    xmlTextWriterWriteElementNS(w, (const xmlChar*) "pc",
        (const xmlChar*)"orientation", NULL,
        (const xmlChar*)orientation.str().c_str());

    xmlTextWriterWriteElementNS(w, (const xmlChar*)"pc",
        (const xmlChar*)"version", NULL,
        (const xmlChar*)PDAL_XML_SCHEMA_VERSION);

    xmlTextWriterEndElement(w);
    xmlTextWriterFlush(w);
}