示例#1
0
文件: StlLoader.cpp 项目: jorji/HIVE
/**
 * STLデータのロード
 * @param filename ファイルパス
 * @retval true 成功
 * @retval false 失敗
 */
bool STLLoader::Load(const char* filename){
	Clear();
	SimpleSTLB obj;
	bool r = obj.Load(filename);

    mesh.Create(obj.GetVertexNum(), obj.GetIndexNum());
    Vec3Buffer* pos = mesh.Position();
    Vec3Buffer* normal = mesh.Normal();
    FloatBuffer* mat = mesh.Material();
    UintBuffer* index = mesh.Index();
    Vec2Buffer* texcoord = mesh.Texcoord();

	memcpy(pos->GetBuffer(), obj.GetPositionBuffer(), sizeof(float) * 3 * pos->GetNum());
	normal->Create(obj.GetVertexNum());
	memcpy(normal->GetBuffer(), obj.GetNormalBuffer(), sizeof(float) * 3 * normal->GetNum());
	mat->Create(obj.GetVertexNum());
	memset(mat->GetBuffer(), 0, sizeof(float) * mat->GetNum());
	index->Create(obj.GetIndexNum());
	memcpy(index->GetBuffer(), obj.GetIndex(), sizeof(unsigned int) * index->GetNum());

    
	printf("%d\n", pos->GetNum()     );
	printf("%d\n", normal->GetNum()  );
	printf("%d\n", mat->GetNum()     );
	printf("%d\n", index->GetNum()   );
	return r;
}
示例#2
0
文件: PdbLoader.cpp 项目: jorji/HIVE
/**
 * マテリアル設定
 * @param i 対象index
 * @param matID マテリアルID
 */
void PDBLoader::SetMaterial(int i, float matID) {
    FloatBuffer* mat     = ball.Material();
	if (i < 0 || i >= mat->GetNum()) {
		return;
	}

	mat->GetBuffer()[i] = matID;
}
示例#3
0
文件: PdbLoader.cpp 项目: jorji/HIVE
/**
 * BCMデータのロード
 * @param filename ファイルパス
 * @param generateBond 線primitiveとの接点作成
 * @retval true 成功
 * @retval false 失敗
 */
bool PDBLoader::Load(const char* filename, bool generateBond){
	Clear();

    tinypdb::TinyPDB pdb(filename);
    if (pdb.Parse(/* isBondGenerated = */ generateBond)) {
        fprintf(stderr,"[PDBLoader] PDB parsing failed: %s \n", filename);
        return false;
    }

	m_atoms = pdb.GetAtoms(); // copy

    int numAtoms = static_cast<int>(pdb.GetAtoms().size());

    {
        ball.Create(numAtoms);
        Vec3Buffer*  pos     = ball.Position();
        FloatBuffer* mat     = ball.Material();
        FloatBuffer* radius  = ball.Radius();

        printf("[PDBLoader] # of atoms: %ld\n", numAtoms);

        float* pp = pos->GetBuffer();
        for (size_t i = 0; i < numAtoms; i++) {
            pp[3*i+0] = pdb.GetAtoms()[i].GetX();
            pp[3*i+1] = pdb.GetAtoms()[i].GetY();
            pp[3*i+2] = pdb.GetAtoms()[i].GetZ();
        }

        // @fixme
        float* rad = radius->GetBuffer();
        for (int i = 0; i < numAtoms; ++i) {
            rad[i] = 0.25f;
        }

        // @todo
        memset(mat->GetBuffer(), 0, sizeof(float) * mat->GetNum());
    }


    if (generateBond) {

        // We reprent Bond as line primitives.
        std::vector<float> bondLines;
        for (unsigned int i = 0; i < numAtoms; i++) {

          tinypdb::Atom& atom = pdb.GetAtoms()[i];

          for (unsigned int j = 0; j < atom.GetBonds().size(); j++) {
            const tinypdb::Atom* dst = atom.GetBonds()[j];

            if (dst->Visited()) {
              continue;
            }

            bondLines.push_back(atom.GetX());
            bondLines.push_back(atom.GetY());
            bondLines.push_back(atom.GetZ());

            bondLines.push_back(dst->GetX());
            bondLines.push_back(dst->GetY());
            bondLines.push_back(dst->GetZ());

          }

          atom.SetVisited(true); 

        }

        size_t numBonds = bondLines.size() / 3 / 2;
        size_t numBondVertices = numBonds * 2;

        printf("[PDBLoader] # of bonds: %ld\n", numBonds);

        stick.Create(numBondVertices, /* index num = */0, /* use vrying radius */false);
        Vec3Buffer*  pos     = stick.Position();
        FloatBuffer* mat     = stick.Material();
        //FloatBuffer* radius  = stick.Radius();
        //UintBuffer*  index   = stick.Index();  // not used.

        float* pp = pos->GetBuffer();
        for (size_t i = 0; i < numBondVertices; i++) {
            pp[3*i+0] = bondLines[3*i+0];
            pp[3*i+1] = bondLines[3*i+1];
            pp[3*i+2] = bondLines[3*i+2];
        }

		// Don't use varying radius.
		//float* rad = radius->GetBuffer();
		//for (int i = 0; i < numBondVertices; ++i) {
		//	rad[i] = 1.0f;
		//}

		// @todo
		memset(mat->GetBuffer(), 0, sizeof(float) * mat->GetNum());

	}

	return true;
}