Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenkernel/intern/lamp.c
| Show First 20 Lines • Show All 110 Lines • ▼ Show 20 Lines | Lamp *BKE_lamp_add(Main *bmain, const char *name) | ||||
| la = BKE_libblock_alloc(bmain, ID_LA, name); | la = BKE_libblock_alloc(bmain, ID_LA, name); | ||||
| BKE_lamp_init(la); | BKE_lamp_init(la); | ||||
| return la; | return la; | ||||
| } | } | ||||
| Lamp *BKE_lamp_copy(Main *bmain, const Lamp *la) | /** | ||||
| * Only copy internal data of Lamp ID from source to already allocated/initialized destination. | |||||
| * You probably nerver want to use that directly, use id_copy or BKE_id_copy_ex for typical needs. | |||||
| * | |||||
| * WARNING! This function will not handle ID user count! | |||||
| * | |||||
| * \param flag Copying options (see BKE_library.h's LIB_ID_COPY_... flags for more). | |||||
| */ | |||||
| void BKE_lamp_copy_data(Main *bmain, Lamp *la_dst, const Lamp *la_src, const int flag) | |||||
| { | { | ||||
| Lamp *lan; | for (int a = 0; a < MAX_MTEX; a++) { | ||||
| int a; | if (la_dst->mtex[a]) { | ||||
| la_dst->mtex[a] = MEM_mallocN(sizeof(*la_dst->mtex[a]), __func__); | |||||
| lan = BKE_libblock_copy(bmain, &la->id); | *la_dst->mtex[a] = *la_src->mtex[a]; | ||||
| for (a = 0; a < MAX_MTEX; a++) { | |||||
| if (lan->mtex[a]) { | |||||
| lan->mtex[a] = MEM_mallocN(sizeof(MTex), "copylamptex"); | |||||
| memcpy(lan->mtex[a], la->mtex[a], sizeof(MTex)); | |||||
| id_us_plus((ID *)lan->mtex[a]->tex); | |||||
| } | } | ||||
| } | } | ||||
| lan->curfalloff = curvemapping_copy(la->curfalloff); | la_dst->curfalloff = curvemapping_copy(la_src->curfalloff); | ||||
| if (la->nodetree) | if (la_src->nodetree) { | ||||
| lan->nodetree = ntreeCopyTree(bmain, la->nodetree); | BKE_id_copy_ex(bmain, (ID *)la_src->nodetree, (ID **)&la_dst->nodetree, flag, false); | ||||
| } | |||||
| BKE_previewimg_id_copy(&lan->id, &la->id); | |||||
| BKE_id_copy_ensure_local(bmain, &la->id, &lan->id); | if ((flag & LIB_ID_COPY_NO_PREVIEW) == 0) { | ||||
| BKE_previewimg_id_copy(&la_dst->id, &la_src->id); | |||||
| } | |||||
| else { | |||||
| la_dst->preview = NULL; | |||||
| } | |||||
| } | |||||
| return lan; | Lamp *BKE_lamp_copy(Main *bmain, const Lamp *la) | ||||
| { | |||||
| Lamp *la_copy; | |||||
| BKE_id_copy_ex(bmain, &la->id, (ID **)&la_copy, 0, false); | |||||
| return la_copy; | |||||
| } | } | ||||
| Lamp *localize_lamp(Lamp *la) | Lamp *localize_lamp(Lamp *la) | ||||
| { | { | ||||
| /* TODO replace with something like | |||||
| * Lamp *la_copy; | |||||
| * BKE_id_copy_ex(bmain, &la->id, (ID **)&la_copy, LIB_ID_COPY_NO_MAIN | LIB_ID_COPY_NO_PREVIEW | LIB_ID_COPY_NO_USER_REFCOUNT, false); | |||||
| * return la_copy; | |||||
| * | |||||
| * ... Once f*** nodes are fully converted to that too :( */ | |||||
| Lamp *lan; | Lamp *lan; | ||||
| int a; | int a; | ||||
| lan = BKE_libblock_copy_nolib(&la->id, false); | lan = BKE_libblock_copy_nolib(&la->id, false); | ||||
| for (a = 0; a < MAX_MTEX; a++) { | for (a = 0; a < MAX_MTEX; a++) { | ||||
| if (lan->mtex[a]) { | if (lan->mtex[a]) { | ||||
| lan->mtex[a] = MEM_mallocN(sizeof(MTex), "localize_lamp"); | lan->mtex[a] = MEM_mallocN(sizeof(MTex), "localize_lamp"); | ||||
| ▲ Show 20 Lines • Show All 80 Lines • Show Last 20 Lines | |||||