コード例 #1
0
// add a component at the given position and orientation
bool PCBMODEL::AddComponent( const std::string& aFileName, const std::string aRefDes,
    bool aBottom, DOUBLET aPosition, double aRotation,
    TRIPLET aOffset, TRIPLET aOrientation )
{
    // first retrieve a label
    TDF_Label lmodel;

    if( !getModelLabel( aFileName, lmodel ) )
    {
        std::ostringstream ostr;
        ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
        ostr << "  * no model for filename '" << aFileName << "'\n";
        wxLogMessage( "%s\n", ostr.str().c_str() );
        return false;
    }

    // calculate the Location transform
    TopLoc_Location toploc;

    if( !getModelLocation( aBottom, aPosition, aRotation, aOffset, aOrientation, toploc ) )
    {
        std::ostringstream ostr;
        ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
        ostr << "  * no location data for filename '" << aFileName << "'\n";
        wxLogMessage( "%s\n", ostr.str().c_str() );
        return false;
    }

    // add the located sub-assembly
    TDF_Label llabel = m_assy->AddComponent( m_assy_label, lmodel, toploc );

    if( llabel.IsNull() )
    {
        std::ostringstream ostr;
        ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
        ostr << "  * could not add component with filename '" << aFileName << "'\n";
        wxLogMessage( "%s\n", ostr.str().c_str() );
        return false;
    }

    // attach the RefDes name
    TCollection_ExtendedString refdes( aRefDes.c_str() );
    TDataStd_Name::Set( llabel, refdes );

    return true;
}
コード例 #2
0
ファイル: ModelClass.cpp プロジェクト: ruleless/aMazing
HRESULT ModelClass::Initialize(ID3D11Device* device,
	ID3D11DeviceContext* context,
	MutableString&& string)
{
	HRESULT hr = E_FAIL;
	hr = BasicObject::Initialize(device, context);
	if (FAILED(hr))
	{
		return hr;
	}
	
	std::string filename = string.getMultiByteString(); 

	unsigned int ppsteps = aiProcess_CalcTangentSpace | // calculate tangents and bitangents if possible
		aiProcess_JoinIdenticalVertices | // join identical vertices/ optimize indexing
		aiProcess_ValidateDataStructure | // perform a full validation of the loader's output
		aiProcess_ImproveCacheLocality | // improve the cache locality of the output vertices
		aiProcess_RemoveRedundantMaterials | // remove redundant materials
		aiProcess_FindDegenerates | // remove degenerated polygons from the import
		aiProcess_FindInvalidData | // detect invalid model data, such as invalid nor vectors
		aiProcess_GenUVCoords | // convert spherical, cylindrical, box and planar mapping to proper UVs
		aiProcess_TransformUVCoords | // preprocess UV transformations (scaling, translation ...)
		aiProcess_FindInstances | // search for instanced meshes and remove them by references to one master
		aiProcess_LimitBoneWeights | // limit bone weights to 4 per SkinVertex
		aiProcess_OptimizeMeshes | // join small meshes, if possible;
		aiProcess_SplitByBoneCount | // split meshes with too many bones. Necessary for our (limited) hardware skinning shader
		0;

	// 使用导入器导入选定的模型文件 
	importer.reset(new Assimp::Importer);
	scene = (aiScene*)importer->ReadFile(filename.c_str(),
		ppsteps |
		aiProcess_GenSmoothNormals |
		aiProcess_SplitLargeMeshes |
		aiProcess_Triangulate |
		aiProcess_ConvertToLeftHanded |
		aiProcess_SortByPType |
		0);
	if (scene == nullptr)
	{
		//failed on loading asset. 
		//if so get error message & output to console.
		std::cout << importer->GetErrorString() << std::endl;
		return E_FAIL;
	}

	sceneAnimator.reset(new SceneAnimator(scene));
	//update the fileLocation
	modelLocation.reset(new std::string(getModelLocation(filename.c_str())));

	hr = boneTransformations.Initialize(device, context, 3);
	if (FAILED(hr))
	{
		return hr;
	}
	//load the texturess of this model.
	loadTextures(device, context, scene, string.getMultiByteString().c_str());

	//load the meshes of this model.
	loadMeshes(scene);
	
	if (vertices.empty() || indices.empty())
	{
		return E_FAIL;
	}
	//send vertices into vertex buffers.
	for (int i = 0; i < vertices.size(); i++)
	{
		auto& currentBuffer = vertexBuffer[i];
		hr = currentBuffer->Initialize(device, context, 
			vertices[i]->data(), 
			vertices[i]->size(),
			indices[i]->data(),
			indices[i]->size());
		if (FAILED(hr))
		{
			return hr;
		}
	}
	return S_OK;
}