コード例 #1
0
ファイル: inputbinder.cpp プロジェクト: pangoo/appleseed
void InputBinder::bind_texture_instance_to_input(
    const TextureInstanceContainer& texture_instances,
    const UniqueID                  assembly_uid,
    const char*                     entity_type,
    const char*                     entity_name,
    const char*                     param_value,
    InputArray::iterator&           input)
{
    const TextureInstance* texture_instance = texture_instances.get_by_name(param_value);
    assert(texture_instance);

    try
    {
        input.bind(
            new TextureSource(
                assembly_uid,
                *texture_instance));
    }
    catch (const exception& e)
    {
        RENDERER_LOG_ERROR(
            "while defining %s \"%s\", failed to bind \"%s\" to input \"%s\" (%s).",
            entity_type,
            entity_name,
            param_value,
            input.name(),
            e.what());

        ++m_error_count;
    }
}
コード例 #2
0
void InputBinder::bind_color_to_input(
    const ColorContainer&           colors,
    const char*                     param_value,
    InputArray::iterator&           input)
{
    const ColorEntity* color_entity = colors.get_by_name(param_value);
    assert(color_entity);

    input.bind(new ColorSource(*color_entity, input.format()));
}
コード例 #3
0
ファイル: inputbinder.cpp プロジェクト: pangoo/appleseed
bool InputBinder::try_bind_scene_entity_to_input(
    const Scene&                    scene,
    const SymbolTable&              scene_symbols,
    const char*                     entity_type,
    const char*                     entity_name,
    const char*                     param_value,
    InputArray::iterator&           input)
{
    if (input.format() == InputFormatEntity)
    {
        #define BIND(symbol, collection)                        \
            case symbol:                                        \
              input.bind(collection.get_by_name(param_value));  \
              return true

        switch (scene_symbols.lookup(param_value))
        {
          BIND(SymbolTable::SymbolColor, scene.colors());
          BIND(SymbolTable::SymbolTexture, scene.textures());
          BIND(SymbolTable::SymbolTextureInstance, scene.texture_instances());
#ifdef APPLESEED_WITH_OSL
          BIND(SymbolTable::SymbolShaderGroup, scene.shader_groups());
#endif
          BIND(SymbolTable::SymbolEnvironmentEDF, scene.environment_edfs());
          BIND(SymbolTable::SymbolEnvironmentShader, scene.environment_shaders());
        }

        #undef BIND
    }
    else
    {
        switch (scene_symbols.lookup(param_value))
        {
          case SymbolTable::SymbolColor:
            bind_color_to_input(
                scene.colors(),
                param_value,
                input);
            return true;

          case SymbolTable::SymbolTextureInstance:
            bind_texture_instance_to_input(
                scene.texture_instances(),
                ~0,                 // the parent is the scene, not an assembly
                entity_type,
                entity_name,
                param_value,
                input);
            return true;
        }
    }

    return false;
}
コード例 #4
0
ファイル: inputbinder.cpp プロジェクト: willzhou/appleseed
void InputBinder::bind_assembly_entity_to_input(
    const Scene&                    scene,
    const SymbolTable&              scene_symbols,
    const Assembly&                 assembly,
    const SymbolTable&              assembly_symbols,
    const char*                     entity_type,
    const char*                     entity_name,
    const char*                     param_value,
    InputArray::iterator&           input)
{
    switch (assembly_symbols.lookup(param_value))
    {
      case SymbolTable::SymbolColor:
        bind_color_to_input(
            assembly.colors(),
            param_value,
            input);
        break;

      case SymbolTable::SymbolTextureInstance:
        bind_texture_instance_to_input(
            assembly.textures(),
            assembly.texture_instances(),
            assembly.get_uid(),
            entity_type,
            entity_name,
            param_value,
            input);
        break;

      case SymbolTable::SymbolNotFound:
        // No entity with this name was found in this scope.
        // Attempt to bind the input to a scene entity.
        bind_scene_entity_to_input(
            scene,
            scene_symbols,
            entity_type,
            entity_name,
            param_value,
            input);
        break;

      default:
        RENDERER_LOG_ERROR(
            "while defining %s \"%s\": cannot bind \"%s\" to parameter \"%s\".",
            entity_type,
            entity_name,
            param_value,
            input.name());
        ++m_error_count;
        break;
    }
}
コード例 #5
0
ファイル: inputbinder.cpp プロジェクト: willzhou/appleseed
void InputBinder::bind_texture_instance_to_input(
    const TextureContainer&         textures,
    const TextureInstanceContainer& texture_instances,
    const UniqueID                  assembly_uid,
    const char*                     entity_type,
    const char*                     entity_name,
    const char*                     param_value,
    InputArray::iterator&           input)
{
    const TextureInstance* texture_instance = texture_instances.get_by_name(param_value);
    assert(texture_instance);

    const size_t texture_index = texture_instance->get_texture_index();
    assert(texture_index != ~0);

    Texture* texture = textures.get_by_index(texture_index);
    assert(texture);

    try
    {
        input.bind(
            new TextureSource(
                assembly_uid,
                *texture_instance,
                texture->properties()));
    }
    catch (const exception& e)
    {
        RENDERER_LOG_ERROR(
            "while defining %s \"%s\", while binding \"%s\" to parameter \"%s\": %s.",
            entity_type,
            entity_name,
            param_value,
            input.name(),
            e.what());
        ++m_error_count;
    }
}
コード例 #6
0
ファイル: inputbinder.cpp プロジェクト: pangoo/appleseed
bool InputBinder::try_bind_scalar_to_input(
    const string&                   param_value,
    InputArray::iterator&           input) const
{
    try
    {
        const double value = from_string<double>(param_value);
        input.bind(new ScalarSource(value));
        return true;
    }
    catch (const ExceptionStringConversionError&)
    {
        return false;
    }
}
コード例 #7
0
ファイル: inputbinder.cpp プロジェクト: willzhou/appleseed
void InputBinder::bind_scene_entity_to_input(
    const Scene&                    scene,
    const SymbolTable&              scene_symbols,
    const char*                     entity_type,
    const char*                     entity_name,
    const char*                     param_value,
    InputArray::iterator&           input)
{
    switch (scene_symbols.lookup(param_value))
    {
      case SymbolTable::SymbolColor:
        bind_color_to_input(
            scene.colors(),
            param_value,
            input);
        break;

      case SymbolTable::SymbolTextureInstance:
        bind_texture_instance_to_input(
            scene.textures(),
            scene.texture_instances(),
            ~0,                     // the parent is the scene, not an assembly
            entity_type,
            entity_name,
            param_value,
            input);
        break;

      default:
        RENDERER_LOG_ERROR(
            "while defining %s \"%s\": cannot bind \"%s\" to parameter \"%s\".",
            entity_type,
            entity_name,
            param_value,
            input.name());
        ++m_error_count;
        break;
    }
}
コード例 #8
0
ファイル: inputbinder.cpp プロジェクト: pangoo/appleseed
bool InputBinder::try_bind_assembly_entity_to_input(
    const Scene&                    scene,
    const SymbolTable&              scene_symbols,
    const Assembly&                 assembly,
    const SymbolTable&              assembly_symbols,
    const char*                     entity_type,
    const char*                     entity_name,
    const char*                     param_value,
    InputArray::iterator&           input)
{
    if (input.format() == InputFormatEntity)
    {
        #define BIND(symbol, collection)                        \
            case symbol:                                        \
              input.bind(collection.get_by_name(param_value));  \
              return true

        switch (assembly_symbols.lookup(param_value))
        {
          BIND(SymbolTable::SymbolColor, assembly.colors());
          BIND(SymbolTable::SymbolTexture, assembly.textures());
          BIND(SymbolTable::SymbolTextureInstance, assembly.texture_instances());
          BIND(SymbolTable::SymbolBSDF, assembly.bsdfs());
          BIND(SymbolTable::SymbolBSSRDF, assembly.bssrdfs());
          BIND(SymbolTable::SymbolEDF, assembly.edfs());
#ifdef APPLESEED_WITH_OSL
          BIND(SymbolTable::SymbolShaderGroup, assembly.shader_groups());
#endif
          BIND(SymbolTable::SymbolSurfaceShader, assembly.surface_shaders());
          BIND(SymbolTable::SymbolMaterial, assembly.materials());
          BIND(SymbolTable::SymbolLight, assembly.lights());
          BIND(SymbolTable::SymbolObject, assembly.objects());
          BIND(SymbolTable::SymbolObjectInstance, assembly.object_instances());
        }

        #undef BIND
    }
    else
    {
        switch (assembly_symbols.lookup(param_value))
        {
          case SymbolTable::SymbolColor:
            bind_color_to_input(
                assembly.colors(),
                param_value,
                input);
            return true;

          case SymbolTable::SymbolTextureInstance:
            bind_texture_instance_to_input(
                assembly.texture_instances(),
                assembly.get_uid(),
                entity_type,
                entity_name,
                param_value,
                input);
            return true;
        }
    }

    return false;
}