예제 #1
0
파일: form.cpp 프로젝트: jftesser/blobs
void form::exportModel() {
    mExporter.beginModel("blob sim");
    
    addMesh(mMesh);
    addMesh(mOuterMesh);
    
    // doing the edge by hand
    for (int i=1; i<mMasterEdgeParticles.size();i++) {
        ofPoint p0 = mBottomParticles[mMasterEdgeParticles[i-1]->array_ind]->getPosition();
        ofPoint p1 = mBottomParticles[mMasterEdgeParticles[i]->array_ind]->getPosition();
        ofPoint p2 = mParticles[mMasterEdgeParticles[i]->array_ind]->getPosition();
        ofPoint p3 = mParticles[mMasterEdgeParticles[i-1]->array_ind]->getPosition();
        
        mExporter.addTriangle(p0, p1, p2, ofPoint(0,0,0));
        mExporter.addTriangle(p0, p2, p3, ofPoint(0,0,0));
    }
    for (int i=1; i<mSlaveEdgeParticles.size();i++) {
        ofBeginShape();
        ofPoint p0 = mBottomParticles[mSlaveEdgeParticles[i-1]->array_ind]->getPosition();
        ofPoint p1 = mBottomParticles[mSlaveEdgeParticles[i]->array_ind]->getPosition();
        ofPoint p2 = mParticles[mSlaveEdgeParticles[i]->array_ind]->getPosition();
        ofPoint p3 = mParticles[mSlaveEdgeParticles[i-1]->array_ind]->getPosition();
        
        mExporter.addTriangle(p0, p1, p2, ofPoint(0,0,0));
        mExporter.addTriangle(p0, p2, p3, ofPoint(0,0,0));
    }

    
    mExporter.useASCIIFormat(false); //export as binary
    mExporter.saveModel(ofToDataPath("blob-to-print-"+ofGetTimestampString()+".stl"));
}
예제 #2
0
파일: canvas.cpp 프로젝트: Andreas665/qt
Main::Main(QGraphicsScene& c, QWidget* parent, const char* name, Qt::WindowFlags f) :
    Q3MainWindow(parent,name,f),
    canvas(c)
{
    editor = new FigureEditor(canvas,this);
    QMenuBar* menu = menuBar();

    Q3PopupMenu* file = new Q3PopupMenu( menu );
    file->insertItem("&Fill canvas", this, SLOT(init()), Qt::CTRL+Qt::Key_F);
    file->insertItem("&Erase canvas", this, SLOT(clear()), Qt::CTRL+Qt::Key_E);
    file->insertItem("&New view", this, SLOT(newView()), Qt::CTRL+Qt::Key_N);
    file->insertSeparator();
    file->insertItem("&Print...", this, SLOT(print()), Qt::CTRL+Qt::Key_P);
    file->insertSeparator();
    file->insertItem("E&xit", qApp, SLOT(quit()), Qt::CTRL+Qt::Key_Q);
    menu->insertItem("&File", file);

    Q3PopupMenu* edit = new Q3PopupMenu( menu );
    edit->insertItem("Add &Circle", this, SLOT(addCircle()), Qt::ALT+Qt::Key_C);
    edit->insertItem("Add &Hexagon", this, SLOT(addHexagon()), Qt::ALT+Qt::Key_H);
    edit->insertItem("Add &Polygon", this, SLOT(addPolygon()), Qt::ALT+Qt::Key_P);
    edit->insertItem("Add Spl&ine", this, SLOT(addSpline()), Qt::ALT+Qt::Key_I);
    edit->insertItem("Add &Text", this, SLOT(addText()), Qt::ALT+Qt::Key_T);
    edit->insertItem("Add &Line", this, SLOT(addLine()), Qt::ALT+Qt::Key_L);
    edit->insertItem("Add &Rectangle", this, SLOT(addRectangle()), Qt::ALT+Qt::Key_R);
    edit->insertItem("Add &Sprite", this, SLOT(addSprite()), Qt::ALT+Qt::Key_S);
    edit->insertItem("Create &Mesh", this, SLOT(addMesh()), Qt::ALT+Qt::Key_M );
    edit->insertItem("Add &Alpha-blended image", this, SLOT(addButterfly()), Qt::ALT+Qt::Key_A);
    menu->insertItem("&Edit", edit);

    Q3PopupMenu* view = new Q3PopupMenu( menu );
    view->insertItem("&Enlarge", this, SLOT(enlarge()), Qt::SHIFT+Qt::CTRL+Qt::Key_Plus);
    view->insertItem("Shr&ink", this, SLOT(shrink()), Qt::SHIFT+Qt::CTRL+Qt::Key_Minus);
    view->insertSeparator();
    view->insertItem("&Rotate clockwise", this, SLOT(rotateClockwise()), Qt::CTRL+Qt::Key_PageDown);
    view->insertItem("Rotate &counterclockwise", this, SLOT(rotateCounterClockwise()), Qt::CTRL+Qt::Key_PageUp);
    view->insertItem("&Zoom in", this, SLOT(zoomIn()), Qt::CTRL+Qt::Key_Plus);
    view->insertItem("Zoom &out", this, SLOT(zoomOut()), Qt::CTRL+Qt::Key_Minus);
    view->insertItem("Translate left", this, SLOT(moveL()), Qt::CTRL+Qt::Key_Left);
    view->insertItem("Translate right", this, SLOT(moveR()), Qt::CTRL+Qt::Key_Right);
    view->insertItem("Translate up", this, SLOT(moveU()), Qt::CTRL+Qt::Key_Up);
    view->insertItem("Translate down", this, SLOT(moveD()), Qt::CTRL+Qt::Key_Down);
    view->insertItem("&Mirror", this, SLOT(mirror()), Qt::CTRL+Qt::Key_Home);
    menu->insertItem("&View", view);

    menu->insertSeparator();

    Q3PopupMenu* help = new Q3PopupMenu( menu );
    help->insertItem("&About", this, SLOT(help()), Qt::Key_F1);
    help->setItemChecked(dbf_id, TRUE);
    menu->insertItem("&Help",help);

    statusBar();

    setCentralWidget(editor);

    printer = 0;

    init();
}
예제 #3
0
Magic3D::ObjectInstance::ObjectInstance(std::string name) : Object(eOBJECT_INSTANCE, eRENDER_3D, name)
{
    this->instance = NULL;
    this->spawnOnLoad = false;

    box = Box(Vector3(-0.5f, -0.5f, -0.5f), Vector3(0.5f, 0.5f, 0.5f));

    ModelInfo* modelInfo = ResourceManager::getModels()->get(M3D_PLACEHOLDER);

    if (modelInfo)
    {
        std::vector<MeshInfo*>::const_iterator it_m = modelInfo->getMeshes()->begin();
        std::vector<MeshInfo*>::const_iterator it_end = modelInfo->getMeshes()->end();
        while (it_m != it_end)
        {
            MeshInfo* meshInfo = *it_m++;

            Mesh* mesh = new Mesh(meshInfo->getData(), meshInfo->isDoubleSide());

            addMesh(mesh);

            Material* material = meshInfo->getMaterial();
            if (!material)
            {
                material = ResourceManager::getMaterials()->get(M3D_DEFAULT_MATERIAL);
            }
            mesh->addMaterial(material);
        }
    }
}
예제 #4
0
MeshEditor::MeshEditor(SharedResources *shared, Editor *editor,
	QWidget *parent) : QWidget(parent)
{
	this->shared = shared;
	this->editor = editor;
	setFocusPolicy(Qt::StrongFocus);

	QVBoxLayout *columns = new QVBoxLayout(this);
	columns->setSizeConstraint(QLayout::SetMinimumSize);
	columns->setSpacing(0);
	columns->setMargin(0);

	QHBoxLayout *topRow = new QHBoxLayout();
	topRow->setSizeConstraint(QLayout::SetMinimumSize);
	topRow->setSpacing(0);
	topRow->setMargin(0);
	initTopRow(topRow);
	columns->addLayout(topRow);

	meshViewer = new MeshViewer(shared, this);
	columns->addWidget(meshViewer);

	QVBoxLayout *layout = new QVBoxLayout();
	layout->setMargin(10);
	layout->setSpacing(3);
	initFields(layout);
	columns->addLayout(layout);
	columns->addStretch(1);

	connect(this, SIGNAL(meshChanged(pg::Geometry)), meshViewer,
		SLOT(updateMesh(pg::Geometry)));
	connect(meshViewer, SIGNAL(ready()), this, SLOT(addMesh()));
}
예제 #5
0
void ResourceManager::addTextureMaterialGeometryMesh(
    const std::string&                  id,
          resource_group::ResourceGroup resourceGroup,
    const std::string&                  shader,
    const glm::vec4&                    colour,
    const std::string&                  texturePath,
          unsigned                      frameRate,
          bool                          repeat,
          unsigned                      begin,
          unsigned                      end,
    const std::string&                  geometryPath,
          int                           layer,
          unsigned                      textureFlags,
          unsigned                      materialFlags )
{
    // texture
    addTexture(
        id, resourceGroup, texturePath, frameRate,
        repeat, begin, end, textureFlags );
    // material
    addMaterial( id, resourceGroup, shader, colour, id, materialFlags );
    // geometry
    addGeometry( id, resourceGroup, geometryPath );
    // mesh
    addMesh( id, resourceGroup, layer, id, id );
}
예제 #6
0
void CMC_ModelData::loadFromTZW(const char *fileName)
{

    // load All materials
    auto data = tzw::Tfile::getInstance()->getData (fileName,true);
    rapidjson::Document d;
    d.Parse((const char *)data.getBytes ());

    auto& materialsObj= d["materials"];
    for(auto iter = materialsObj.Begin ();iter!=materialsObj.End ();iter++)
    {
        auto& materialObj = *iter;
        auto material = new CMC_Material();
        material->loadFromTZW (materialObj);
        addMaterial (material);
    }

    //load all meshes.
    auto& meshesObj = d["meshes"];
    for(auto iter = meshesObj.Begin ();iter!= meshesObj.End ();iter++)
    {
        auto& meshObj = *iter;
        auto mesh = new CMC_MeshData();
        mesh->loadFromTZW (meshObj);
        addMesh (mesh);
    }
}
예제 #7
0
void
MeshViewController::onSignal(sg_gui::VolumePointSelected& signal) {

	unsigned int x, y, z;
	_labels->getDiscreteCoordinates(
			signal.position().x(),
			signal.position().y(),
			signal.position().z(),
			x, y, z);

	float label = (*_labels)(x, y, z);

	if (label == 0)
		return;

	LOG_DEBUG(meshviewcontrollerlog) << "selected label " << label << std::endl;

	if (_meshes->contains(label)) {

		removeMesh(label);

	} else {

		addMesh(label);
	}

	send<sg_gui::SetMeshes>(_meshes);
}
void EntityGridObject::addChildren(int y, int x, OBJECT_TYPE childType, GridMap * currMap)
{
	EntityGridObject * newChild = new EntityGridObject(childType);
	newChild->m_iIndexX = x;
	newChild->m_iIndexY = y;

	auto childGC = new GraphicsComponent();
	switch (childType)
	{
		case OBJECT_UNDEFINED:
			currMap->getGridMap()[y][x]->setremoveDoor(true);
			currMap->getGridMap()[y][x]->replaceTile(Grid::TILE_FLOOR, BACKGROUND_TILE);
		break;
		
		case OBJECT_BOX:
			break;
		
		case OBJECT_KEY:
			break;
		
		case OBJECT_SWITCH:
			break;
		
		case OBJECT_DOOR:
			newChild->setToggleable(true);
			childGC->addMesh(MeshBuilder::GenerateQuad("Door", Color(1.f, 0.f, 0.f), 32.f));
			childGC->getMesh()->textureArray[0] = LoadTGA("Images//Tiles//tile109.tga");
			newChild->addComponent(childGC);
			currMap->getGridMap()[y][x]->addGridEntity(newChild);
		break;
	}
	this->m_cChildren.push_back(newChild);
}
예제 #9
0
파일: model.cpp 프로젝트: whztt07/Magic3D-2
bool Magic3D::Model::load(ModelInfo* modelInfo)
{
    bool result = false;
    if (modelInfo)
    {
        clearMeshes();
        std::vector<MeshInfo*>::const_iterator it_m = modelInfo->getMeshes()->begin();
        std::vector<MeshInfo*>::const_iterator it_end = modelInfo->getMeshes()->end();
        while (it_m != it_end)
        {
            MeshInfo* meshInfo = *it_m++;

            Mesh* mesh = new Mesh(meshInfo->getData(), meshInfo->isDoubleSide());

            addMesh(mesh);

            Magic3D::Material* material = meshInfo->getMaterial();
            if (!material)
            {
                material = ResourceManager::getMaterials()->get(M3D_DEFAULT_MATERIAL);
            }
            mesh->addMaterial(material);
        }

        if (modelInfo->getSkeleton())
        {
            skeleton->copyFrom(modelInfo->getSkeleton());
        }

        updateBoundingBox();
    }

    return result;
}
예제 #10
0
파일: Icosahedron.cpp 프로젝트: sdp0et/gtp
Icosahedron* Icosahedron::createMesh( MeshType iMeshType, VertexType iVertexType )
{
  Mesh *mesh = new Mesh( this, iMeshType, iVertexType ) ;

  //http://en.wikipedia.org/wiki/Icosahedron
  //(0, ±1, ±φ)
  //(±1, ±φ, 0)
  //(±φ, 0, ±1)
  //where φ = (1 + √5) / 2 

  const real t = ( 1 + sqrt( 5.0 ) ) / 2.0 ;
  // So each side has a length of sqrt( t*t + 1.0 )
  real rScale = r / sqrt( t*t + 1.0 ) ; // correct the radius
  Vector* v = &A ;
  
  for( int i = 0 ; i < 4; i++ )
    //v[ i ] = Vector( 0, -(i&2), -(i&1)*t ) ; 
    v[ i ] = rScale*Vector( 0, i&2?-1:1, i&1?-t:t ) ; 

  for( int i = 4 ; i < 8; i++ )
    //v[ i ] = Vector( -(i&2), -(i&1)*t, 0 ) ; 
    v[ i ] = rScale*Vector( i&2?-1:1, i&1?-t:t, 0 ) ; 

  for( int i = 8 ; i < 12; i++ )
    //v[ i ] = Vector( -(i&1)*t, 0, -(i&2) ) ; 
    v[ i ] = rScale*Vector( i&1?-t:t, 0, i&2?-1:1 ) ; 


  mesh->addTri( v[0], v[2], v[8] ) ;
  mesh->addTri( v[0], v[8], v[4] ) ;
  mesh->addTri( v[0], v[4], v[6] ) ;
  mesh->addTri( v[0], v[6], v[9] ) ;
  mesh->addTri( v[0], v[9], v[2] ) ;

  mesh->addTri( v[2], v[7], v[5] ) ;
  mesh->addTri( v[2], v[5], v[8] ) ;
  mesh->addTri( v[2], v[9], v[7] ) ;
    
  mesh->addTri( v[8], v[5], v[10] ) ;
  mesh->addTri( v[8], v[10], v[4] ) ;
  
  mesh->addTri( v[10], v[5], v[3] ) ;
  mesh->addTri( v[10], v[3], v[1] ) ;
  mesh->addTri( v[10], v[1], v[4] ) ;
  
  mesh->addTri( v[1], v[6], v[4] ) ;
  mesh->addTri( v[1], v[3], v[11] ) ;
  mesh->addTri( v[1], v[11], v[6] ) ;

  mesh->addTri( v[6], v[11], v[9] ) ;

  mesh->addTri( v[11], v[3], v[7] ) ;
  mesh->addTri( v[11], v[7], v[9] ) ;

  mesh->addTri( v[3], v[5], v[7] ) ;

  addMesh( mesh ) ;

  return this ;
}
예제 #11
0
void MeshEditor::initTopRow(QHBoxLayout *topRow)
{
	addButton = new QPushButton("+", this);
	addButton->setFixedHeight(22);
	addButton->setFixedWidth(22);

	removeButton = new QPushButton("-", this);
	removeButton->setFixedHeight(22);
	removeButton->setFixedWidth(22);

	meshBox = new QComboBox(this);
	meshBox->setEditable(true);
	meshBox->setInsertPolicy(QComboBox::NoInsert);
	meshBox->setItemDelegate(new ItemDelegate());

	topRow->addWidget(meshBox);;
	topRow->addWidget(removeButton);
	topRow->addWidget(addButton);
	topRow->setAlignment(Qt::AlignTop);

	connect(meshBox, SIGNAL(editTextChanged(const QString &)), this,
		SLOT(renameMesh(const QString &)));
	connect(addButton, SIGNAL(clicked()), this, SLOT(addMesh()));
	connect(removeButton, SIGNAL(clicked()), this, SLOT(removeMesh()));
	connect(meshBox, SIGNAL(currentIndexChanged(int)), this,
		SLOT(selectMesh()));
}
예제 #12
0
파일: NGLScene.cpp 프로젝트: NCCA/NGL6Demos
void NGLScene::keyPressEvent(QKeyEvent *_event)
{
  // this method is called every time the main window recives a key event.
  // we then switch on the key value and set the camera in the NGLScene
  switch (_event->key())
  {
  // escape key to quite
  case Qt::Key_Escape : QGuiApplication::exit(EXIT_SUCCESS); break;
  // turn on wirframe rendering
  case Qt::Key_W : glPolygonMode(GL_FRONT_AND_BACK,GL_LINE); break;
  // turn off wire frame
  case Qt::Key_S : glPolygonMode(GL_FRONT_AND_BACK,GL_FILL); break;
  // show full screen
  case Qt::Key_F : showFullScreen(); break;
  // show windowed
  case Qt::Key_N : showNormal(); break;
  case Qt::Key_Space : m_car->reset(); break;
  case Qt::Key_X : stepAnimation(); break;
  case Qt::Key_1 : addCube(); break;
  case Qt::Key_2 : addSphere(); break;
  case Qt::Key_3 : addCapsule(); break;
  case Qt::Key_4 : addCylinder(); break;
  case Qt::Key_5 : addCone(); break;
  case Qt::Key_6 : addMesh(TEAPOT); break;
  case Qt::Key_7 : addMesh(APPLE); break;
/*  case Qt::Key_Left : m_physics->addImpulse(ngl::Vec3(-5,0.0f,0.0f)); break;
  case Qt::Key_Right : m_physics->addImpulse(ngl::Vec3(5.0f,0.0f,0.0f)); break;
  case Qt::Key_Up : m_physics->addImpulse(ngl::Vec3(0.0f,5.0f,0.0f)); break;
  case Qt::Key_Down : m_physics->addImpulse(ngl::Vec3(0.0f,-5.0f,0.0f)); break;
*/
  case Qt::Key_Left : m_car->left(); break;
  case Qt::Key_Right : m_car->right(); break;
  case Qt::Key_Up : m_car->accelerate(); break;
  case Qt::Key_Down : m_car->stop(); break;


  case Qt::Key_B : toggleBBox(); break;
  case Qt::Key_R : toggleRandomPlace(); break;
  case Qt::Key_0 : resetSim();  break;

  default : break;
  }
  // finally update the GLWindow and re-draw
  //if (isExposed())
    renderNow();
}
예제 #13
0
void MeshWidget::checkChanged(int b){
	if (b){
		//QMessageBox::about(this, "Adding a mesh", "This is a signal/slot sample with one parameter.");
		emit addMesh(file);
	}
	else{
		emit removeMesh(file);
	}
}
예제 #14
0
SimpleScene::SimpleScene() {
    float3 cameraPosition = float3(12.0f, 3.0f, 0.0f);
    float3 spherePosition = float3(0.0f, 0.0f, 0.0f);

    setCamera(new Camera(cameraPosition, float3(0.0f, 1.75f, 0.0f),
        (float)M_PI / 4.0f, 0.08f * 0, 11.137f));

    auto mesh1 = MeshLoader::load(relToExeDir("content/models/dragon.fbx"));
    addMesh(new MeshInstance(mesh1, spherePosition, float3(0.0f, (float)M_PI / 2.0f * 1.3f, 0.0f), 0.4f));

    auto mesh2 = MeshLoader::load(relToExeDir("content/models/plane.fbx"));
    addMesh(new MeshInstance(mesh2, float3(0.0f, 0.0f, 0.0f), float3(0.0f), 1.0f));

    //addLight(new PointLight(float3(5.0f, 5.0f, 5.0f), 0.3f, 20.0f, true));

    setEnvironmentMap(ImageLoader::load(relToExeDir("content/textures/cubemap.bmp")));
    setEnvironmentMapSampler(new Sampler(Bilinear, Wrap));
}
bool Cterrain::init(const string&heightMapFileName,const Cc3dRect&rect,float heightScale,int quadtreeDepth,
                   Cc3dTexture*texture){
    assert(rect.getWidth()==rect.getHeight());
    m_heightScale=heightScale;
    m_quadtreeDepth=quadtreeDepth;
    m_heightMapFileName=heightMapFileName;
    //生成mesh
    Cc3dMesh*mesh=new Cc3dMesh();
    mesh->init();
    mesh->autorelease();
    addMesh(mesh);
    //读取高程数据--abc
    readLandMat();
    //求高度范围--abc
    float Hmin=c3d_INF;
    float Hmax=-c3d_INF;
    for(int i=0;i<(int)landMat.size();i++){//倒序--abc
        for(int j=0;j<(int)landMat[i].size();j++){//正序--abc
            if(landMat[i][j]>Hmax){
                Hmax=landMat[i][j];
            }
            if(landMat[i][j]<Hmin){
                Hmin=landMat[i][j];
            }
        }
    }//得到Hmin和Hmax
    //设置m_range
    m_range.init(rect.getMinX(), rect.getMaxX(), Hmin, Hmax, rect.getMinY(), rect.getMaxY());
    //计算步长--abc
    int markMatSideLength=pow(2.0,m_quadtreeDepth-1)+1;//do not use 2, should use 2.0, see: http://www.360doc.com/content/11/0826/15/7566064_143451209.shtml
    gridSize=m_range.getSpanX()/(markMatSideLength-1);
    //填充法向数据--abc
    fillNormalMat();
    //markmat开辟空间--abc
    markmat.resize(markMatSideLength);
    for(int i=0;i<(int)markmat.size();i++){
        markmat[i].resize(markMatSideLength);
        for(int j=0;j<(int)markmat[i].size();j++){
            markmat[i][j]=0;
        }
    }
    //制作ground submesh
    Cc3dSubMesh*submesh=new Cc3dSubMesh();
    submesh->autorelease();
    submesh->init();
    submesh->setTexture(texture);
    submesh->getIndexVBO()->genBuffers();
    this->getMesh()->addSubMesh(submesh);
    //make submesh
    makeMesh();
    
 
    return true;
    
}
예제 #16
0
Sprite3D* Sprite3D::createSprite3DNode(NodeData* nodedata,ModelData* modeldata,const MaterialDatas& materialdatas)
{
    auto sprite = new (std::nothrow) Sprite3D();
    if (sprite)
    {
        sprite->setName(nodedata->id);
        auto mesh = Mesh::create(nodedata->id, getMeshIndexData(modeldata->subMeshId));
        if (modeldata->matrialId == "" && materialdatas.materials.size())
        {
            const NTextureData* textureData = materialdatas.materials[0].getTextureData(NTextureData::Usage::Diffuse);
            if (!textureData->filename.empty())
                mesh->setTexture(textureData->filename);
        }
        else
        {
            const NMaterialData*  materialData=materialdatas.getMaterialData(modeldata->matrialId);
            if(materialData)
            {
                const NTextureData* textureData = materialData->getTextureData(NTextureData::Usage::Diffuse);
                if(textureData && !textureData->filename.empty())
                {
                    auto tex = Director::getInstance()->getTextureCache()->addImage(textureData->filename);
                    if(tex)
                    {
                        Texture2D::TexParams texParams;
                        texParams.minFilter = GL_LINEAR;
                        texParams.magFilter = GL_LINEAR;
                        texParams.wrapS = textureData->wrapS;
                        texParams.wrapT = textureData->wrapT;
                        tex->setTexParameters(texParams);
                        mesh->setTexture(tex);
                        mesh->_isTransparent = (materialData->getTextureData(NTextureData::Usage::Transparency) != nullptr);
                    }

                }
            }
        }

        // set locale transform
        Vec3 pos;
        Quaternion qua;
        Vec3 scale;
        nodedata->transform.decompose(&scale, &qua, &pos);
        sprite->setPosition3D(pos);
        sprite->setRotationQuat(qua);
        sprite->setScaleX(scale.x);
        sprite->setScaleY(scale.y);
        sprite->setScaleZ(scale.z);
        
        sprite->addMesh(mesh);
        sprite->autorelease();
        sprite->genGLProgramState(); 
    }
    return   sprite;
}
예제 #17
0
MshTabWidget::MshTabWidget( QWidget* parent /*= 0*/ )
    : QWidget(parent)
{
    setupUi(this);

    connect(this->addMeshPushButton, SIGNAL(clicked()), this->treeView, SLOT(addMesh()));
    connect(this->saveMeshPushButton, SIGNAL(clicked()), this->treeView, SLOT(writeToFile()));
    connect(this->removeMeshPushButton, SIGNAL(clicked()), this->treeView, SLOT(removeMesh()));
    connect(this->treeView, SIGNAL(enableSaveButton(bool)), this, SLOT(enableSaveButton(bool)));
    connect(this->treeView, SIGNAL(enableRemoveButton(bool)), this, SLOT(enableRemoveButton(bool)));
}
예제 #18
0
파일: text.cpp 프로젝트: whztt07/Magic3D-2
Magic3D::Text::Text(std::string name, float size) : Object(eOBJECT_TEXT, eRENDER_3D, name)
{
    setZOrder(true);
    Mesh* textMesh = new Mesh(new TextData("name", size, true), true, true);
    textMesh->setIlluminated(false);
    textMesh->setCastShadows(false);
    textMesh->setReceiveShadows(false);
    addMesh(textMesh);

    textMesh->addMaterial(ResourceManager::getMaterials()->get(M3D_DEFAULT_MATERIAL_FONT));
}
	SkeletalAnimatedObject::SkeletalAnimatedObject(ref<SkinnedMesh> mesh) :
	Spatial(mesh->boundingVolume->clone()),
	animationSet(skeleton),
	skeleton(mesh->skeleton),
	jointSpatials(new Spatial*[mesh->skeleton->numJoints])
	{
		skeletonPoseBuffer = new matrix4f[skeleton->numJoints];
		for (uint i = 0; i < skeleton->numJoints; ++i)
			jointSpatials[i] = NULL;
		addMesh(mesh);
	}
/** \Returns Returns an array of ID numbers */
core::array<s32> CBatchingMesh::addMesh(IMesh* mesh, core::vector3df pos, core::vector3df rot, core::vector3df scale)
{
	core::matrix4 m;
	m.setRotationDegrees(rot);
	m.setTranslation(pos);

	core::matrix4 scalem;
	scalem.setScale(scale);
	m *= scalem;

	return addMesh(mesh, m);
}
예제 #21
0
void MeshDecimationApp::initUpdate()
{
    Input::subscribe(this);

    m_modelCamera.setPerspective(45.0f, float(Screen::getWidth()), float(Screen::getHeight()), 0.3f, 100.0f);
    m_modelCamera.setViewport(0.0f, 0.0f, float(Screen::getWidth()), float(Screen::getHeight()));
    m_modelCamera.setPosition(glm::vec3(0.0f, 0.0f, -1.25f));
    m_modelCamera.lookAt(glm::vec3(0.0f));

    m_engine->registerCamera(&m_modelCamera);

    m_shader.load("assets/shaders/lit.vert", "assets/shaders/lit.frag", { "in_pos", "in_normal" });

    addMesh("assets/meshes/Sphere.obj", "Sphere");
    addMesh("assets/meshes/bunny.obj", "Stanford Bunny");
    m_curLoadingMesh = *m_meshes[m_curLoadingMeshIdx].originalEdgeMesh;

    glEnable(GL_SCISSOR_TEST);

    m_initializing = false;
}
예제 #22
0
void PolylineStyleBuilder<V>::addFeature(const Feature& _feat, const DrawRule& _rule) {

    if (_feat.geometryType == GeometryType::points) { return; }
    if (!checkRule(_rule)) { return; }

    Parameters params = parseRule(_rule, _feat.props);

    if (params.fill.width[0] <= 0.0f && params.fill.width[1] <= 0.0f ) { return; }

    if (_feat.geometryType == GeometryType::lines) {
        // Line geometries are never clipped to tiles, so keep all segments
        params.keepTileEdges = true;

        for (auto& line : _feat.lines) {
            addMesh(line, params);
        }
    } else {
        for (auto& polygon : _feat.polygons) {
            for (const auto& line : polygon) {
                addMesh(line, params);
            }
        }
    }
}
예제 #23
0
void ResourceManager::addMaterialGeometryMesh(
    const std::string&                  id,
          resource_group::ResourceGroup resourceGroup,
    const std::string&                  shader,
    const glm::vec4&                    colour,
    const std::string&                  geometryPath,
          int                           layer,
          unsigned                      materialFlags )
{
    // material
    addMaterial( id, resourceGroup, shader, colour, materialFlags );
    // geometry
    addGeometry( id, resourceGroup, geometryPath );
    // mesh
    addMesh( id, resourceGroup, layer, id, id );
}
예제 #24
0
/*! 
Constructor with a mesh pointer and name.
*/ 
SLNode::SLNode(SLMesh* mesh, SLstring name) : SLObject(name)
{  
    _stateGL = SLGLState::getInstance();
    _parent = 0;
    _depth = 1;
    _om.identity();
    _wm.identity();
    _wmI.identity();
    _wmN.identity();
    _drawBits.allOff();
    _animation = 0;
    _isWMUpToDate = false;
    _isAABBUpToDate = false;
    
    addMesh(mesh);
}
예제 #25
0
void MeshEditor::addMesh()
{
	pg::Geometry geom;
	std::string name;
	QString qname;

	for (int i = 1; true; i++) {
		name = "Mesh " + std::to_string(i);
		qname = QString::fromStdString(name);
		if (meshBox->findText(qname) == -1)
			break;
	}

	geom.setName(name);
	geom.setPlane();
	addMesh(geom);
}
예제 #26
0
Sprite3D* Sprite3D::createSprite3DNode(NodeData* nodedata,ModelData* modeldata,const MaterialDatas& matrialdatas)
{
    auto sprite = new (std::nothrow) Sprite3D();
    if (sprite)
    {
        sprite->setName(nodedata->id);
        auto mesh = Mesh::create(nodedata->id, getMeshIndexData(modeldata->subMeshId));
        if (modeldata->matrialId == "" && matrialdatas.materials.size())
        {
            const NTextureData* textureData = matrialdatas.materials[0].getTextureData(NTextureData::Usage::Diffuse);
            if (!textureData->filename.empty())
                mesh->setTexture(textureData->filename);
        }
        else
        {
            const NMaterialData*  materialData=matrialdatas.getMaterialData(modeldata->matrialId);
            if(materialData)
            {
                const NTextureData* textureData = materialData->getTextureData(NTextureData::Usage::Diffuse);
                if(textureData && !textureData->filename.empty())
                {
                    auto tex = Director::getInstance()->getTextureCache()->addImage(textureData->filename);
                    if(tex)
                    {
                        Texture2D::TexParams    texParams;
                        texParams.minFilter = GL_LINEAR;
                        texParams.magFilter = GL_LINEAR;
                        texParams.wrapS = textureData->wrapS;
                        texParams.wrapT = textureData->wrapT;
                        tex->setTexParameters(texParams);
                        mesh->setTexture(tex);
                        mesh->_isTransparent = (materialData->getTextureData(NTextureData::Usage::Transparency) != nullptr);
                    }

                }
            }
        }
        sprite->setAdditionalTransform(&nodedata->transform);
        sprite->addMesh(mesh);
        sprite->autorelease();
        sprite->genGLProgramState(); 
    }
    return   sprite;
}
예제 #27
0
void CSkelModel::load(const std::string &n, CVirtualFS *vfs){
    setName(n);

    CFileText f(n);
    vfs->readFile(f);

	string buffer = (char*)f.getData();
    
    CTokenizerNoComments tokenizer(buffer);

    string path;
    bool skeletonLoaded = false;
    while(tokenizer.nextToken()){
        const string key = tokenizer.lowerCase(tokenizer.getToken());
        tokenizer.nextToken();
        const string value = tokenizer.getToken();
        if(key == "path"){
            path = value;
            if(path[path.size()-1] != '/')
                path += '/';
        } else if(key == "skeleton"){
            setSkeleton(mManager->registerSkeleton(path + value));
            skeletonLoaded = true;
        } else if(key == "mesh"){
            if(!skeletonLoaded)
                throw CException("Failed because no skeleton active");
            addMesh(mManager->registerMesh(path + value));
        } else if(key == "animation"){
            if(!skeletonLoaded)
                throw CException("Failed because no skeleton active");
			tokenizer.nextToken();
			string alias = tokenizer.getToken();
			if (alias == "-"){
				alias = value;
			}
            addSkelAnimation(mManager->registerSkelAnimation(path + value), alias);
        } else if(key == "material"){
            mMeshes.back()->addShader(CEngine::getSingleton()->mMaterials.registerMaterial(path + value));      
			//addShader(mManager->registerShader(path + value));
        }
    }

    CResource::load(); // Mark us loaded
}
예제 #28
0
void ResourceManager::addTextureMaterialGeometryMesh(
    const std::string&                  id,
          resource_group::ResourceGroup resourceGroup,
    const std::string&                  shader,
    const std::string&                  texturePath,
    const std::string&                  geometryPath,
          int                           layer,
          unsigned                      textureFlags,
          unsigned                      materialFlags )
{
    // texture
    addTexture( id, resourceGroup, texturePath, textureFlags );
    // material
    addMaterial( id, resourceGroup, shader, id, materialFlags );
    // geometry
    addGeometry( id, resourceGroup, geometryPath );
    // mesh
    addMesh( id, resourceGroup, layer, id, id );
}
예제 #29
0
void MainWindow::addCurrentMesh()
{

    mat topology(2, ENS_DIM);

    try{
        for (int i = 0; i < 2; ++i) {
            for (int j = 0; j < ENS_DIM; ++j) {
                topology(j, i) = boost::lexical_cast<double>(ui->tableWidget_mesh->item(j, i)->text().toStdString());
            }
        }
    }
    catch (std::exception & e) {
        warning(e.what() + (std::string)"  |  invalid topology numbers." );
        return;
    }

    std::string name = ui->lineEdit->text().toStdString();

    for (MeshField* mf : meshFields) {
        if (mf->description.compare(name) == 0){
            warning("A mesh with an equal name already exists.");
            return;
        }
    }

    MeshField* meshField = new MeshField(topology, *ensemble, name);
    MeshField* currentMesh = meshFields.at(ui->meshComboBox->currentIndex());

    try {
        addMesh(meshField, currentMesh);
    }
    catch (std::exception & e) {
        warning(e.what() + (std::string)"  |  invalid mesh topology.");
        return;
    }



}
예제 #30
0
	void MeshMergeTool::doInvoke(const OptionList& toolOptions,
			const Ogre::StringVector& inFileNames,
			const Ogre::StringVector& outFileNames)
	{
		if (outFileNames.size() != 1)
		{
			fail("Exactly one output file must be specified.");
			return;
		}
		else if (inFileNames.size() == 0)
		{
			fail("No input files specified.");
			return;
		}

		StatefulMeshSerializer* meshSer = OgreEnvironment::getSingleton().getMeshSerializer();
		StatefulSkeletonSerializer* skelSer =
			OgreEnvironment::getSingleton().getSkeletonSerializer();
		for (Ogre::StringVector::const_iterator it = inFileNames.begin();
			it != inFileNames.end(); ++it)
		{
			MeshPtr curMesh = meshSer->loadMesh(*it);
			if (!curMesh.isNull())
			{
				if (curMesh->hasSkeleton() && SkeletonManager::getSingleton().getByName(
					curMesh->getSkeletonName()).isNull())
				{
					skelSer->loadSkeleton(curMesh->getSkeletonName());
				}
				addMesh(curMesh);
			}
			else
			{
				warn("Skipped: Mesh " + *it + " cannnot be loaded.");
			}
		}
		Ogre::String outputfile = *outFileNames.begin();
		meshSer->exportMesh(merge(outputfile).getPointer(), outputfile);
	}