Exemple #1
0
ModelPtr AssetLoader::LoadStaticModel(std::string fileName)
{
    std::ifstream file(fileName.c_str(),std::ios::binary);

    if(file.is_open())
    {
        unsigned int number;
        file.read((char*)&number,sizeof(unsigned int));
        if(number != 0)
            return ModelPtr(true);

        unsigned int numberOfMeshes;
        file.read((char*)&numberOfMeshes,4);

        ModelPtr ptr(Heap::GetPtr()->Models.New());
        Model * model = ptr.Get();

        for(unsigned int iMesh = 0; iMesh < numberOfMeshes; iMesh++)
        {
            file.read((char*)&staticMeshData.numberOfVerts,sizeof(unsigned int));

            file.read((char*)staticMeshData.vertecies,sizeof(StaticVert) * staticMeshData.numberOfVerts);
            file.read((char*)&staticMeshData.numberOfIndecies,sizeof(unsigned int));

            file.read((char*)staticMeshData.indecies,sizeof(unsigned int) * staticMeshData.numberOfIndecies);

            MeshPtr meshPtr = factory->CreateMesh();
            Mesh * mesh = meshPtr.Get();
            mesh->Init();
            mesh->SetDrawMethod(DM_DRAW_INDEXED);

            mesh->InitVertexBuffer(staticMeshData.numberOfVerts * sizeof(StaticVert),sizeof(StaticVert),staticMeshData.vertecies);
            mesh->InitIndexBuffer(staticMeshData.numberOfIndecies,staticMeshData.indecies);

            model->AddMesh(meshPtr);

        }

        file.close();

        return ptr;
    }
    else return ModelPtr(true);

}
ModelPtr XFileLoader::OpenFromResource( int resourceID,float scale )
{
	HRESULT hr = S_OK;

	m_fileName = _T("");

	TCHAR path[MAX_PATH];
	_tcscpy_s( path,MAX_PATH,m_fileName.c_str() );
	PathRemoveFileSpec( path );
	PathAddBackslash( path );
	m_path = path;

	m_scale = scale;

	Graphics* graphics = Graphics::GetInstance();
	IDirect3DDevice9Ptr pD3DDevice = graphics->GetDirect3DDevice();

	m_pAdjacencyBuf = NULL;
	m_pMaterialBuf = NULL;
	m_pEffectInstancesBuf = NULL;
	m_Materials = 0;
	m_pD3DMesh = NULL;

	ModelPtr pModel;

	hr = D3DXLoadMeshFromXResource(
		NULL,
		(LPSTR)MAKEINTRESOURCE( resourceID ),
		(LPSTR)RT_RCDATA,
		D3DXMESH_SYSTEMMEM,
		pD3DDevice,
		&m_pAdjacencyBuf,
		&m_pMaterialBuf,
		&m_pEffectInstancesBuf,
		&m_Materials,
		&m_pD3DMesh );

	if( FAILED(hr) )
	{
		return ModelPtr();
	}

	return ModelPtr( new Model( CreateMeshContainer() ) );
}
ModelPtr XFileLoader::Open( const tstring& filePath,float scale )
{
	HRESULT hr = S_OK;

	m_fileName = filePath;

	TCHAR path[MAX_PATH];
	_tcscpy_s( path,MAX_PATH,filePath.c_str() );
	PathRemoveFileSpec( path );
	PathAddBackslash( path );
	m_path = path;

	m_scale = scale;

	Graphics* graphics = Graphics::GetInstance();
	IDirect3DDevice9Ptr pD3DDevice = graphics->GetDirect3DDevice();

	m_pAdjacencyBuf = NULL;
	m_pMaterialBuf = NULL;
	m_pEffectInstancesBuf = NULL;
	m_Materials = 0;
	m_pD3DMesh = NULL;

	ModelPtr pModel;

	hr = D3DXLoadMeshFromX(
		m_fileName.c_str(),
		D3DXMESH_SYSTEMMEM,
		pD3DDevice,
		&m_pAdjacencyBuf,
		&m_pMaterialBuf,
		&m_pEffectInstancesBuf,
		&m_Materials,
		&m_pD3DMesh );

	if( FAILED(hr) )
	{
		return ModelPtr();
	}

	return ModelPtr( new Model( CreateMeshContainer() ) );
}
StaticMesh::StaticMesh( MeshBufferPtr mesh, string name )
    : Renderable( name )
{

    m_model = ModelPtr( new Model( mesh ) );
    m_nameList = -1;
    init( mesh );

    calcBoundingBox();
    compileColoredMeshList();
    compileWireframeList();
    compileNameList();

}
Exemple #5
0
ModelPtr AssetLoader::LoadAnimatedModel(std::string fileName)
{
    FILE * f = nullptr;
    fopen_s(&f,fileName.c_str(),"rb");
    if(f != nullptr)
    {
        unsigned int number;
        fread_s(&number,4,4,1,f);
        if(number != 50)
        {
            fclose(f);
            return ModelPtr(true);
        }

        unsigned int meshesCount;
        fread_s(&meshesCount,4,4,1,f);

        ModelPtr ptr(Heap::GetPtr()->Models.New());
        Model * model = ptr.Get();

        for(unsigned int iMesh = 0; iMesh < meshesCount; iMesh++)
        {
            fread_s(&animatedMeshData.numOfVerts,4,4,1,f);

            fread_s(animatedMeshData.verts,sizeof(AnimatedVert) * animatedMeshData.numOfVerts,sizeof(AnimatedVert),animatedMeshData.numOfVerts,f);
            fread_s(&animatedMeshData.numOfIndecies,4,4,1,f);

            fread_s(animatedMeshData.indecies,sizeof(unsigned int) * animatedMeshData.numOfIndecies, 4 ,animatedMeshData.numOfIndecies,f);

            MeshPtr meshPtr = factory->CreateMesh();
            Mesh * mesh = meshPtr.Get();
            mesh->Init();
            mesh->SetDrawMethod(DM_DRAW_INDEXED);

            mesh->InitVertexBuffer(animatedMeshData.numOfVerts * sizeof(AnimatedVert),sizeof(AnimatedVert),animatedMeshData.verts);
            mesh->InitIndexBuffer(animatedMeshData.numOfIndecies,animatedMeshData.indecies);

            model->AddMesh(meshPtr);

        }


        fclose(f);

        return ptr;
    }
    else return nullptr;
}
Exemple #6
0
Window::Window(int width, int height, int bpp) :
    width(width), height(height), bpp(bpp), quit(false), isActive(true),
    lightPos(Vec4(2.0, 5.0, 0.5, 1.0)), topView(false),
    from(new Vec3(-2, 4.0, 8)), at(new Vec3(0.0, 0.0, -1.0)),
    up(new Vec3(0, 1, 0)), camera(from, at, up)
{
    initSDL();
    initGL();

    AC3DConverter a;
    model = ModelPtr(a.loadAC3DModel("../data/cylinder.ac"));

    BonePtr bone(model->getBone());
    bone->setPos(Vec3(-3.0, 0.0, 0.0));

    JointPtr joint = bone->getJoint();
    joint->setPos(Vec3(0.0, 0.0, 0.0));

    BonePtr b(new Bone);
    joint->setBone(b);
    BonePtr bone2 = joint->getBone();

    JointPtr joint2 = bone2->getJoint();
    joint2->setPos(Vec3(3.0, 0.0, 0.0));

    bone->setTransform(vr::Matrix::translate(0.0, 2.0, 0.0));
    bone->getJoint()->setTransform(vr::Matrix::translate(0.0, -2.0, 0.0));
    bone2->setTransform(vr::Matrix::translate(0.0, 2.0, 0.0));

    model->calcWeight();

    ShaderPtr shader(new Shader("shaders/skin.vert", "shaders/skin.frag"));
    program = ProgramPtr(new Program());
    program->addShaders(shader);

    tex = TexturePtr(new Texture());
    tex->createTextureARB("../data/alpha.png", GL_TEXTURE0_ARB);
    uniformTex = Uniform1iPtr(new Uniform<int, 1>("ualpha", program->getId()));
    uniformTex->setValue(0);
    program->addUniform(uniformTex);

    texFur = TexturePtr(new Texture());
    texFur->createTextureARB("../data/Fur1.png", GL_TEXTURE1_ARB);
    uniformTexFur = Uniform1iPtr(new Uniform<int, 1>("ufur", program->getId()));
    uniformTexFur->setValue(1);
    uniformTexFur->apply();
    program->addUniform(uniformTexFur);

    uniformPass = Uniform1iPtr(new Uniform<int, 1>("upass", program->getId()));
    program->addUniform(uniformPass);

    uniformMatrices = UniformMatrix3fvPtr(new Uniform<vr::Matrix, 3>("boneMatrices[0]", program->getId()));
    program->addUniform(uniformMatrices);

    rotation = 0.0f;

    for (unsigned int i = 0; i < 20; i++) 
    {
        pressedKeys[i] = false;
    }
}
Exemple #7
0
ModelPtr STLIO::read(string filename)
{
	return ModelPtr(new Model);
}
MultiPointCloud::MultiPointCloud(PointBufferPtr buffer, string name)
{
	m_model = ModelPtr(new Model(buffer));
	init(buffer);
}