예제 #1
0
파일: h3d.cpp 프로젝트: cewbost/texgen
void disableRenderStage(const char* id)
{
    if(_pipeline == 0)
        throw tgException("no pipeline active");

    int elem = h3dFindResElem(
                   _pipeline,
                   H3DPipeRes::StageElem,
                   H3DPipeRes::StageNameStr,
                   id);
    if(elem == -1)
        throw tgException("stage %s not found", id);
    h3dSetResParamI(
        _pipeline,
        H3DPipeRes::StageElem,
        elem,
        H3DPipeRes::StageActivationI,
        0);
}
예제 #2
0
파일: h3d.cpp 프로젝트: cewbost/texgen
int loadTexture(const char* buffer, size_t size)
{
    char name[64] = "";
    snprintf(name, 64, "_res%i", _res_loaded++);
    H3DRes res = h3dAddResource(H3DResTypes::Texture, name, 0);
    if(!h3dLoadResource(res, buffer, size))
    {
        dumpMessages();
        throw tgException("unable to load texture resource");
    }

    int handle = TextureManager::addTexture(res);
    dumpMessages();
    return handle;
}
예제 #3
0
void tgStructure::addPair(const btVector3& from, const btVector3& to, std::string tags)
{
    // @todo: do we need to pass in tags here? might be able to save some proc time if not...
    tgPair p = tgPair(from, to);
    if (!m_pairs.contains(p))
    {
        m_pairs.addPair(tgPair(from, to, tags));
    }
    else
    {
        std::ostringstream os;
        os << "A pair matching " << p << " already exists in this structure.";
        throw tgException(os.str());
    }
}
예제 #4
0
파일: h3d.cpp 프로젝트: cewbost/texgen
void setPipeline(const char* buffer, size_t size)
{
    char name[64] = "";
    snprintf(name, 64, "_res%i", _res_loaded++);
    H3DRes res = h3dAddResource(H3DResTypes::Pipeline, name, 0);
    if(!h3dLoadResource(res, buffer, size))
    {
        dumpMessages();
        throw tgException("unable to load pipeline resource");
    }
    else
    {
        if(_pipeline) h3dUnloadResource(_pipeline);
        _pipeline = res;

        Viewer::newCamera(res);
        dumpMessages();
    }
}
예제 #5
0
파일: h3d.cpp 프로젝트: cewbost/texgen
void setShader(const char* buffer, size_t size)
{
    char name[64] = "";
    snprintf(name, 64, "_res%i", _res_loaded++);
    H3DRes res = h3dAddResource(H3DResTypes::Shader, name, 0);
    if(!h3dLoadResource(res, buffer, size))
    {
        dumpMessages();
        throw tgException("unable to load shader resource");
    }
    else
    {
        if(_shader) h3dUnloadResource(_shader);
        _shader = res;

        _mat_builder->setShader(name);
        _mat_builder->build();
        dumpMessages();
    }
}
예제 #6
0
파일: h3d.cpp 프로젝트: cewbost/texgen
void setGeo(const char* buffer, size_t size)
{
    char name[64] = "";
    snprintf(name, 64, "_res%i", _res_loaded++);
    H3DRes res = h3dAddResource(H3DResTypes::Geometry, name, 0);
    if(!h3dLoadResource(res, buffer, size))
    {
        dumpMessages();
        throw tgException("unable to load shader resource");
    }
    else
    {
        if(_geometry) h3dUnloadResource(_geometry);
        _geometry = res;

        if(_geometry != 0 && _shader != 0)
            Viewer::newModel(_geometry, _mat_builder->getRes());
        dumpMessages();
    }
}
예제 #7
0
파일: h3d.cpp 프로젝트: cewbost/texgen
void setGeo(
    std::vector<float> verts,
    std::vector<float> normals,
    std::vector<float> tangents,
    std::vector<float> binormals,
    std::vector<float> texcoords1,
    std::vector<float> texcoords2,
    std::vector<unsigned> indices,
    bool get_tanspace)
{
    if(indices.size() <= 0)
        throw tgException("no triangle indices supplied");
    else if(indices.size() % 3 != 0)
        throw tgException("triangle indices must come in packs of three");

    unsigned num_verts = verts.size();
    if(num_verts <= 0)
        throw tgException("no vertices supplied");
    else if(num_verts % 3 != 0)
        throw tgException("vertices must have three components each");
    num_verts /= 3;

    std::unique_ptr<int16_t[]> norms, tangs, binorms;
    float *tex1, *tex2;

    if(normals.empty())
    {
        norms = nullptr;
        tangs = nullptr;
        binorms = nullptr;
    }
    else if(normals.size() != num_verts * 3)
        throw tgException("number of normals does not match number of vertices");
    else
    {
        norms.reset(new int16_t[num_verts * 3]);
        for(unsigned i = 0; i < num_verts * 3; ++i)
        {
            norms[i] = (int16_t)(normals[i] * std::numeric_limits<int16_t>::max());
        }

        if(tangents.empty())
            tangs = nullptr;
        else if(tangents.size() != num_verts * 3)
            throw tgException("number of tangents does not match number of vertices");
        else
        {
            tangs.reset(new int16_t[num_verts * 3]);
            for(unsigned i = 0; i < num_verts * 3; ++i)
            {
                tangs[i] = (int16_t)(tangents[i] * std::numeric_limits<int16_t>::max());
            }
        }

        if(binormals.empty())
            binorms = nullptr;
        else if(binormals.size() != num_verts * 3)
            throw tgException("number of binormals does not match number of vertices");
        else
        {
            binorms.reset(new int16_t[num_verts * 3]);
            for(unsigned i = 0; i < num_verts * 3; ++i)
            {
                binorms[i] = (int16_t)(binormals[i] * std::numeric_limits<int16_t>::max());
            }
        }

        if((bool)binorms != (bool)tangs && get_tanspace)
        {
            if((bool)tangs)
            {
                binorms.reset(new int16_t[num_verts * 3]);
                for(unsigned i = 0; i < num_verts * 3; i += 3)
                {
                    Eigen::Vector3f norm(normals[i], normals[i + 1], normals[i + 2]);
                    Eigen::Vector3f tang(tangents[i], tangents[i + 1], tangents[i + 2]);
                    Eigen::Vector3f bin = norm.cross(tang);
                    binorms[i] = (int16_t)(bin[0] * std::numeric_limits<int16_t>::max());
                    binorms[i + 1] = (int16_t)(bin[1] * std::numeric_limits<int16_t>::max());
                    binorms[i + 2] = (int16_t)(bin[2] * std::numeric_limits<int16_t>::max());
                }
            }
            else
            {
                tangs.reset(new int16_t[num_verts * 3]);
                for(unsigned i = 0; i < num_verts * 3; i += 3)
                {
                    Eigen::Vector3f norm(normals[i], normals[i + 1], normals[i + 2]);
                    Eigen::Vector3f bin(binormals[i], binormals[i + 1], binormals[i + 2]);
                    Eigen::Vector3f tang = bin.cross(norm);
                    tangs[i] = (int16_t)(tang[0] * std::numeric_limits<int16_t>::max());
                    tangs[i + 1] = (int16_t)(tang[1] * std::numeric_limits<int16_t>::max());
                    tangs[i + 2] = (int16_t)(tang[2] * std::numeric_limits<int16_t>::max());
                }
            }
        }
    }

    if(texcoords1.empty())
        tex1 = nullptr;
    else if(texcoords1.size() != num_verts * 2)
        throw tgException(
            "number if texcoords stream 1 does not match number of vertices");
    else tex1 = texcoords1.data();

    if(texcoords2.empty())
        tex2 = nullptr;
    else if(texcoords2.size() != num_verts * 2)
        throw tgException(
            "number if texcoords stream 2 does not match number of vertices");
    else tex2 = texcoords2.data();

    H3DRes res;
    try
    {
        res = _makeGeometry(num_verts, verts.data(), norms.get(), tangs.get(),
                            binorms.get(), tex1, tex2, indices.size() / 3, indices.data());
    }
    catch(...)
    {
        dumpMessages();
        throw;
    }

    if(_geometry) h3dUnloadResource(_geometry);
    _geometry = res;

    if(_geometry != 0 && _shader != 0)
        Viewer::newModel(_geometry, _mat_builder->getRes());
    dumpMessages();
}