Пример #1
0
void EntityMap::insert(auto_release_ptr<Entity> entity)
{
    // Retrieve the entity.
    Entity* entity_ptr = entity.release();
    assert(entity_ptr);

    // The entity shouldn't already be in the container.
    assert(impl->m_storage.find(entity_ptr->get_uid()) == impl->m_storage.end());
    assert(impl->m_index.find(entity_ptr->get_name()) == impl->m_index.end());

    // Insert the entity into the container.
    impl->m_storage[entity_ptr->get_uid()] = entity_ptr;
    impl->m_index[entity_ptr->get_name()] = entity_ptr;
}
Пример #2
0
size_t EntityVector::insert(auto_release_ptr<Entity> entity)
{
    // Retrieve the entity.
    Entity* entity_ptr = entity.release();
    assert(entity_ptr);

    // The entity shouldn't already be in the container.
    assert(impl->m_id_index.find(entity_ptr->get_uid()) == impl->m_id_index.end());
    assert(impl->m_name_index.find(entity_ptr->get_name()) == impl->m_name_index.end());

    // Insert the entity into the container.
    const size_t entity_index = impl->m_storage.size();
    impl->m_storage.push_back(entity_ptr);
    impl->m_id_index[entity_ptr->get_uid()] = entity_index;
    impl->m_name_index[entity_ptr->get_name()] = entity_index;

    // Link the entity to its parent.
    entity_ptr->set_parent(m_parent);

    return entity_index;
}
Пример #3
0
    // Initialize OSL's shading system.
    bool initialize_osl_shading_system(
        TextureStore&               texture_store,
        IAbortSwitch&               abort_switch)
    {
        // Construct a search paths string from the project's search paths.
        const string project_search_paths =
            to_string(m_project.search_paths().to_string_reversed(SearchPaths::osl_path_separator()));

        // Initialize OIIO.
        const size_t texture_cache_size_bytes =
            m_params.child("texture_store").get_optional<size_t>(
                "max_size",
                TextureStore::get_default_size());
        RENDERER_LOG_INFO(
            "setting oiio texture cache size to %s.",
            pretty_size(texture_cache_size_bytes).c_str());
        const float texture_cache_size_mb =
            static_cast<float>(texture_cache_size_bytes) / (1024 * 1024);
        m_texture_system->attribute("max_memory_MB", texture_cache_size_mb);

        // Set OIIO search paths.
        string prev_oiio_search_path;
        m_texture_system->getattribute("searchpath", prev_oiio_search_path);
        if (prev_oiio_search_path != project_search_paths)
        {
            RENDERER_LOG_INFO("setting oiio search paths to %s", project_search_paths.c_str());
            m_texture_system->invalidate_all(true);
            m_texture_system->attribute("searchpath", project_search_paths);
        }

        // Also use the project search paths to look for OpenImageIO plugins.
        m_texture_system->attribute("plugin_searchpath", project_search_paths);

        // Initialize OSL.
        m_renderer_services->initialize(texture_store);

        // Set OSL search paths.
        string prev_osl_search_paths;
        m_shading_system->getattribute("searchpath:shader", prev_osl_search_paths);
        if (prev_osl_search_paths != project_search_paths)
        {
            RENDERER_LOG_INFO("setting osl shader search paths to %s", project_search_paths.c_str());
            m_project.get_scene()->release_optimized_osl_shader_groups();
            m_shading_system->attribute("searchpath:shader", project_search_paths);
        }

        // Initialize the shader compiler, if the OSL headers are found.
        if (m_resource_search_paths.exist("stdosl.h"))
        {
            const APIString stdosl_path = m_resource_search_paths.qualify("stdosl.h");
            RENDERER_LOG_INFO("found OSL headers in %s", stdosl_path.c_str());
            m_osl_compiler = ShaderCompilerFactory::create(stdosl_path.c_str());
        }
        else
            RENDERER_LOG_INFO("OSL headers not found.");

        // Re-optimize shader groups that need updating.
        return
            m_project.get_scene()->create_optimized_osl_shader_groups(
                *m_shading_system,
                m_osl_compiler.get(),
                &abort_switch);
    }
Пример #4
0
    void add_cube(
        Assembly&           assembly,
        const size_t        ix,
        const size_t        iy,
        const double        fx,
        const double        fz,
        const Color3b&      color,
        const Transformd&   transform) override
    {
        // Push vertices.
        const size_t base_vertex_index = m_mesh->get_vertex_count();
        for (size_t i = 0; i < m_cube->get_vertex_count(); ++i)
        {
            m_mesh->push_vertex(
                transform.point_to_parent(m_cube->get_vertex(i)));
        }

        // Push normals.
        const size_t base_vertex_normal_index = m_mesh->get_vertex_normal_count();
        for (size_t i = 0; i < m_cube->get_vertex_normal_count(); ++i)
        {
            m_mesh->push_vertex_normal(
                normalize(
                    transform.normal_to_parent(m_cube->get_vertex_normal(i))));
        }

        // Push texture coordinates.
        const size_t tex_coords_index =
            m_mesh->push_tex_coords(
                GVector2(static_cast<float>(fx), static_cast<float>(1.0 - fz)));

        // Push triangles.
        for (size_t i = 0; i < m_cube->get_triangle_count(); ++i)
        {
            Triangle triangle = m_cube->get_triangle(i);
            triangle.m_v0 += static_cast<uint32>(base_vertex_index);
            triangle.m_v1 += static_cast<uint32>(base_vertex_index);
            triangle.m_v2 += static_cast<uint32>(base_vertex_index);
            triangle.m_n0 += static_cast<uint32>(base_vertex_normal_index);
            triangle.m_n1 += static_cast<uint32>(base_vertex_normal_index);
            triangle.m_n2 += static_cast<uint32>(base_vertex_normal_index);
            triangle.m_a0 = triangle.m_a1 = triangle.m_a2 = static_cast<uint32>(tex_coords_index);
            m_mesh->push_triangle(triangle);
        }
    }
Пример #5
0
    void initialize_assembly(
        Project&            project,
        Assembly&           assembly,
        const size_t        image_width,
        const size_t        image_height) override
    {
        assembly.textures().insert(
            DiskTexture2dFactory().create(
                "cubes_texture",
                ParamArray()
                    .insert("filename", "heightfield.png")
                    .insert("color_space", "srgb"),
                project.search_paths()));

        assembly.texture_instances().insert(
            TextureInstanceFactory::create(
                "cubes_texture_instance",
                ParamArray()
                    .insert("filtering_mode", "nearest")
                    .insert("addressing_mode", "wrap"),
                "cubes_texture"));

        assembly.bsdfs().insert(
            DisneyBRDFFactory().create(
                "cubes_brdf",
                ParamArray()
                    .insert("anisotropic", 0.0)
                    .insert("base_color", "cubes_texture_instance")
                    .insert("clearcoat", 1.0)
                    .insert("clearcoat_gloss", 0.9)
                    .insert("metallic", 0.0)
                    .insert("roughness", 0.3)
                    .insert("sheen", 0.0)
                    .insert("sheen_tint", 0.0)
                    .insert("specular", 0.9)
                    .insert("specular_tint", 1.0)
                    .insert("subsurface", 1.0)));

        assembly.surface_shaders().insert(
            PhysicalSurfaceShaderFactory().create(
                "physical_surface_shader",
                ParamArray()));

        assembly.materials().insert(
            GenericMaterialFactory().create(
                "cubes_material",
                ParamArray()
                    .insert("surface_shader", "physical_surface_shader")
                    .insert("bsdf", "cubes_brdf")));

        // Load the cube mesh object from disk.
        MeshObjectArray objects;
        MeshObjectReader::read(
            project.search_paths(),
            "cube",
            ParamArray()
                .insert("filename", "cube.obj"),
            objects);
        assert(objects.size() == 1);
        m_cube.reset(objects[0]);

        // Create the baked mesh object.
        m_mesh = MeshObjectFactory().create("cubes", ParamArray());

        // Reserve memory into the baked mesh object.
        const size_t cube_count = image_width * image_height;
        m_mesh->reserve_vertices(m_cube->get_vertex_count() * cube_count);
        m_mesh->reserve_vertex_normals(m_cube->get_vertex_normal_count() * cube_count);
        m_mesh->reserve_tex_coords(cube_count);
        m_mesh->reserve_triangles(m_cube->get_triangle_count() * cube_count);
    }