//////////////////////////////////////////////////////////////////////////
///  Particle Quad
gfx::ModelMesh* ContentManager::getParticleQuad()
{
    if (m_ParticleQuad == nullptr)
    {    
        using namespace gfx;
        VertexLayout layout;
        layout.addElement(VertexElement(eShaderAttribute_Position, eShaderAttributeType_Float, eShaderAttributeTypeComponents_3, 0));

        he::ObjectList<VertexPos> vertices(4);
        vertices.add(VertexPos(vec3(-1, 1, 0.0f)));
        vertices.add(VertexPos(vec3(1, 1, 0.0f)));
        vertices.add(VertexPos(vec3(-1, -1, 0.0f)));
        vertices.add(VertexPos(vec3(1, -1, 0.0f)));

        he::PrimitiveList<uint16> indices(6);
        indices.add(1); indices.add(0); indices.add(2);
        indices.add(1); indices.add(2); indices.add(3);

        ObjectHandle handle(ResourceFactory<ModelMesh>::getInstance()->create());
        m_ParticleQuad = ResourceFactory<ModelMesh>::getInstance()->get(handle);
        m_ParticleQuad->setName(he::String("Particle quad"));

        m_ParticleQuad->init(layout, gfx::MeshDrawMode_Triangles);
        m_ParticleQuad->setVertices(&vertices[0], 4, gfx::MeshUsage_Static, false);
        m_ParticleQuad->setIndices(&indices[0], 6, gfx::IndexStride_UShort, gfx::MeshUsage_Static);
        m_ParticleQuad->setLoaded(eLoadResult_Success);
    }

    m_ParticleQuad->instantiate();
    return m_ParticleQuad;
}
Esempio n. 2
0
void SkyBox::load( const he::String& asset )
{
    HE_ASSERT(m_Drawable == nullptr, "Skybox is loaded twice!");
    m_Drawable = HENew(Drawable)();
    m_Drawable->setLocalScale(vec3(1000000000)); // bounds must be huge
    //////////////////////////////////////////////////////////////////////////
    /// Load Model
    //////////////////////////////////////////////////////////////////////////
    ModelMesh* const cube(
        ResourceFactory<gfx::ModelMesh>::getInstance()->get(ResourceFactory<gfx::ModelMesh>::getInstance()->create()));
    cube->setName(he::String("skybox-") + asset);
    he::PrimitiveList<vec3> vertices(8);
    vertices.add(vec3(-1,  1, -1));
    vertices.add(vec3( 1,  1, -1));
    vertices.add(vec3(-1, -1, -1));
    vertices.add(vec3( 1, -1, -1));

    vertices.add(vec3(-1,  1,  1));
    vertices.add(vec3( 1,  1,  1));
    vertices.add(vec3(-1, -1,  1));
    vertices.add(vec3( 1, -1,  1));

    he::PrimitiveList<uint16> indices(36);
    indices.add(0); indices.add(1); indices.add(2); //front
    indices.add(1); indices.add(3); indices.add(2);

    indices.add(5); indices.add(4); indices.add(7); //back
    indices.add(4); indices.add(6); indices.add(7);

    indices.add(4); indices.add(0); indices.add(6); //left
    indices.add(0); indices.add(2); indices.add(6);

    indices.add(1); indices.add(5); indices.add(3); //right
    indices.add(5); indices.add(7); indices.add(3);

    indices.add(4); indices.add(5); indices.add(0); //top
    indices.add(5); indices.add(1); indices.add(0);

    indices.add(3); indices.add(7); indices.add(2); //bottom
    indices.add(7); indices.add(6); indices.add(2);

    VertexLayout layout;
    layout.addElement(VertexElement(eShaderAttribute_Position, eShaderAttributeType_Float, eShaderAttributeTypeComponents_3, 0));
    cube->init(layout, MeshDrawMode_Triangles);
    cube->setVertices(&vertices[0], static_cast<uint32>(vertices.size()), MeshUsage_Static, false);
    cube->setIndices(&indices[0], static_cast<uint32>(indices.size()), IndexStride_UShort, MeshUsage_Static);
    cube->setLoaded(eLoadResult_Success);
    m_Drawable->setModelMesh(cube);
    cube->release();

    Material* const material(CONTENT->loadMaterial("engine/sky.material"));
    m_Drawable->setMaterial(material);
    material->release();

    const int8 cubeMap(m_Drawable->getMaterial()->findParameter(HEFS::strcubeMap));
    if (cubeMap >= 0)
    {
        const TextureCube* cube(CONTENT->asyncLoadTextureCube(asset));
        m_Drawable->getMaterial()->getParameter(cubeMap).setTextureCube(cube);
        cube->release();
    }
}