bool  MeshModel::loadOFF(std::ifstream& infile)
{
	std::string temp;
	infile >> temp;
	unsigned int numVertices,numFaces;
	infile >> numVertices >> numFaces >> temp;

	if (infile.eof())
		return false;

	vertices.resize(numVertices);
	double z;

	for (unsigned int i = 0; i < numVertices; i++) {
		if (infile.eof()) return false;
		infile >> vertices[i].x >> vertices[i].y >> z;
	}


	int three;
	faces->resize(numFaces);

	for (unsigned int i = 0; i < numFaces; i++) {
		if (infile.eof()) return false;
		infile >> three >> (*faces)[i][0] >> (*faces)[i][1] >> (*faces)[i][2];
	}

	identityTexCoords();
	return updateMeshInfo();
}
Ejemplo n.º 2
0
void
Mesh::setSupportedInterleavedAttribute(unsigned attribute, bool state)
{
  _supportedInterleavedComponents.setFlag(attribute, state);

  updateMeshInfo();
}
Ejemplo n.º 3
0
void
PrototypeLayer::clear()
{
  mFileName = "";
  mPrototype->clear();
  updateMeshInfo();
  mIconImage->markDirty();
}
Ejemplo n.º 4
0
void cubiverse::VoxelEditor::updateMesh(int group) {
	updateMeshInfo(group);
	meshs[group]->updateMesh();
}
Ejemplo n.º 5
0
void
PrototypeLayer::actionPerformed(Widget* source)
{
  if(source == mNewPrototypeButton) {
    clear();
  }
  else if(source == mLoadPrototypeButton) {
    string fileName;
    if(rPlatform()->openFileDialog(fileName)) {
      mFileName = fileName;

      // Raw load to get around CacheManager.
      ifstream inFile(mFileName.c_str(), ios_base::in | ios_base::binary);
      inFile.seekg(0, ios::end);
      streampos fileSize = inFile.tellg();
      inFile.seekg(0, ios::beg);

      char* data = new char[fileSize];
      inFile.read(data, fileSize);
      ChunkData* chunkData = new ChunkData(data, fileSize);
      mPrototype->load(chunkData, true);
      delete chunkData;
      delete[] data;
      inFile.close();
      
      // Force recalculation of collision data and similar
      mPrototype->getMesh()->flush();
      
      updateMeshInfo();
      mIconImage->markDirty();
    }
  }
  else if(source == mSavePrototypeButton && mFileName != "") {
    ChunkStream cStream(mFileName);
    mPrototype->save(&cStream);
    cStream.close();
    updateMeshInfo();
  }
  else if(source == mSaveAsPrototypeButton || source == mSavePrototypeButton) {
    string fileName;
    if(rPlatform()->saveFileDialog(fileName)) {
      mFileName = fileName;
      ChunkStream cStream(mFileName);
      mPrototype->save(&cStream);
      cStream.close();
      updateMeshInfo();
    }
  }
  else if(source == mImportOBJButton) {
    string fileName;
    if(rPlatform()->openFileDialog(fileName)) {
      mPrototype->getMesh()->loadFromOBJ(fileName);
      updateMeshInfo();
    }
  }
  else if(source == mImportSSMButton) {
    string fileName;
    if(rPlatform()->openFileDialog(fileName)) {
      mPrototype->getMesh()->loadFromSSM(fileName);
      updateMeshInfo();
    }    
  }
  else if(source == mImportTGAButton) {
    string fileName;
    if(rPlatform()->openFileDialog(fileName)) {
      mPrototype->getColorTexture()->loadFromTGA(fileName);
      updateMeshInfo();
    }
  }  
  else if(source == mImportPNGButton) {
    string fileName;
    if(rPlatform()->openFileDialog(fileName)) {
      mPrototype->getColorTexture()->loadFromPNG(fileName);    
      updateMeshInfo();
    }
  }  
  else if(source == mImportIconButton) {
    string fileName;
    if(rPlatform()->openFileDialog(fileName)) {
      mPrototype->getIconSurface128()->loadFromPNG(fileName);    
      mPrototype->updateIcons();
      mIconImage->markDirty();
    }
  }  
  else if(source == mToggleNormalsButton) {
    mRenderNormals = !mRenderNormals;
  }
  else if(source == mToggleTextureButton) {
    mRenderTexture = !mRenderTexture;
  }
  else if(source == mToggleWireframeButton) {
    mRenderWireframe = !mRenderWireframe;
  }
  else if(source == mQuitButton) {
    rMain()->quitApplication();
  }

  // ----------------------------------------
  // Port controls

  PortList& ports = mPrototype->getPorts();

  if(source == mPortNextButton) {
    mCurrentPort = clamp<int>(mCurrentPort + 1, 0, ports.size());
  }
  else if(source == mPortPrevButton) {
    mCurrentPort = clamp<int>(mCurrentPort - 1, 0, ports.size());
  }  
  else if(source == mPortAddButton) {
    Port* newPort = new Port();
    mPrototype->addPort(newPort);
    mCurrentPort = ports.size() - 1;
  }
  else if(source == mPortRemoveButton && 0 != ports.size()) {
    ports.erase(ports.begin() + mCurrentPort);
    mCurrentPort = clamp<int>(mCurrentPort, 0, ports.size());    
  }
  

  // ----------------------------------------
  // Movement and Rotate
  if(0 == ports.size()) return;

  float deltaMove = 1;
  if(rGUIManager()->getKeyModifier() & KEY_MODIFIER_SHIFT)
    deltaMove = 0.1;
  if(rGUIManager()->getKeyModifier() & KEY_MODIFIER_CONTROL)
    deltaMove = 0.01;
 
  Vector& position = ports[mCurrentPort]->getPosition();
  if(source == mPortMovXAddButton) {
    position.x += deltaMove;
  }
  else if(source == mPortMovXSubButton) {
    position.x -= deltaMove;
  }
  else if(source == mPortMovYAddButton) {
    position.y += deltaMove;
  }
  else if(source == mPortMovYSubButton) {
    position.y -= deltaMove;
  }
  else if(source == mPortMovZAddButton) {
    position.z += deltaMove;
  }
  else if(source == mPortMovZSubButton) {
    position.z -= deltaMove;
  }

  Degree deltaRot = 45;
  if(rGUIManager()->getKeyModifier() & KEY_MODIFIER_SHIFT)
    deltaRot = 45 / 4;
  if(rGUIManager()->getKeyModifier() & KEY_MODIFIER_CONTROL)
    deltaRot = 45 / 16;

  Quaternion& orientation = ports[mCurrentPort]->getOrientation();
  if(source == mPortRotXAddButton) {
    orientation = orientation * Quaternion(Vector::UNIT_X, deltaRot);
  }
  else if(source == mPortRotXSubButton) {
    orientation = orientation * Quaternion(Vector::UNIT_X, -deltaRot);
  }  
  else if(source == mPortRotYAddButton) {
    orientation = orientation * Quaternion(Vector::UNIT_Y, deltaRot);
  }  
  else if(source == mPortRotYSubButton) {
    orientation = orientation * Quaternion(Vector::UNIT_Y, -deltaRot);
  }  
  else if(source == mPortRotZAddButton) {
    orientation = orientation * Quaternion(Vector::UNIT_Z, deltaRot);
  }  
  else if(source == mPortRotZSubButton) {
    orientation = orientation * Quaternion(Vector::UNIT_Z, -deltaRot);
  }  
}