コード例 #1
0
ファイル: Input.cpp プロジェクト: u-engine/chihuahua
//-------------------------------------------------------------------------------
// handle mouse input for the light rotation
//
// Axes: global x/y axis
//-------------------------------------------------------------------------------
void HandleMouseInputLightRotate( void )
	{
	POINT mousePos;
	GetCursorPos( &mousePos );
	ScreenToClient( GetDlgItem(g_hDlg,IDC_RT), &mousePos );

	g_mousePos.x = mousePos.x;
	g_mousePos.y = mousePos.y;

	if (g_bMousePressedR)
		{
		int nXDiff = -(g_mousePos.x - g_LastmousePos.x);
		int nYDiff = -(g_mousePos.y - g_LastmousePos.y);

		aiVector3D v = aiVector3D(1.0f,0.0f,0.0f);
		aiMatrix4x4 mTemp;
		D3DXMatrixRotationAxis( (D3DXMATRIX*) &mTemp, (D3DXVECTOR3*)&v, D3DXToRadian((float)nYDiff / 2.0f));
		D3DXVec3TransformCoord((D3DXVECTOR3*)&g_avLightDirs[0],
			(const D3DXVECTOR3*)&g_avLightDirs[0],(const D3DXMATRIX*)&mTemp);

		v = aiVector3D(0.0f,1.0f,0.0f);
		D3DXMatrixRotationAxis( (D3DXMATRIX*) &mTemp, (D3DXVECTOR3*)&v, D3DXToRadian((float)nXDiff / 2.0f));
		D3DXVec3TransformCoord((D3DXVECTOR3*)&g_avLightDirs[0],
			(const D3DXVECTOR3*)&g_avLightDirs[0],(const D3DXMATRIX*)&mTemp);
		}
	return;
	}
コード例 #2
0
ファイル: ObjFileParser.cpp プロジェクト: RSATom/Qt
// -------------------------------------------------------------------
//  Get values for two 3D vectors on the same line
void ObjFileParser::getTwoVectors3( std::vector<aiVector3D> &point3d_array_a, std::vector<aiVector3D> &point3d_array_b ) {
    float x, y, z;
    copyNextWord(m_buffer, Buffersize);
    x = (float) fast_atof(m_buffer);

    copyNextWord(m_buffer, Buffersize);
    y = (float) fast_atof(m_buffer);

    copyNextWord( m_buffer, Buffersize );
    z = ( float ) fast_atof( m_buffer );

    point3d_array_a.push_back( aiVector3D( x, y, z ) );

    copyNextWord(m_buffer, Buffersize);
    x = (float) fast_atof(m_buffer);

    copyNextWord(m_buffer, Buffersize);
    y = (float) fast_atof(m_buffer);

    copyNextWord( m_buffer, Buffersize );
    z = ( float ) fast_atof( m_buffer );

    point3d_array_b.push_back( aiVector3D( x, y, z ) );

    m_DataIt = skipLine<DataArrayIt>( m_DataIt, m_DataItEnd, m_uiLine );
}
コード例 #3
0
ファイル: StandardShapes.cpp プロジェクト: 304471720/spring
// ------------------------------------------------------------------------------------------------
// Build a circle
void StandardShapes::MakeCircle(float radius, unsigned int tess,
	std::vector<aiVector3D>& positions)
{
	// Sorry, a circle with less than 3 segments makes ABSOLUTELY NO SENSE
	if (tess < 3 || !radius)
		return;

	radius = math::fabs(radius);

	// We will need 3 vertices per segment 
	positions.reserve(positions.size()+tess*3);

	const float angle_delta = (float)AI_MATH_TWO_PI / tess;
	const float angle_max   = (float)AI_MATH_TWO_PI;

	float s = 1.f; // cos(angle == 0);
	float t = 0.f; // sin(angle == 0);

	for (float angle = 0.f; angle < angle_max;  )
	{
		positions.push_back(aiVector3D(s * radius,0.f,t * radius));
		angle += angle_delta;
		s = math::cos(angle);
		t = math::sin(angle);
		positions.push_back(aiVector3D(s * radius,0.f,t * radius));

		positions.push_back(aiVector3D(0.f,0.f,0.f));
	}
}
コード例 #4
0
void ofxAssimpModelLoader::updateBones() {
    // update mesh position for the animation
	for(unsigned int i=0; i<modelMeshes.size(); ++i) {
		// current mesh we are introspecting
		const aiMesh* mesh = modelMeshes[i].mesh;
        
		// calculate bone matrices
		vector<aiMatrix4x4> boneMatrices(mesh->mNumBones);
		for(unsigned int a=0; a<mesh->mNumBones; ++a) {
			const aiBone* bone = mesh->mBones[a];
            
			// find the corresponding node by again looking recursively through the node hierarchy for the same name
			aiNode* node = scene->mRootNode->FindNode(bone->mName);
            
			// start with the mesh-to-bone matrix
			boneMatrices[a] = bone->mOffsetMatrix;
			// and now append all node transformations down the parent chain until we're back at mesh coordinates again
			const aiNode* tempNode = node;
			while(tempNode) {
				// check your matrix multiplication order here!!!
				boneMatrices[a] = tempNode->mTransformation * boneMatrices[a];
				// boneMatrices[a] = boneMatrices[a] * tempNode->mTransformation;
				tempNode = tempNode->mParent;
			}
			modelMeshes[i].hasChanged = true;
			modelMeshes[i].validCache = false;
		}
        
		modelMeshes[i].animatedPos.assign(modelMeshes[i].animatedPos.size(), aiVector3D(0.0f));
		if(mesh->HasNormals()){
			modelMeshes[i].animatedNorm.assign(modelMeshes[i].animatedNorm.size(), aiVector3D(0.0f));
		}
		// loop through all vertex weights of all bones
		for(unsigned int a=0; a<mesh->mNumBones; ++a) {
			const aiBone* bone = mesh->mBones[a];
			const aiMatrix4x4& posTrafo = boneMatrices[a];
            
			for(unsigned int b=0; b<bone->mNumWeights; ++b) {
				const aiVertexWeight& weight = bone->mWeights[b];
                
				size_t vertexId = weight.mVertexId;
				const aiVector3D& srcPos = mesh->mVertices[vertexId];
                
				modelMeshes[i].animatedPos[vertexId] += weight.mWeight * (posTrafo * srcPos);
			}
			if(mesh->HasNormals()){
				// 3x3 matrix, contains the bone matrix without the translation, only with rotation and possibly scaling
				aiMatrix3x3 normTrafo = aiMatrix3x3( posTrafo);
				for(unsigned int b=0; b<bone->mNumWeights; ++b) {
					const aiVertexWeight& weight = bone->mWeights[b];
					size_t vertexId = weight.mVertexId;
                    
					const aiVector3D& srcNorm = mesh->mNormals[vertexId];
					modelMeshes[i].animatedNorm[vertexId] += weight.mWeight * (normTrafo * srcNorm);
				}
			}
		}
	}
}
コード例 #5
0
ファイル: Info.cpp プロジェクト: lubosz/assimp
// -----------------------------------------------------------------------------------
void FindSpecialPoints(const aiScene* scene,aiVector3D special_points[3])
{
	special_points[0] = aiVector3D(1e10f,1e10f,1e10f);
	special_points[1] = aiVector3D(-1e10f,-1e10f,-1e10f);

	FindSpecialPoints(scene,scene->mRootNode,special_points);
	special_points[2] = 0.5f*(special_points[0]+special_points[1]);
}
コード例 #6
0
ファイル: ProcessHelper.cpp プロジェクト: 123woodman/minko
// -------------------------------------------------------------------------------
void FindAABBTransformed (const aiMesh* mesh, aiVector3D& min, aiVector3D& max, 
	const aiMatrix4x4& m)
{
	min = aiVector3D (10e10f,  10e10f, 10e10f);
	max = aiVector3D (-10e10f,-10e10f,-10e10f);
	for (unsigned int i = 0;i < mesh->mNumVertices;++i)
	{
		const aiVector3D v = m * mesh->mVertices[i];
		min = std::min(v,min);
		max = std::max(v,max);
	}
}
コード例 #7
0
ファイル: ObjFileParser.cpp プロジェクト: NevilX/assimp
// -------------------------------------------------------------------
void ObjFileParser::getVector( std::vector<aiVector3D> &point3d_array ) {
    size_t numComponents( 0 );
    DataArrayIt tmp( m_DataIt );
    while( !IsLineEnd( *tmp ) ) {
        if( *tmp == ' ' ) {
            ++numComponents;
        }
        tmp++;
    }
    float x, y, z;
    if( 2 == numComponents ) {
        copyNextWord( m_buffer, BUFFERSIZE );
        x = ( float ) fast_atof( m_buffer );

        copyNextWord( m_buffer, BUFFERSIZE );
        y = ( float ) fast_atof( m_buffer );
        z = 0.0;
    } else if( 3 == numComponents ) {
        copyNextWord( m_buffer, BUFFERSIZE );
        x = ( float ) fast_atof( m_buffer );

        copyNextWord( m_buffer, BUFFERSIZE );
        y = ( float ) fast_atof( m_buffer );

        copyNextWord( m_buffer, BUFFERSIZE );
        z = ( float ) fast_atof( m_buffer );
    } else {
        ai_assert( !"Invalid number of components" );
    }
    point3d_array.push_back( aiVector3D( x, y, z ) );
    m_DataIt = skipLine<DataArrayIt>( m_DataIt, m_DataItEnd, m_uiLine );
}
コード例 #8
0
ファイル: ObjFileParser.cpp プロジェクト: RSATom/Qt
// -------------------------------------------------------------------
void ObjFileParser::getVector( std::vector<aiVector3D> &point3d_array ) {
    size_t numComponents = getNumComponentsInLine();
    float x, y, z;
    if( 2 == numComponents ) {
        copyNextWord( m_buffer, Buffersize );
        x = ( float ) fast_atof( m_buffer );

        copyNextWord( m_buffer, Buffersize );
        y = ( float ) fast_atof( m_buffer );
        z = 0.0;
    } else if( 3 == numComponents ) {
        copyNextWord( m_buffer, Buffersize );
        x = ( float ) fast_atof( m_buffer );

        copyNextWord( m_buffer, Buffersize );
        y = ( float ) fast_atof( m_buffer );

        copyNextWord( m_buffer, Buffersize );
        z = ( float ) fast_atof( m_buffer );
    } else {
        throw DeadlyImportError( "OBJ: Invalid number of components" );
    }
    point3d_array.push_back( aiVector3D( x, y, z ) );
    m_DataIt = skipLine<DataArrayIt>( m_DataIt, m_DataItEnd, m_uiLine );
}
コード例 #9
0
void ColladaExporter::create_assimp_scene(aiScene& scene, const TMD::PostProcessed::Data_t& data) const {
	scene.mRootNode = new aiNode();

	scene.mRootNode->mMeshes = new unsigned[data.meshes.size()];
	scene.mRootNode->mMeshes[0] = 0;
	scene.mRootNode->mNumMeshes = 1;

	scene.mMeshes = new aiMesh*[data.meshes.size()];
	for (auto mesh_idx(0U); mesh_idx < data.meshes.size(); ++mesh_idx) {
		scene.mMeshes[mesh_idx] = new aiMesh();
		scene.mNumMeshes = data.meshes.size();
		auto& mesh_out = *scene.mMeshes[0];
		const auto& mesh_in = data.meshes[mesh_idx];
		mesh_out.mNumVertices = data.vertices.size();
		mesh_out.mVertices = new aiVector3D[data.vertices.size()];
		for (auto vert_idx(0U); vert_idx < data.vertices.size(); ++vert_idx) {
			const auto& vert_in(data.vertices[vert_idx]);
			mesh_out.mVertices[vert_idx] = aiVector3D(vert_in[0], vert_in[1], vert_in[2]);
		}
	}
	



}
コード例 #10
0
// -------------------------------------------------------------------
void ObjFileParser::getVector( std::vector<aiVector3D> &point3d_array ) {
    size_t numComponents( 0 );
    const char* tmp( &m_DataIt[0] );
    while( !IsLineEnd( *tmp ) ) {
        if ( !SkipSpaces( &tmp ) ) {
            break;
        }
        SkipToken( tmp );
        ++numComponents;
    }
    float x, y, z;
    if( 2 == numComponents ) {
        copyNextWord( m_buffer, BUFFERSIZE );
        x = ( float ) fast_atof( m_buffer );

        copyNextWord( m_buffer, BUFFERSIZE );
        y = ( float ) fast_atof( m_buffer );
        z = 0.0;
    } else if( 3 == numComponents ) {
        copyNextWord( m_buffer, BUFFERSIZE );
        x = ( float ) fast_atof( m_buffer );

        copyNextWord( m_buffer, BUFFERSIZE );
        y = ( float ) fast_atof( m_buffer );

        copyNextWord( m_buffer, BUFFERSIZE );
        z = ( float ) fast_atof( m_buffer );
    } else {
        throw DeadlyImportError( "OBJ: Invalid number of components" );
    }
    point3d_array.push_back( aiVector3D( x, y, z ) );
    m_DataIt = skipLine<DataArrayIt>( m_DataIt, m_DataItEnd, m_uiLine );
}
コード例 #11
0
ファイル: Model.cpp プロジェクト: 3Dheaven/OuterHeaven
void Model::processLight(const aiScene* scene)
{
	vector<Light> listPointLight;
	vector<Light> listSpotLight;
	vector<Light> listDirectionalLight;

	aiLight* light;
	Light myLight;

	/*
	listPointLight.push_back(createLight(aiVector3D(-50.0f, 10.0f, 0.0f), aiColor3D(1.0f, 1.0f, 1.0f), aiColor3D(1.0f, 1.0f, 1.0f),
		aiColor3D(1.0f, 1.0f, 1.0f), 1.0f, 0.009f, 0.0032f, 0.71f, 0.52f, aiVector3D(-1.0f, -1.0f, 1.0f)));
	*/
	listPointLight.push_back(createLight(aiVector3D(0.0f, 10.0f, 0.0f), aiColor3D(1.0f, 1.0f, 1.0f), aiColor3D(1.0f, 1.0f, 1.0f),
		aiColor3D(1.0f, 1.0f, 1.0f), 1.0f, 0.009f, 0.0032f, 0.71f, 0.52f, aiVector3D(-1.0f, -1.0f, 1.0f)));
	/*
	listPointLight.push_back(createLight(aiVector3D(50.0f, 10.0f, 0.0f), aiColor3D(1.0f, 1.0f, 1.0f), aiColor3D(1.0f, 1.0f, 1.0f),
		aiColor3D(1.0f, 1.0f, 1.0f), 1.0f, 0.009f, 0.0032f, 0.71f, 0.52f, aiVector3D(0.0f, -1.0f, 0.0f)));
	*/

	for(int i=0; scene->mNumLights; i++)
	{
		light = scene->mLights[i];

		myLight = createLight(light->mPosition, light->mColorAmbient, light->mColorDiffuse, light->mColorSpecular, 
			light->mAttenuationConstant, light->mAttenuationLinear, light->mAttenuationQuadratic,
			light->mAngleInnerCone, light->mAngleOuterCone, light->mDirection);

		if(light->mType == aiLightSourceType::aiLightSource_POINT)
			listPointLight.push_back(myLight);

		if(light->mType == aiLightSourceType::aiLightSource_SPOT)
			listSpotLight.push_back(myLight);

		if(light->mType == aiLightSourceType::aiLightSource_DIRECTIONAL)
			listDirectionalLight.push_back(myLight);
	}

	GLuint nbLights = listPointLight.size() + listSpotLight.size() + listDirectionalLight.size();

	m_lightShaderStorageBuffer.create(sizeof(glm::ivec4) + sizeof(Light)*nbLights, GL_SHADER_STORAGE_BUFFER, GL_STATIC_DRAW);
	glBufferSubData(GL_SHADER_STORAGE_BUFFER, 0, sizeof(glm::ivec4), glm::value_ptr(glm::ivec4(listPointLight.size(), listSpotLight.size(), listDirectionalLight.size(), 1)));
	glBufferSubData(GL_SHADER_STORAGE_BUFFER, sizeof(glm::ivec4), sizeof(Light)*listPointLight.size(), &listPointLight[0]);
	glBufferSubData(GL_SHADER_STORAGE_BUFFER, sizeof(glm::ivec4) + sizeof(Light)*listPointLight.size(), sizeof(Light)*listSpotLight.size(), &listSpotLight[0]);
	glBufferSubData(GL_SHADER_STORAGE_BUFFER, sizeof(glm::ivec4) + sizeof(Light)*listPointLight.size() + sizeof(Light)*listSpotLight.size(), sizeof(Light)*listDirectionalLight.size(), &listDirectionalLight[0]);
	m_lightShaderStorageBuffer.setBindingPoint(0);
}
コード例 #12
0
ファイル: CompareDump.cpp プロジェクト: smacdo/assimp
/* Specialization for aiVector3D */
template<> aiVector3D comparer_context :: cmp<aiVector3D >(const std::string& name) 
{
	const float x = cmp<float>(name+".x");
	const float y = cmp<float>(name+".y");
	const float z = cmp<float>(name+".z");

	return aiVector3D(x,y,z);
}
コード例 #13
0
ファイル: StandardShapes.cpp プロジェクト: 304471720/spring
// ------------------------------------------------------------------------------------------------
// Build a tetrahedron with points.magnitude == 1
unsigned int StandardShapes::MakeTetrahedron(std::vector<aiVector3D>& positions)
{
	positions.reserve(positions.size()+9);

	const float a = 1.41421f/3.f;
	const float b = 2.4494f/3.f;

	const aiVector3D v0  = aiVector3D(0.f,0.f,1.f);
	const aiVector3D v1  = aiVector3D(2*a,0,-1.f/3.f);
	const aiVector3D v2  = aiVector3D(-a,b,-1.f/3.f);
	const aiVector3D v3  = aiVector3D(-a,-b,-1.f/3.f);

	ADD_TRIANGLE(v0,v1,v2);
	ADD_TRIANGLE(v0,v2,v3);
	ADD_TRIANGLE(v0,v3,v1);
	ADD_TRIANGLE(v1,v3,v2);
	return 3;
}
コード例 #14
0
ファイル: StandardShapes.cpp プロジェクト: Polynominal/Lucy3D
// ------------------------------------------------------------------------------------------------
// Build a tetrahedron with points.magnitude == 1
unsigned int StandardShapes::MakeTetrahedron(std::vector<aiVector3D>& positions)
{
    positions.reserve(positions.size()+9);

    const ai_real a = 1.41421/3.0;
    const ai_real b = 2.4494/3.0;

    const aiVector3D v0  = aiVector3D(0.0,0.0,1.0);
    const aiVector3D v1  = aiVector3D(2*a,0,-1.0/3.0);
    const aiVector3D v2  = aiVector3D(-a,b,-1.0/3.0);
    const aiVector3D v3  = aiVector3D(-a,-b,-1.0/3.0);

    ADD_TRIANGLE(v0,v1,v2);
    ADD_TRIANGLE(v0,v2,v3);
    ADD_TRIANGLE(v0,v3,v1);
    ADD_TRIANGLE(v1,v3,v2);
    return 3;
}
コード例 #15
0
ファイル: Input.cpp プロジェクト: u-engine/chihuahua
//-------------------------------------------------------------------------------
// Handle mouse input for movements of the skybox
//
// The skybox can be moved by holding both the left and the right mouse button
// pressed. Rotation is possible in x and y direction.
//-------------------------------------------------------------------------------
void HandleMouseInputSkyBox( void )
	{
	POINT mousePos;
	GetCursorPos( &mousePos );
	ScreenToClient( GetDlgItem(g_hDlg,IDC_RT), &mousePos );

	g_mousePos.x = mousePos.x;
	g_mousePos.y = mousePos.y;

	aiMatrix4x4 matRotation;

	if (g_bMousePressedBoth )
		{
		int nXDiff = -(g_mousePos.x - g_LastmousePos.x);
		int nYDiff = -(g_mousePos.y - g_LastmousePos.y);

		aiMatrix4x4 matWorld;

		if( 0 != nYDiff)
			{
			aiVector3D v = aiVector3D(1.0f,0.0f,0.0f);
			D3DXMatrixRotationAxis( (D3DXMATRIX*) &matWorld, (D3DXVECTOR3*)&v, D3DXToRadian((float)nYDiff / 2.0f));
			CBackgroundPainter::Instance().RotateSB(&matWorld);
			}

		if( 0 != nXDiff)
			{
			aiMatrix4x4 matWorldOld;
			if( 0 != nYDiff)
				{
				matWorldOld = matWorld;
				}

			aiVector3D v = aiVector3D(0.0f,1.0f,0.0f);
			D3DXMatrixRotationAxis( (D3DXMATRIX*)&matWorld, (D3DXVECTOR3*)&v, D3DXToRadian((float)nXDiff / 2.0f) );
			matWorld =  matWorldOld * matWorld;		
			CBackgroundPainter::Instance().RotateSB(&matWorld);
			}
		}
	}
コード例 #16
0
ファイル: Mesh.cpp プロジェクト: Nerote/ProtoEngine
bool Mesh::Load(const char* p_sFile) {
	m_sName=p_sFile;

	std::string sFilepath=MODEL_PATH;
	sFilepath.append(p_sFile);

	Assimp::Importer xImporter;
	const aiScene* pxScene=xImporter.ReadFile(sFilepath.c_str(),
												aiProcess_Triangulate|
												aiProcess_GenSmoothNormals|
												
												aiProcess_CalcTangentSpace);
	
	if(!pxScene) {
		printf("Error: failed to load mesh %s\r\n",p_sFile);
		return false;
	};

	const aiMesh* pxMesh=pxScene->mMeshes[0];
	std::vector<graphics::Vertex> axVertices;
	std::vector<dword> aiIndices;

	const aiVector3D* vZero=&aiVector3D(0.0f,0.0f,0.0f);

	int i,iC=pxMesh->mNumVertices;
	for(i=0;i<iC;i++) {
		const aiVector3D* vPos=		&(pxMesh->mVertices[i]);
		const aiVector3D* vNormal=	&(pxMesh->mNormals[i]);
		const aiVector3D* vTexCoord=pxMesh->HasTextureCoords(0)?&(pxMesh->mTextureCoords[0][i]):vZero;
		const aiVector3D* vTangent= pxMesh->HasTangentsAndBitangents()?&(pxMesh->mTangents[i]):vZero;

		graphics::Vertex xVertex(
			math::Vec3(vPos->x,vPos->y,vPos->z),
			math::Vec2(vTexCoord->x,vTexCoord->y),
			math::Vec3(vNormal->x,vNormal->y,vNormal->z),
			math::Vec3(vTangent->x,vTangent->y,vTangent->z)
			);

		axVertices.push_back(xVertex);
	};

	iC=pxMesh->mNumFaces;
	for(i=0;i<iC;i++) {
		const aiFace& xFace=pxMesh->mFaces[i];
		aiIndices.push_back(xFace.mIndices[0]);
		aiIndices.push_back(xFace.mIndices[1]);
		aiIndices.push_back(xFace.mIndices[2]);
	};

	Init(&axVertices[0],axVertices.size(),&aiIndices[0],aiIndices.size());
	return true;
};
コード例 #17
0
ファイル: vix_model.cpp プロジェクト: ritgraphics/VixenEngine
	void Model::InitMesh(const aiMesh* mesh)
	{
		MeshInfo* meshInfo = new MeshInfo;
		meshInfo->NumVertices = mesh->mNumVertices;
		meshInfo->NumIndices  = mesh->mNumFaces * 3;
		Mesh* modelMesh = new Mesh(this, meshInfo);

		/*READ VERTS INTO MODEL MESH*/
		size_t numVerts = mesh->mNumVertices;
		for(size_t i = 0; i < numVerts; i++)
		{
			aiVector3D vertex = mesh->mVertices[i];
			aiVector3D tangent = aiVector3D(0.0f);
			if(mesh->HasTangentsAndBitangents()) {
				tangent = mesh->mTangents[i];
			}
			aiVector3D normal(0.0f);
			float u = 0.0f;
			float v = 0.0f;
			if(mesh->HasNormals()) {
				normal = mesh->mNormals[i];
			}
			if(mesh->HasTextureCoords(0)) {
				aiVector3D uvs = mesh->mTextureCoords[0][i];
				u = uvs.x;
				v = uvs.y;
			}
			meshInfo->Vertices.push_back(Vec3(vertex.x, vertex.y, vertex.z));
			modelMesh->AddVertex(vertex.x, vertex.y, vertex.z,
							     normal.x, normal.y, normal.z,
								 u, v,
								 tangent.x, tangent.y, tangent.z);
		}

		/*READ FACES INTO MODEL MESH*/
		size_t numFaces = mesh->mNumFaces;
		for(size_t i = 0; i < numFaces; i++)
		{
			aiFace face = mesh->mFaces[i];
			modelMesh->AddFace(face.mIndices[0],
							   face.mIndices[1],
							   face.mIndices[2]);
		}

		/*INITIALIZE MESH*/
		modelMesh->Init();

		/*ADD MODELMESH TO COLLECTION*/
		m_meshes.push_back(modelMesh);

	}
コード例 #18
0
ファイル: qmesh.cpp プロジェクト: LaurensVergote/Robotic-Hand
void QMesh::draw(aiMatrix4x4 transform) const
{
    glPushMatrix();
    aiMatrix4x4 mult;
    aiMatrix4x4::Translation(aiVector3D(0,-100,0), mult);
    transform = mult * transform;
    transform.Transpose(); //Transpose for some reason
    glMultMatrixf(static_cast<GLfloat*>(transform[0]));
    glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, faceColor);

    const GLuint *indices = geom->faces.constData();
    glDrawElements(GL_TRIANGLES, count, GL_UNSIGNED_INT, indices + start);
    glPopMatrix();
}
コード例 #19
0
void AssimpScene::update_center(float * vert, int length, aiVector3D & min, aiVector3D & max, aiVector3D & center)
{
	center.x = (sceneMax.x + sceneMin.x)/2.f;
	center.y = (sceneMax.y + sceneMin.y)/2.f;
	center.z = (sceneMax.z + sceneMin.z)/2.f;
	min = min - center;
	max = max - center;
	for (int i = 0; i < length; i += 3) {
		vert[i + 0] -= sceneCenter.x;
		vert[i + 1] -= sceneCenter.y;
		vert[i + 2] -= sceneCenter.z;
	}
	center = aiVector3D();
}
コード例 #20
0
ファイル: ObjFileParser.cpp プロジェクト: NevilX/assimp
// -------------------------------------------------------------------
//	Get values for a new 3D vector instance
void ObjFileParser::getVector3(std::vector<aiVector3D> &point3d_array) {
	float x, y, z;
	copyNextWord(m_buffer, BUFFERSIZE);
	x = (float) fast_atof(m_buffer);	
	
	copyNextWord(m_buffer, BUFFERSIZE);
	y = (float) fast_atof(m_buffer);

    copyNextWord( m_buffer, BUFFERSIZE );
    z = ( float ) fast_atof( m_buffer );

	point3d_array.push_back( aiVector3D( x, y, z ) );
	m_DataIt = skipLine<DataArrayIt>( m_DataIt, m_DataItEnd, m_uiLine );
}
コード例 #21
0
ファイル: StandardShapes.cpp プロジェクト: 304471720/spring
// ------------------------------------------------------------------------------------------------
// Fast subdivision for a mesh whose verts have a magnitude of 1
void Subdivide(std::vector<aiVector3D>& positions)
{
	// assume this to be constant - (fixme: must be 1.0? I think so)
	const float fl1 = positions[0].Length();

	unsigned int origSize = (unsigned int)positions.size();
	for (unsigned int i = 0 ; i < origSize ; i+=3)
	{
		aiVector3D& tv0 = positions[i];
		aiVector3D& tv1 = positions[i+1];
		aiVector3D& tv2 = positions[i+2];

		aiVector3D a = tv0, b = tv1, c = tv2;
		aiVector3D v1 = aiVector3D(a.x+b.x, a.y+b.y, a.z+b.z).Normalize()*fl1;
		aiVector3D v2 = aiVector3D(a.x+c.x, a.y+c.y, a.z+c.z).Normalize()*fl1;
		aiVector3D v3 = aiVector3D(b.x+c.x, b.y+c.y, b.z+c.z).Normalize()*fl1;

		tv0 = v1; tv1 = v3; tv2 = v2; // overwrite the original
		ADD_TRIANGLE(v1, v2, a);
		ADD_TRIANGLE(v2, v3, c);
		ADD_TRIANGLE(v3, v1, b);
	}
}
コード例 #22
0
ファイル: IFCProfile.cpp プロジェクト: niavok/spring
// ------------------------------------------------------------------------------------------------
void ProcessParametrizedProfile(const IfcParameterizedProfileDef& def, TempMesh& meshout, ConversionData& conv)
{
	if(const IfcRectangleProfileDef* const cprofile = def.ToPtr<IfcRectangleProfileDef>()) {
		const float x = cprofile->XDim*0.5f, y = cprofile->YDim*0.5f;

		meshout.verts.reserve(meshout.verts.size()+4);
		meshout.verts.push_back( aiVector3D( x, y, 0.f ));
		meshout.verts.push_back( aiVector3D(-x, y, 0.f ));
		meshout.verts.push_back( aiVector3D(-x,-y, 0.f ));
		meshout.verts.push_back( aiVector3D( x,-y, 0.f ));
		meshout.vertcnt.push_back(4);
	}
	else if( const IfcCircleProfileDef* const circle = def.ToPtr<IfcCircleProfileDef>()) {
		if( const IfcCircleHollowProfileDef* const hollow = def.ToPtr<IfcCircleHollowProfileDef>()) {
			// TODO
		}
		const size_t segments = 32;
		const float delta = AI_MATH_TWO_PI_F/segments, radius = circle->Radius;

		meshout.verts.reserve(segments);

		float angle = 0.f;
		for(size_t i = 0; i < segments; ++i, angle += delta) {
			meshout.verts.push_back( aiVector3D( cos(angle)*radius, sin(angle)*radius, 0.f ));
		}

		meshout.vertcnt.push_back(segments);
	}
	else {
		IFCImporter::LogWarn("skipping unknown IfcParameterizedProfileDef entity, type is " + def.GetClassName());
		return;
	}

	aiMatrix4x4 trafo;
	ConvertAxisPlacement(trafo, *def.Position);
	meshout.Transform(trafo);
}
コード例 #23
0
ファイル: Main.cpp プロジェクト: mrotondo/ccrma
void move()
{
    // TODO: This has the classic "diagonal movement is faster" bug
    // TODO: It also has the classic "movement speed is dependent on framerate" bug
    static float speed = 0.2;
    float rad_pitch = pitch + M_PI / 2.0;
    float rad_yaw = yaw;

    if (forward) {

        aiVector3D force = aiVector3D(-speed * sin(rad_pitch) * sin(rad_yaw),
                                      -speed * cos(rad_pitch),
                                      speed * sin(rad_pitch) * cos(rad_yaw));
        velocity += force;
    }
    if (backward) {
        aiVector3D force = aiVector3D(-speed * sin(rad_pitch) * sin(rad_yaw),
                                      -speed * cos(rad_pitch),
                                      speed * sin(rad_pitch) * cos(rad_yaw));
        velocity -= force;
    }
    if (left) {
        aiVector3D force = aiVector3D(-speed * sin(rad_pitch) * sin(rad_yaw + M_PI / 2.0),
                                      0.0,
                                      speed * sin(rad_pitch) * cos(rad_yaw + M_PI / 2.0));
        velocity -= force;
    }
    if (right) {
        aiVector3D force = aiVector3D(-speed * sin(rad_pitch) * sin(rad_yaw + M_PI / 2.0),
                                      0.0,
                                      speed * sin(rad_pitch) * cos(rad_yaw + M_PI / 2.0));
        velocity += force;
    }

    position -= velocity;
    velocity *= (1.0 - friction);
}
コード例 #24
0
ファイル: exporter.cpp プロジェクト: apjagdale/GearVRf
/* Converts the GVRMesh to aiMesh */
void gvr2aiMesh(Mesh &gvrmesh, aiMesh &aimesh) {
    const auto &vertices = gvrmesh.vertices();
    const auto &normals = gvrmesh.normals();
    const auto &uvs = gvrmesh.getVec2Vector("a_texcoord");

    aimesh.mMaterialIndex = 0;
    aimesh.mVertices = new aiVector3D[vertices.size()];
    aimesh.mNormals = new aiVector3D[vertices.size()];
    aimesh.mNumVertices = vertices.size();

    aimesh.mTextureCoords[0] = new aiVector3D[vertices.size()];
    aimesh.mNumUVComponents[0] = vertices.size();

    int j;
    for (j = 0; j < aimesh.mNumVertices; j++) {
        aimesh.mNormals[j] = aiVector3D(normals[j].x, normals[j].y, normals[j].z);
        aimesh.mVertices[j] = aiVector3D(vertices[j].x, vertices[j].y, vertices[j].z);
        aimesh.mTextureCoords[0][j] = aiVector3D(uvs[j].x, uvs[j].y, 0);
    }

    const auto &indices = gvrmesh.indices();

    aimesh.mNumFaces = (unsigned int)(indices.size() / 3);
    aimesh.mFaces = new aiFace[aimesh.mNumFaces];

    j = 0;
    for (int i = 0; i < aimesh.mNumFaces; i++) {
        aiFace &face = aimesh.mFaces[i];
        face.mIndices = new unsigned int[3];
        face.mNumIndices = 3;

        face.mIndices[0] = indices[j + 2];
        face.mIndices[1] = indices[j + 1];
        face.mIndices[2] = indices[j];
        j = j + 3;
    }
}
コード例 #25
0
int AssimpScene::uncompress_recursive_old(float * arr, float arr_size, float vertex_size, int arr_index_start, const aiScene * sc, const aiNode * nd, aiMatrix4x4 * matrix_before)
{
	aiMatrix4x4 m = (*matrix_before) * nd->mTransformation;
	int arr_index = arr_index_start;
	int count_vertex = 0; //combined sum is returned at the end

	for (int n = 0; n < nd->mNumMeshes; ++n) {
		const aiMesh* mesh = sc->mMeshes[nd->mMeshes[n]];
		for (int t = 0; t < mesh->mNumFaces; ++t) {
			const struct aiFace* face = &mesh->mFaces[t];
			bool isNormal = mesh->mNormals != NULL;

			for (int i = 0; i < face->mNumIndices; i++) {
				count_vertex++;
				int index = face->mIndices[i];
				aiVector3D 
					vert(m*mesh->mVertices[index]),
					normal((isNormal)? aiVector3D (mesh->mNormals[index]): aiVector3D());
				adjust_scene_roperty(vert.x, vert.y, vert.z);
				arr[arr_index]		= vert.x;
				arr[arr_index + 1]	= vert.y;
				arr[arr_index + 2]	= vert.z;
				arr[arr_index + 3]	= normal.x;
				arr[arr_index + 4]	= normal.y;
				arr[arr_index + 5]	= normal.z;
				arr_index			+= vertex_size;
			}
		}

	}

	for (int n = 0; n < nd->mNumChildren; ++n) {
		count_vertex += uncompress_recursive_old(arr, arr_size, vertex_size, arr_index, sc, nd, &m);
	}
	return count_vertex;
}
コード例 #26
0
ファイル: Main.cpp プロジェクト: mrotondo/ccrma
void initOpenGL() {
    // Initialize GLEW on Windows, to make sure that OpenGL 2.0 is loaded
#ifdef FRAMEWORK_USE_GLEW
    GLint error = glewInit();
    if (GLEW_OK != error) {
        std::cerr << glewGetErrorString(error) << std::endl;
        exit(-1);
    }
    if (!GLEW_VERSION_2_0 || !GL_EXT_framebuffer_object) {
        std::cerr << "This program requires OpenGL 2.0 and FBOs" << std::endl;
        exit(-1);
    }
#endif

    // This initializes OpenGL with some common defaults.  More info here:
    // http://www.sfml-dev.org/tutorials/1.6/window-opengl.php
    glClearDepth(1.0f);
    glClearColor(0.15f, 0.15f, 0.15f, 1.0f);
    glEnable(GL_DEPTH_TEST);
    glHint(GL_PERSPECTIVE_CORRECTION_HINT,GL_NICEST);
    glViewport(0, 0, window.GetWidth(), window.GetHeight());

    position = aiVector3D(35.0, -20.0, 0.0);
    yaw = M_PI * 3 / 2.0;
    pitch = -M_PI / 7;

    GLfloat light0_position[] = { 0.0, 30.0, 0.0, 0.0 };
    GLfloat light0_ambient[] = { 245/2550.0, 222/2550.0, 179/2550.0, 1 };
    GLfloat light0_diffuse[] = { 245/255.0, 232/255.0, 199/255.0, 1 };
    GLfloat light0_specular[] = { 0.7, 0.7, 0.7, 1 };
    GLfloat shininess = 90;
    glLightfv(GL_LIGHT0, GL_POSITION, light0_position);
    glLightfv( GL_LIGHT0, GL_AMBIENT, light0_ambient );
    glLightfv( GL_LIGHT0, GL_DIFFUSE, light0_diffuse );
    glLightfv( GL_LIGHT0, GL_SPECULAR, light0_specular );
    glLightfv( GL_LIGHT0, GL_SHININESS, &shininess );
    glEnable(GL_LIGHT0);

    GLfloat light1_position[] = { 0, 11, 0, 0.0 };
    GLfloat light1_diffuse[] = { 145/2550.0, 222/2550.0, 149/2550.0, 1 };
    GLfloat light1_specular[] = { 0.1, 0.1, 0.1, 1 };
    glLightfv( GL_LIGHT1, GL_POSITION, light1_position );
    glLightfv( GL_LIGHT1, GL_DIFFUSE, light1_diffuse );
    glLightfv( GL_LIGHT1, GL_SPECULAR, light1_specular );
    glEnable(GL_LIGHT1);

    depthRenderTarget = new DepthRenderTarget(RENDER_WIDTH * SHADOW_MAP_RATIO, RENDER_HEIGHT * SHADOW_MAP_RATIO);
}
コード例 #27
0
 //Draw the animation frame given time in seconds
 void drawFrame(double time) {
     model.createFrame(0, time);
     
     unsigned int boneId=model.boneName2boneId.at("head");
     aiVector3D oldScale;
     aiQuaternion oldRotation;
     aiVector3D oldPosition;
     model.bones[boneId].transformation.Decompose(oldScale, oldRotation, oldPosition);
     aiMatrix3x3 newRotation;
     aiMatrix3x3::Rotation(cos(time*10.0), aiVector3D(0, 0, 1), newRotation);
     model.bones[boneId].transformation=aiMatrix4x4Compose(oldScale, aiQuaternion(newRotation)*oldRotation, oldPosition);
     
     for(auto& mesh: model.meshes) {
         auto meshFrame=model.getMeshFrame(mesh);
         model.drawMeshFrame(meshFrame);
     }
 }
コード例 #28
0
void AnimaApplication::ProcessInput()
{
	const Input::KeyMap& keys = mInput->GetKeys();
	for( Input::KeyMap::const_iterator it = keys.begin(); it != keys.end(); ++it )
	{
		if( (it->second.PreviousState & RI_KEY_BREAK) && (it->second.CurrentState & RI_KEY_BREAK) == 0 )
		{
			switch( it->first )
			{
				case VK_SPACE:
					mRotateModel = mModel->ToggleAnimationPlayback();
					break;
				case VK_ESCAPE:
				case 0x51: // 'Q'
					PostQuitMessage(0);
					break;

				case 0x52: // 'R'
					TestDeviceLost();
					break;

				case 0x53:	// 'S'
					mUserInterface->ToggleStatistics();
					break;
				case 0x54: // 'T'
				{
					int shaderTest = mModel->ToggleShaderTest();
					mUserInterface->SetShaderTest( shaderTest );
					break;
				}
				case 0x4D: // 'M'
				{
					int animationMethod = mModel->ToggleAnimationMethod();
					mModel->SetRoot( aiVector3D(0,0,0), mModelRotation );
					mModel->Update( 0 );
					mUserInterface->SetSkeletalAnimationMethod( animationMethod );
					break;
				}
			}
		}
	}
}
コード例 #29
0
ファイル: thing.cpp プロジェクト: wilkie/apsis-barebones
void Apsis::Model::Thing::_addMesh(const void* mesh_ptr) {
  const aiMesh* mesh = (const aiMesh*)mesh_ptr;

  unsigned int materialIndex = mesh->mMaterialIndex;
  unsigned int numberOfVertices = mesh->mNumVertices;
  unsigned int numberOfFaces = mesh->mNumFaces;

  std::vector<glm::vec3> vertices;
  std::vector<glm::vec3> normals;
  std::vector<glm::vec2> textureCoords;
  std::vector<unsigned int> elements;

  aiVector3D zero = aiVector3D(0.0f, 0.0f, 0.0f);

  for (unsigned int i = 0; i < numberOfVertices; i++) {
    const aiVector3D* pos     = &mesh->mVertices[i];
    const aiVector3D* normal  = &zero;
    const aiVector3D* texture = &zero;
    if (mesh->HasNormals()) {
      normal = &mesh->mNormals[i];
    }
    if (mesh->HasTextureCoords(0)) {
      texture = &mesh->mTextureCoords[0][i];
    }

    vertices.push_back(glm::vec3(pos->x, pos->y, pos->z));
    normals.push_back(glm::vec3(normal->x, normal->y, normal->z));
    textureCoords.push_back(glm::vec2(texture->x, texture->y));
  }

  for (unsigned int i = 0; i < numberOfFaces; i++) {
    const aiFace& face = mesh->mFaces[i];
    if (face.mNumIndices == 3) {
      elements.push_back(face.mIndices[0]);
      elements.push_back(face.mIndices[1]);
      elements.push_back(face.mIndices[2]);
    }
  }

  _meshes.push_back(Mesh(vertices, normals, textureCoords, elements));
}
コード例 #30
0
ファイル: StandardShapes.cpp プロジェクト: 304471720/spring
// ------------------------------------------------------------------------------------------------
// Build a hexahedron with points.magnitude == 1
unsigned int StandardShapes::MakeHexahedron(std::vector<aiVector3D>& positions,
	bool polygons /*= false*/)
{
	positions.reserve(positions.size()+36);
	const float length = 1.f/1.73205080f;

	const aiVector3D v0  = aiVector3D(-1.f,-1.f,-1.f)*length;
	const aiVector3D v1  = aiVector3D(1.f,-1.f,-1.f)*length;
	const aiVector3D v2  = aiVector3D(1.f,1.f,-1.f)*length;
	const aiVector3D v3  = aiVector3D(-1.f,1.f,-1.f)*length;
	const aiVector3D v4  = aiVector3D(-1.f,-1.f,1.f)*length;
	const aiVector3D v5  = aiVector3D(1.f,-1.f,1.f)*length;
	const aiVector3D v6  = aiVector3D(1.f,1.f,1.f)*length;
	const aiVector3D v7  = aiVector3D(-1.f,1.f,1.f)*length;

	ADD_QUAD(v0,v3,v2,v1);
	ADD_QUAD(v0,v1,v5,v4);
	ADD_QUAD(v0,v4,v7,v3);
	ADD_QUAD(v6,v5,v1,v2);
	ADD_QUAD(v6,v2,v3,v7);
	ADD_QUAD(v6,v7,v4,v5);
	return (polygons ? 4 : 3);
}