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); } }
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); }