Ejemplo n.º 1
0
void BlenderSync::sync_camera(BL::RenderSettings& b_render,
                              BL::Object& b_override,
                              int width, int height,
                              const char *viewname)
{
	BlenderCamera bcam;
	blender_camera_init(&bcam, b_render);

	/* pixel aspect */
	bcam.pixelaspect.x = b_render.pixel_aspect_x();
	bcam.pixelaspect.y = b_render.pixel_aspect_y();
	bcam.shuttertime = b_render.motion_blur_shutter();

	BL::CurveMapping b_shutter_curve(b_render.motion_blur_shutter_curve());
	curvemapping_to_array(b_shutter_curve, bcam.shutter_curve, RAMP_TABLE_SIZE);

	PointerRNA cscene = RNA_pointer_get(&b_scene.ptr, "cycles");
	bcam.motion_position =
	        (Camera::MotionPosition)get_enum(cscene,
	                                         "motion_blur_position",
	                                         Camera::MOTION_NUM_POSITIONS,
	                                         Camera::MOTION_POSITION_CENTER);
	bcam.rolling_shutter_type =
		(Camera::RollingShutterType)get_enum(cscene,
		                                     "rolling_shutter_type",
		                                     Camera::ROLLING_SHUTTER_NUM_TYPES,
		                                     Camera::ROLLING_SHUTTER_NONE);
	bcam.rolling_shutter_duration = RNA_float_get(&cscene, "rolling_shutter_duration");

	/* border */
	if(b_render.use_border()) {
		bcam.border.left = b_render.border_min_x();
		bcam.border.right = b_render.border_max_x();
		bcam.border.bottom = b_render.border_min_y();
		bcam.border.top = b_render.border_max_y();
	}

	/* camera object */
	BL::Object b_ob = b_scene.camera();

	if(b_override)
		b_ob = b_override;

	if(b_ob) {
		BL::Array<float, 16> b_ob_matrix;
		blender_camera_from_object(&bcam, b_engine, b_ob);
		b_engine.camera_model_matrix(b_ob, bcam.use_spherical_stereo, b_ob_matrix);
		bcam.matrix = get_transform(b_ob_matrix);
	}

	/* sync */
	Camera *cam = scene->camera;
	blender_camera_sync(cam, &bcam, width, height, viewname);
}
Ejemplo n.º 2
0
 options_iterate(curr_options, poption) {
   switch (option_type(poption)) {
   case OT_BOOLEAN:
     option_bool_set(poption, get_bool(poption));
     break;
   case OT_INTEGER:
     option_int_set(poption, get_int(poption));
     break;
   case OT_STRING:
     option_str_set(poption, get_string(poption));
     break;
   case OT_ENUM:
     option_enum_set_int(poption, get_enum(poption));
     break;
   case OT_BITWISE:
     option_bitwise_set(poption, get_bitwise(poption));
     break;
   case OT_FONT:
     option_font_set(poption, get_button_font(poption));
     break;
   case OT_COLOR:
     option_color_set(poption, get_color(poption));
     break;
   case OT_VIDEO_MODE:
     log_error("Option type %s (%d) not supported yet.",
               option_type_name(option_type(poption)),
               option_type(poption));
     break;
   }
 } options_iterate_end;
Ejemplo n.º 3
0
 T get( const field_desc_type *fld ) const
 {
     switch(fld->cpp_type( )) {
     case field_desc_type::CPPTYPE_INT32:
         return boost::lexical_cast<T>(get_int32(fld));
     case field_desc_type::CPPTYPE_INT64:
         return boost::lexical_cast<T>(get_int64(fld));
     case field_desc_type::CPPTYPE_UINT32:
         return boost::lexical_cast<T>(get_uint32(fld));
     case field_desc_type::CPPTYPE_UINT64:
         return boost::lexical_cast<T>(get_uint64(fld));
     case field_desc_type::CPPTYPE_FLOAT:
         return boost::lexical_cast<T>(get_float(fld));
     case field_desc_type::CPPTYPE_DOUBLE:
         return boost::lexical_cast<T>(get_double(fld));
     case field_desc_type::CPPTYPE_ENUM:
         return boost::lexical_cast<T>(get_enum(fld)->number());
     case field_desc_type::CPPTYPE_STRING:
         return boost::lexical_cast<T>(get_string(fld));
     case field_desc_type::CPPTYPE_BOOL:
         return boost::lexical_cast<T>(get_bool(fld));
     case field_desc_type::CPPTYPE_MESSAGE:
         throw std::bad_cast( );
     default:
         return T( );
     }
 }
Ejemplo n.º 4
0
static VolumeInterpolation get_volume_interpolation(PointerRNA& ptr)
{
	return (VolumeInterpolation)get_enum(ptr,
	                                     "volume_interpolation",
	                                     VOLUME_NUM_INTERPOLATION,
	                                     VOLUME_INTERPOLATION_LINEAR);
}
Ejemplo n.º 5
0
static VolumeSampling get_volume_sampling(PointerRNA& ptr)
{
	return (VolumeSampling)get_enum(ptr,
	                                "volume_sampling",
	                                VOLUME_NUM_SAMPLING,
	                                VOLUME_SAMPLING_DISTANCE);
}
bool FSkookumScriptEditor::is_property_type_supported_and_known(UProperty * var_p) const
  {
  if (!is_property_type_supported(var_p))
    {
    return false;
    }

  UObjectPropertyBase * object_var_p = Cast<UObjectPropertyBase>(var_p);
  if (object_var_p && (!object_var_p->PropertyClass || !get_runtime()->is_static_class_known_to_skookum(object_var_p->PropertyClass)))
    {
    return false;
    }

  UStructProperty * struct_var_p = Cast<UStructProperty>(var_p);
  if (struct_var_p && (!struct_var_p->Struct || (get_skookum_struct_type(struct_var_p->Struct) == SkTypeID_UStruct && !get_runtime()->is_static_struct_known_to_skookum(struct_var_p->Struct))))
    {
    return false;
    }

  UArrayProperty * array_var_p = Cast<UArrayProperty>(var_p);
  if (array_var_p && (!array_var_p->Inner || !is_property_type_supported_and_known(array_var_p->Inner)))
    {
    return false;
    }

  UEnum * enum_p = get_enum(var_p);
  if (enum_p && !get_runtime()->is_static_enum_known_to_skookum(enum_p))
    {
    return false;
    }

  return true;
  }
Ejemplo n.º 7
0
void BlenderSync::sync_materials(bool update_all)
{
	shader_map.set_default(scene->shaders[scene->default_surface]);

	/* material loop */
	BL::BlendData::materials_iterator b_mat;

	for(b_data.materials.begin(b_mat); b_mat != b_data.materials.end(); ++b_mat) {
		Shader *shader;

		/* test if we need to sync */
		if(shader_map.sync(&shader, *b_mat) || update_all) {
			ShaderGraph *graph = new ShaderGraph();

			shader->name = b_mat->name().c_str();
			shader->pass_id = b_mat->pass_index();

			/* create nodes */
			if(b_mat->use_nodes() && b_mat->node_tree()) {
				BL::ShaderNodeTree b_ntree(b_mat->node_tree());

				add_nodes(scene, b_engine, b_data, b_scene, !preview, graph, b_ntree);
			}
			else {
				ShaderNode *closure, *out;

				closure = graph->add(new DiffuseBsdfNode());
				closure->input("Color")->value = get_float3(b_mat->diffuse_color());
				out = graph->output();

				graph->connect(closure->output("BSDF"), out->input("Surface"));
			}

			/* settings */
			PointerRNA cmat = RNA_pointer_get(&b_mat->ptr, "cycles");
			shader->use_mis = get_boolean(cmat, "sample_as_light");
			shader->use_transparent_shadow = get_boolean(cmat, "use_transparent_shadow");
			shader->heterogeneous_volume = !get_boolean(cmat, "homogeneous_volume");
			shader->volume_sampling_method = (VolumeSampling)get_enum(cmat, "volume_sampling");
			shader->volume_interpolation_method = (VolumeInterpolation)get_enum(cmat, "volume_interpolation");

			shader->set_graph(graph);
			shader->tag_update(scene);
		}
	}
}
Ejemplo n.º 8
0
static int new_pref(lua_State* L, pref_type_t type) {
    const gchar* label = luaL_optstring(L,1,NULL);
    const gchar* descr = luaL_optstring(L,3,"");

    Pref pref = (wslua_pref_t *)g_malloc(sizeof(wslua_pref_t));
    pref->name = NULL;
    pref->label = label ? g_strdup(label) : NULL;
    pref->desc = g_strdup(descr);
    pref->type = type;
    pref->next = NULL;
    pref->proto = NULL;

    switch(type) {
        case PREF_BOOL: {
            gboolean def = wslua_toboolean(L,2);
            pref->value.b = def;
            break;
        }
        case PREF_UINT: {
            guint32 def = wslua_optgint32(L,2,0);
            pref->value.u = def;
            break;
        }
        case PREF_STRING: {
            gchar* def = g_strdup(luaL_optstring(L,2,""));
            pref->value.s = def;
            break;
        }
        case PREF_ENUM: {
            guint32 def = wslua_optgint32(L,2,0);
            enum_val_t *enum_val = get_enum(L,4);
            gboolean radio = wslua_toboolean(L,5);
            pref->value.e = def;
            pref->info.enum_info.enumvals = enum_val;
            pref->info.enum_info.radio_buttons = radio;
            break;
        }
        case PREF_RANGE: {
            range_t *range = get_range(L,2,4);
            guint32 max = wslua_optgint32(L,4,0);
            pref->value.r = range;
            pref->info.max_value = max;
            break;
        }
        case PREF_STATIC_TEXT: {
            /* This is just a static text. */
            break;
        }
        default:
            g_assert_not_reached();
            break;

    }

    pushPref(L,pref);
    return 1;
}
Ejemplo n.º 9
0
EnumCmp::EnumCmp(char const *enum_name) throw()
  : m_enum_id(BADNODE)
{
  // find the enum by its (non null) name
  if(enum_name != NULL)
  {
    m_enum_id = get_enum(enum_name);

    if(m_enum_id != BADNODE)
    {
      for_all_consts(m_enum_id, *this);
    }
  }
}
Ejemplo n.º 10
0
//--------------------------------------------------------------------------
static tid_t get_class_struct_flags_enum()
{
  static const char enum_name[] = "ClassFlags";
  enum_t id = get_enum(enum_name);
  if ( id != BADNODE ) return id;
  id = add_enum(BADADDR, enum_name, hexflag());
  set_enum_bf(id, true);
  add_const(id, "CLASSF_HAS_DEFAULT",     (1<<0), (1<<0));
  add_const(id, "CLASSF_MASTER_CLASS",    (1<<1), (1<<1));
  add_const(id, "CLASSF_VARIANT_CLASS",   (1<<2), (1<<2));
  add_const(id, "CLASSF_DISCARD_ON_SAVE", (1<<3), (1<<3));
  add_const(id, "CLASSF_NEVER_SAVED",     (1<<4), (1<<4));
  add_const(id, "CLASSF_HAS_RELOC",       (1<<5), (1<<5));
  add_const(id, "CLASSF_C_HANDLERS",      (1<<6), (1<<6));
  return id;
}
Ejemplo n.º 11
0
void BlenderSync::sync_background_light(bool use_portal)
{
  BL::World b_world = b_scene.world();

  if (b_world) {
    PointerRNA cscene = RNA_pointer_get(&b_scene.ptr, "cycles");
    PointerRNA cworld = RNA_pointer_get(&b_world.ptr, "cycles");

    enum SamplingMethod { SAMPLING_NONE = 0, SAMPLING_AUTOMATIC, SAMPLING_MANUAL, SAMPLING_NUM };
    int sampling_method = get_enum(cworld, "sampling_method", SAMPLING_NUM, SAMPLING_AUTOMATIC);
    bool sample_as_light = (sampling_method != SAMPLING_NONE);

    if (sample_as_light || use_portal) {
      /* test if we need to sync */
      Light *light;
      ObjectKey key(b_world, 0, b_world);

      if (light_map.sync(&light, b_world, b_world, key) || world_recalc ||
          b_world.ptr.data != world_map) {
        light->type = LIGHT_BACKGROUND;
        if (sampling_method == SAMPLING_MANUAL) {
          light->map_resolution = get_int(cworld, "sample_map_resolution");
        }
        else {
          light->map_resolution = 0;
        }
        light->shader = scene->default_background;
        light->use_mis = sample_as_light;
        light->max_bounces = get_int(cworld, "max_bounces");

        int samples = get_int(cworld, "samples");
        if (get_boolean(cscene, "use_square_samples"))
          light->samples = samples * samples;
        else
          light->samples = samples;

        light->tag_update(scene);
        light_map.set_recalc(b_world);
      }
    }
  }

  world_map = b_world.ptr.data;
  world_recalc = false;
}
Ejemplo n.º 12
0
CUDFProperty::CUDFProperty(char *tname, CUDFPropertyType ttype, CUDFEnums *tenum, char *tident) {
  int lgth = strlen(tname);

  if ((name = (char *)malloc(lgth+1)) == NULL) {
    fprintf(stderr, "error: cannot alloc name for property %s.\n", tname);
    exit(-1);
  }
  strcpy(name, tname);
    
  type_id = ttype;
  required = true;

  enuml = tenum;

  char *defval = get_enum(tenum, tident);
  if (defval == (char *)NULL) {
    fprintf(stderr, "CUDF error: property %s default value can not be %s.\n", tname, tident);
    exit(-1);
  } else
    default_value = new CUDFPropertyValue(this, defval);

}
Ejemplo n.º 13
0
static int new_pref(lua_State* L, pref_type_t type) {
    const gchar* label = luaL_optstring(L,1,NULL);
    const gchar* descr = luaL_optstring(L,3,"");

    Pref pref = (wslua_pref_t *)g_malloc0(sizeof(wslua_pref_t));
    pref->label = g_strdup(label);
    pref->desc = g_strdup(descr);
    pref->type = type;

    switch(type) {
        case PREF_BOOL: {
            gboolean def = wslua_toboolean(L,2);
            pref->value.b = def;
            break;
        }
        case PREF_UINT: {
            guint32 def = wslua_optgint32(L,2,0);
            pref->value.u = def;
            break;
        }
        case PREF_STRING: {
            gchar* def = g_strdup(luaL_optstring(L,2,""));
            /*
             * prefs_register_string_preference() assumes that the
             * variable for the preference points to a static
             * string that is the initial (default) value of the
             * preference.  It makes a g_strdup()ed copy of that
             * string, and assigns a pointer to that string to
             * the variable.
             *
             * Our default string is *not* a static string, it's
             * a g_strdup()ed copy of a string from Lua, so it would
             * be leaked.
             *
             * We save it in info.default_s, as well as setting the
             * initial value of the preference from it, so that we
             * can free it after prefs_register_string_preference()
             * returns.
             *
             * (Would that we were programming in a language where
             * the details of memory management were handled by the
             * compiler and language support....)
             */
            pref->value.s = def;
            pref->info.default_s = def;
            break;
        }
        case PREF_ENUM: {
            guint32 def = wslua_optgint32(L,2,0);
            enum_val_t *enum_val = get_enum(L,4);
            gboolean radio = wslua_toboolean(L,5);
            pref->value.e = def;
            pref->info.enum_info.enumvals = enum_val;
            pref->info.enum_info.radio_buttons = radio;
            break;
        }
        case PREF_RANGE: {
            range_t *range = get_range(L,2,4);
            guint32 max = wslua_optgint32(L,4,0);
            pref->value.r = range;
            pref->info.max_value = max;
            break;
        }
        case PREF_STATIC_TEXT: {
            /* This is just a static text. */
            break;
        }
        default:
            g_assert_not_reached();
            break;

    }

    pushPref(L,pref);
    return 1;
}
Ejemplo n.º 14
0
static void blender_camera_from_object(BlenderCamera *bcam,
                                       BL::RenderEngine& b_engine,
                                       BL::Object& b_ob,
                                       bool skip_panorama = false)
{
	BL::ID b_ob_data = b_ob.data();

	if(b_ob_data.is_a(&RNA_Camera)) {
		BL::Camera b_camera(b_ob_data);
		PointerRNA ccamera = RNA_pointer_get(&b_camera.ptr, "cycles");

		bcam->nearclip = b_camera.clip_start();
		bcam->farclip = b_camera.clip_end();

		switch(b_camera.type())
		{
			case BL::Camera::type_ORTHO:
				bcam->type = CAMERA_ORTHOGRAPHIC;
				break;
			case BL::Camera::type_PANO:
				if(!skip_panorama)
					bcam->type = CAMERA_PANORAMA;
				else
					bcam->type = CAMERA_PERSPECTIVE;
				break;
			case BL::Camera::type_PERSP:
			default:
				bcam->type = CAMERA_PERSPECTIVE;
				break;
		}

		bcam->panorama_type = (PanoramaType)get_enum(ccamera,
		                                             "panorama_type",
		                                             PANORAMA_NUM_TYPES,
		                                             PANORAMA_EQUIRECTANGULAR);

		bcam->fisheye_fov = RNA_float_get(&ccamera, "fisheye_fov");
		bcam->fisheye_lens = RNA_float_get(&ccamera, "fisheye_lens");
		bcam->latitude_min = RNA_float_get(&ccamera, "latitude_min");
		bcam->latitude_max = RNA_float_get(&ccamera, "latitude_max");
		bcam->longitude_min = RNA_float_get(&ccamera, "longitude_min");
		bcam->longitude_max = RNA_float_get(&ccamera, "longitude_max");

		bcam->ortho_scale = b_camera.ortho_scale();

		bcam->lens = b_camera.lens();

		/* allow f/stop number to change aperture_size but still
		 * give manual control over aperture radius */
		int aperture_type = get_enum(ccamera, "aperture_type");

		if(aperture_type == 1) {
			float fstop = RNA_float_get(&ccamera, "aperture_fstop");
			fstop = max(fstop, 1e-5f);

			if(bcam->type == CAMERA_ORTHOGRAPHIC)
				bcam->aperturesize = 1.0f/(2.0f*fstop);
			else
				bcam->aperturesize = (bcam->lens*1e-3f)/(2.0f*fstop);
		}
		else
			bcam->aperturesize = RNA_float_get(&ccamera, "aperture_size");

		bcam->apertureblades = RNA_int_get(&ccamera, "aperture_blades");
		bcam->aperturerotation = RNA_float_get(&ccamera, "aperture_rotation");
		bcam->focaldistance = blender_camera_focal_distance(b_engine, b_ob, b_camera);
		bcam->aperture_ratio = RNA_float_get(&ccamera, "aperture_ratio");

		bcam->shift.x = b_engine.camera_shift_x(b_ob);
		bcam->shift.y = b_camera.shift_y();

		bcam->sensor_width = b_camera.sensor_width();
		bcam->sensor_height = b_camera.sensor_height();

		if(b_camera.sensor_fit() == BL::Camera::sensor_fit_AUTO)
			bcam->sensor_fit = BlenderCamera::AUTO;
		else if(b_camera.sensor_fit() == BL::Camera::sensor_fit_HORIZONTAL)
			bcam->sensor_fit = BlenderCamera::HORIZONTAL;
		else
			bcam->sensor_fit = BlenderCamera::VERTICAL;
	}
	else {
		/* from lamp not implemented yet */
	}
}
Ejemplo n.º 15
0
void BlenderSync::sync_curve_settings()
{
  PointerRNA csscene = RNA_pointer_get(&b_scene.ptr, "cycles_curves");

  CurveSystemManager *curve_system_manager = scene->curve_system_manager;
  CurveSystemManager prev_curve_system_manager = *curve_system_manager;

  curve_system_manager->use_curves = get_boolean(csscene, "use_curves");

  curve_system_manager->primitive = (CurvePrimitiveType)get_enum(
      csscene, "primitive", CURVE_NUM_PRIMITIVE_TYPES, CURVE_LINE_SEGMENTS);
  curve_system_manager->curve_shape = (CurveShapeType)get_enum(
      csscene, "shape", CURVE_NUM_SHAPE_TYPES, CURVE_THICK);
  curve_system_manager->resolution = get_int(csscene, "resolution");
  curve_system_manager->subdivisions = get_int(csscene, "subdivisions");
  curve_system_manager->use_backfacing = !get_boolean(csscene, "cull_backfacing");

  /* Triangles */
  if (curve_system_manager->primitive == CURVE_TRIANGLES) {
    /* camera facing planes */
    if (curve_system_manager->curve_shape == CURVE_RIBBON) {
      curve_system_manager->triangle_method = CURVE_CAMERA_TRIANGLES;
      curve_system_manager->resolution = 1;
    }
    else if (curve_system_manager->curve_shape == CURVE_THICK) {
      curve_system_manager->triangle_method = CURVE_TESSELATED_TRIANGLES;
    }
  }
  /* Line Segments */
  else if (curve_system_manager->primitive == CURVE_LINE_SEGMENTS) {
    if (curve_system_manager->curve_shape == CURVE_RIBBON) {
      /* tangent shading */
      curve_system_manager->line_method = CURVE_UNCORRECTED;
      curve_system_manager->use_encasing = true;
      curve_system_manager->use_backfacing = false;
      curve_system_manager->use_tangent_normal_geometry = true;
    }
    else if (curve_system_manager->curve_shape == CURVE_THICK) {
      curve_system_manager->line_method = CURVE_ACCURATE;
      curve_system_manager->use_encasing = false;
      curve_system_manager->use_tangent_normal_geometry = false;
    }
  }
  /* Curve Segments */
  else if (curve_system_manager->primitive == CURVE_SEGMENTS) {
    if (curve_system_manager->curve_shape == CURVE_RIBBON) {
      curve_system_manager->primitive = CURVE_RIBBONS;
      curve_system_manager->use_backfacing = false;
    }
  }

  if (curve_system_manager->modified_mesh(prev_curve_system_manager)) {
    BL::BlendData::objects_iterator b_ob;

    for (b_data.objects.begin(b_ob); b_ob != b_data.objects.end(); ++b_ob) {
      if (object_is_mesh(*b_ob)) {
        BL::Object::particle_systems_iterator b_psys;
        for (b_ob->particle_systems.begin(b_psys); b_psys != b_ob->particle_systems.end();
             ++b_psys) {
          if ((b_psys->settings().render_type() == BL::ParticleSettings::render_type_PATH) &&
              (b_psys->settings().type() == BL::ParticleSettings::type_HAIR)) {
            BL::ID key = BKE_object_is_modified(*b_ob) ? *b_ob : b_ob->data();
            mesh_map.set_recalc(key);
            object_map.set_recalc(*b_ob);
          }
        }
      }
    }
  }

  if (curve_system_manager->modified(prev_curve_system_manager))
    curve_system_manager->tag_update(scene);
}
Ejemplo n.º 16
0
Mesh *BlenderSync::sync_mesh(BL::Object& b_ob,
                             bool object_updated,
                             bool hide_tris)
{
	/* When viewport display is not needed during render we can force some
	 * caches to be releases from blender side in order to reduce peak memory
	 * footprint during synchronization process.
	 */
	const bool is_interface_locked = b_engine.render() &&
	                                 b_engine.render().use_lock_interface();
	const bool can_free_caches = BlenderSession::headless || is_interface_locked;

	/* test if we can instance or if the object is modified */
	BL::ID b_ob_data = b_ob.data();
	BL::ID key = (BKE_object_is_modified(b_ob))? b_ob: b_ob_data;
	BL::Material material_override = render_layer.material_override;

	/* find shader indices */
	vector<uint> used_shaders;

	BL::Object::material_slots_iterator slot;
	for(b_ob.material_slots.begin(slot); slot != b_ob.material_slots.end(); ++slot) {
		if(material_override) {
			find_shader(material_override, used_shaders, scene->default_surface);
		}
		else {
			BL::ID b_material(slot->material());
			find_shader(b_material, used_shaders, scene->default_surface);
		}
	}

	if(used_shaders.size() == 0) {
		if(material_override)
			find_shader(material_override, used_shaders, scene->default_surface);
		else
			used_shaders.push_back(scene->default_surface);
	}
	
	/* test if we need to sync */
	int requested_geometry_flags = Mesh::GEOMETRY_NONE;
	if(render_layer.use_surfaces) {
		requested_geometry_flags |= Mesh::GEOMETRY_TRIANGLES;
	}
	if(render_layer.use_hair) {
		requested_geometry_flags |= Mesh::GEOMETRY_CURVES;
	}
	Mesh *mesh;

	if(!mesh_map.sync(&mesh, key)) {
		/* if transform was applied to mesh, need full update */
		if(object_updated && mesh->transform_applied);
		/* test if shaders changed, these can be object level so mesh
		 * does not get tagged for recalc */
		else if(mesh->used_shaders != used_shaders);
		else if(requested_geometry_flags != mesh->geometry_flags);
		else {
			/* even if not tagged for recalc, we may need to sync anyway
			 * because the shader needs different mesh attributes */
			bool attribute_recalc = false;

			foreach(uint shader, mesh->used_shaders)
				if(scene->shaders[shader]->need_update_attributes)
					attribute_recalc = true;

			if(!attribute_recalc)
				return mesh;
		}
	}

	/* ensure we only sync instanced meshes once */
	if(mesh_synced.find(mesh) != mesh_synced.end())
		return mesh;
	
	mesh_synced.insert(mesh);

	/* create derived mesh */
	PointerRNA cmesh = RNA_pointer_get(&b_ob_data.ptr, "cycles");

	vector<Mesh::Triangle> oldtriangle = mesh->triangles;
	
	/* compares curve_keys rather than strands in order to handle quick hair
	 * adjustments in dynamic BVH - other methods could probably do this better*/
	vector<float4> oldcurve_keys = mesh->curve_keys;

	mesh->clear();
	mesh->used_shaders = used_shaders;
	mesh->name = ustring(b_ob_data.name().c_str());

	if(requested_geometry_flags != Mesh::GEOMETRY_NONE) {
		/* mesh objects does have special handle in the dependency graph,
		 * they're ensured to have properly updated.
		 *
		 * updating meshes here will end up having derived mesh referencing
		 * freed data from the blender side.
		 */
		if(preview && b_ob.type() != BL::Object::type_MESH)
			b_ob.update_from_editmode();

		bool need_undeformed = mesh->need_attribute(scene, ATTR_STD_GENERATED);
		BL::Mesh b_mesh = object_to_mesh(b_data, b_ob, b_scene, true, !preview, need_undeformed);

		if(b_mesh) {
			if(render_layer.use_surfaces && !hide_tris) {
				if(cmesh.data && experimental && RNA_boolean_get(&cmesh, "use_subdivision"))
					create_subd_mesh(scene, mesh, b_mesh, &cmesh, used_shaders);
				else
					create_mesh(scene, mesh, b_mesh, used_shaders);

				create_mesh_volume_attributes(scene, b_ob, mesh, b_scene.frame_current());
			}

			if(render_layer.use_hair)
				sync_curves(mesh, b_mesh, b_ob, false);

			if(can_free_caches) {
				b_ob.cache_release();
			}

			/* free derived mesh */
			b_data.meshes.remove(b_mesh);
		}
	}
	mesh->geometry_flags = requested_geometry_flags;

	/* displacement method */
	if(cmesh.data) {
		const int method = get_enum(cmesh, "displacement_method");

		if(method == 0 || !experimental)
			mesh->displacement_method = Mesh::DISPLACE_BUMP;
		else if(method == 1)
			mesh->displacement_method = Mesh::DISPLACE_TRUE;
		else
			mesh->displacement_method = Mesh::DISPLACE_BOTH;
	}

	/* tag update */
	bool rebuild = false;

	if(oldtriangle.size() != mesh->triangles.size())
		rebuild = true;
	else if(oldtriangle.size()) {
		if(memcmp(&oldtriangle[0], &mesh->triangles[0], sizeof(Mesh::Triangle)*oldtriangle.size()) != 0)
			rebuild = true;
	}

	if(oldcurve_keys.size() != mesh->curve_keys.size())
		rebuild = true;
	else if(oldcurve_keys.size()) {
		if(memcmp(&oldcurve_keys[0], &mesh->curve_keys[0], sizeof(float4)*oldcurve_keys.size()) != 0)
			rebuild = true;
	}
	
	mesh->tag_update(scene, rebuild);

	return mesh;
}
Ejemplo n.º 17
0
// check if there is a typedef with a given name and equivalent content in the db
// equivalent content means e.g. structures, unions and enums have the same members
// return its ordinal if the typedef is found. (0 otherwise)
uint32 get_equivalent_typedef_ordinal(DieHolder &typedef_holder, uint32 const type_ordinal)
{
  uint32 ordinal = 0;
  char const *typedef_name = typedef_holder.get_name();
  type_t const *type = NULL;
  char const *name = NULL;
  bool ok = get_numbered_type(idati, type_ordinal, &type);

  if(ok)
  {
    type_t const *existing_type = NULL;
    // already an existing type with the same name?
    ok = get_named_type(idati, typedef_name, NTF_TYPE | NTF_NOBASE, &existing_type);

    if(ok)
    {
      // existing type is a typedef?
      if(is_type_typedef(*existing_type))
      {
        // typedef to a structure/union?
        if(is_type_struni(*type))
        {
          name = get_typedef_name(existing_type);

          if(name != NULL)
          {
            tid_t struc_id = get_struc_id(name);

            ok = (struc_id != BADNODE);
            if(ok)
            {
              Dwarf_Off offset = 0;

              ok = diecache.get_type_offset(type_ordinal, &offset);
              if(ok)
              {
                DieHolder structure_holder(typedef_holder.get_dbg(), offset);
                StrucCmp struc_cmp(name);

                ok = struc_cmp.equal(structure_holder);
              }
            }
          }
        }
        // typedef to an enum
        else if(is_type_enum(*type))
        {
          name = get_typedef_name(existing_type);

          if(name != NULL)
          {
            enum_t enum_id = get_enum(name);

            ok = (enum_id != BADNODE);
            if(ok)
            {
              Dwarf_Off offset = 0;

              ok = diecache.get_type_offset(type_ordinal, &offset);
              if(ok)
              {
                DieHolder enumeration_holder(typedef_holder.get_dbg(), offset);
                EnumCmp enum_cmp(name);

                ok = enum_cmp.equal(enumeration_holder);
              }
            }
          }
        }
      }
    }
  }

  if(name != NULL)
  {
    if(ok)
    {
      ordinal = get_type_ordinal(idati, typedef_name);

      DEBUG("found equivalent typedef typedef_name='%s' name='%s' type_ordinal=%u ordinal=%u\n",
            typedef_name, name, type_ordinal, ordinal);
    }
  }

  return ordinal;
}
Ejemplo n.º 18
0
//----------------------------------------------------------------------
static tid_t set_dsp_regs_enum()
{
  static const char enum_name[] = "DSPRegisters";
  enum_t id = get_enum(enum_name);
  if ( id != BADNODE )
    return id;
  id = add_enum(-1, enum_name, hexflag());

  add_enum_member(id, "V0VOLL"  , 0x00);
  add_enum_member(id, "V0VOLR"  , 0x01);
  add_enum_member(id, "V0PL"    , 0x02);
  add_enum_member(id, "V0PH"    , 0x03);
  add_enum_member(id, "V0SRCN"  , 0x04);
  add_enum_member(id, "V0ADSR1" , 0x05);
  add_enum_member(id, "V0ADSR2" , 0x06);
  add_enum_member(id, "V0GAIN"  , 0x07);
  add_enum_member(id, "V0ENVX"  , 0x08);
  add_enum_member(id, "V0OUTX"  , 0x09);

  add_enum_member(id, "V1VOLL"  , 0x10);
  add_enum_member(id, "V1VOLR"  , 0x11);
  add_enum_member(id, "V1PL"    , 0x12);
  add_enum_member(id, "V1PH"    , 0x13);
  add_enum_member(id, "V1SRCN"  , 0x14);
  add_enum_member(id, "V1ADSR1" , 0x15);
  add_enum_member(id, "V1ADSR2" , 0x16);
  add_enum_member(id, "V1GAIN"  , 0x17);
  add_enum_member(id, "V1ENVX"  , 0x18);
  add_enum_member(id, "V1OUTX"  , 0x19);

  add_enum_member(id, "V2VOLL"  , 0x20);
  add_enum_member(id, "V2VOLR"  , 0x21);
  add_enum_member(id, "V2PL"    , 0x22);
  add_enum_member(id, "V2PH"    , 0x23);
  add_enum_member(id, "V2SRCN"  , 0x24);
  add_enum_member(id, "V2ADSR1" , 0x25);
  add_enum_member(id, "V2ADSR2" , 0x26);
  add_enum_member(id, "V2GAIN"  , 0x27);
  add_enum_member(id, "V2ENVX"  , 0x28);
  add_enum_member(id, "V2OUTX"  , 0x29);

  add_enum_member(id, "V3VOLL"  , 0x30);
  add_enum_member(id, "V3VOLR"  , 0x31);
  add_enum_member(id, "V3PL"    , 0x32);
  add_enum_member(id, "V3PH"    , 0x33);
  add_enum_member(id, "V3SRCN"  , 0x34);
  add_enum_member(id, "V3ADSR1" , 0x35);
  add_enum_member(id, "V3ADSR2" , 0x36);
  add_enum_member(id, "V3GAIN"  , 0x37);
  add_enum_member(id, "V3ENVX"  , 0x38);
  add_enum_member(id, "V3OUTX"  , 0x39);

  add_enum_member(id, "V4VOLL"  , 0x40);
  add_enum_member(id, "V4VOLR"  , 0x41);
  add_enum_member(id, "V4PL"    , 0x42);
  add_enum_member(id, "V4PH"    , 0x43);
  add_enum_member(id, "V4SRCN"  , 0x44);
  add_enum_member(id, "V4ADSR1" , 0x45);
  add_enum_member(id, "V4ADSR2" , 0x46);
  add_enum_member(id, "V4GAIN"  , 0x47);
  add_enum_member(id, "V4ENVX"  , 0x48);
  add_enum_member(id, "V4OUTX"  , 0x49);

  add_enum_member(id, "V5VOLL"  , 0x50);
  add_enum_member(id, "V5VOLR"  , 0x51);
  add_enum_member(id, "V5PL"    , 0x52);
  add_enum_member(id, "V5PH"    , 0x53);
  add_enum_member(id, "V5SRCN"  , 0x54);
  add_enum_member(id, "V5ADSR1" , 0x55);
  add_enum_member(id, "V5ADSR2" , 0x56);
  add_enum_member(id, "V5GAIN"  , 0x57);
  add_enum_member(id, "V5ENVX"  , 0x58);
  add_enum_member(id, "V5OUTX"  , 0x59);

  add_enum_member(id, "V6VOLL"  , 0x60);
  add_enum_member(id, "V6VOLR"  , 0x61);
  add_enum_member(id, "V6PL"    , 0x62);
  add_enum_member(id, "V6PH"    , 0x63);
  add_enum_member(id, "V6SRCN"  , 0x64);
  add_enum_member(id, "V6ADSR1" , 0x65);
  add_enum_member(id, "V6ADSR2" , 0x66);
  add_enum_member(id, "V6GAIN"  , 0x67);
  add_enum_member(id, "V6ENVX"  , 0x68);
  add_enum_member(id, "V6OUTX"  , 0x69);

  add_enum_member(id, "V7VOLL"  , 0x70);
  add_enum_member(id, "V7VOLR"  , 0x71);
  add_enum_member(id, "V7PL"    , 0x72);
  add_enum_member(id, "V7PH"    , 0x73);
  add_enum_member(id, "V7SRCN"  , 0x74);
  add_enum_member(id, "V7ADSR1" , 0x75);
  add_enum_member(id, "V7ADSR2" , 0x76);
  add_enum_member(id, "V7GAIN"  , 0x77);
  add_enum_member(id, "V7ENVX"  , 0x78);
  add_enum_member(id, "V7OUTX"  , 0x79);

  add_enum_member(id, "MVOLL"   , 0x0c);
  add_enum_member(id, "MVOLR"   , 0x1c);
  add_enum_member(id, "EVOLL"   , 0x2c);
  add_enum_member(id, "EVOLR"   , 0x3c);
  add_enum_member(id, "KON"     , 0x4c);
  add_enum_member(id, "KOF"     , 0x5c);
  add_enum_member(id, "FLG"     , 0x6c);
  add_enum_member(id, "ENDX"    , 0x7c);
  add_enum_member(id, "EFB"     , 0x0d);
  add_enum_member(id, "PMON"    , 0x2d);
  add_enum_member(id, "NON"     , 0x3d);
  add_enum_member(id, "EON"     , 0x4d);
  add_enum_member(id, "DIR"     , 0x5d);
  add_enum_member(id, "ESA"     , 0x6d);
  add_enum_member(id, "EDL"     , 0x7d);
  add_enum_member(id, "FIR0"    , 0x0f);
  add_enum_member(id, "FIR1"    , 0x1f);
  add_enum_member(id, "FIR2"    , 0x2f);
  add_enum_member(id, "FIR3"    , 0x3f);
  add_enum_member(id, "FIR4"    , 0x4f);
  add_enum_member(id, "FIR5"    , 0x5f);
  add_enum_member(id, "FIR6"    , 0x6f);
  add_enum_member(id, "FIR7"    , 0x7f);

  return id;
}
Ejemplo n.º 19
0
void BlenderSync::sync_world(bool update_all)
{
	Background *background = scene->background;
	Background prevbackground = *background;

	BL::World b_world = b_scene.world();

	if(world_recalc || update_all || b_world.ptr.data != world_map) {
		Shader *shader = scene->shaders[scene->default_background];
		ShaderGraph *graph = new ShaderGraph();

		/* create nodes */
		if(b_world && b_world.use_nodes() && b_world.node_tree()) {
			BL::ShaderNodeTree b_ntree(b_world.node_tree());

			add_nodes(scene, b_engine, b_data, b_scene, !preview, graph, b_ntree);

			/* volume */
			PointerRNA cworld = RNA_pointer_get(&b_world.ptr, "cycles");
			shader->heterogeneous_volume = !get_boolean(cworld, "homogeneous_volume");
			shader->volume_sampling_method = (VolumeSampling)get_enum(cworld, "volume_sampling");
			shader->volume_interpolation_method = (VolumeInterpolation)get_enum(cworld, "volume_interpolation");
		}
		else if(b_world) {
			ShaderNode *closure, *out;

			closure = graph->add(new BackgroundNode());
			closure->input("Color")->value = get_float3(b_world.horizon_color());
			out = graph->output();

			graph->connect(closure->output("Background"), out->input("Surface"));
		}

		if(b_world) {
			/* AO */
			BL::WorldLighting b_light = b_world.light_settings();

			if(b_light.use_ambient_occlusion())
				background->ao_factor = b_light.ao_factor();
			else
				background->ao_factor = 0.0f;

			background->ao_distance = b_light.distance();

			/* visibility */
			PointerRNA cvisibility = RNA_pointer_get(&b_world.ptr, "cycles_visibility");
			uint visibility = 0;

			visibility |= get_boolean(cvisibility, "camera")? PATH_RAY_CAMERA: 0;
			visibility |= get_boolean(cvisibility, "diffuse")? PATH_RAY_DIFFUSE: 0;
			visibility |= get_boolean(cvisibility, "glossy")? PATH_RAY_GLOSSY: 0;
			visibility |= get_boolean(cvisibility, "transmission")? PATH_RAY_TRANSMIT: 0;
			visibility |= get_boolean(cvisibility, "scatter")? PATH_RAY_VOLUME_SCATTER: 0;

			background->visibility = visibility;
		}
		else {
			background->ao_factor = 0.0f;
			background->ao_distance = FLT_MAX;
		}

		shader->set_graph(graph);
		shader->tag_update(scene);
		background->tag_update(scene);
	}

	PointerRNA cscene = RNA_pointer_get(&b_scene.ptr, "cycles");

	/* when doing preview render check for BI's transparency settings,
	 * this is so because Blender's preview render routines are not able
	 * to tweak all cycles's settings depending on different circumstances
	 */
	if(b_engine.is_preview() == false)
		background->transparent = get_boolean(cscene, "film_transparent");
	else
		background->transparent = b_scene.render().alpha_mode() == BL::RenderSettings::alpha_mode_TRANSPARENT;

	background->use_shader = render_layer.use_background_shader;
	background->use_ao = render_layer.use_background_ao;

	if(background->modified(prevbackground))
		background->tag_update(scene);
}