//------------------------------- Not used in the new system.--------------------------------------------------------
void AnimationExporter::find_rotation_frames(Object *ob, std::vector<float> &fra, const char *prefix, int rotmode)
{
	if (rotmode > 0)
		find_frames(ob, fra, prefix, "rotation_euler");
	else if (rotmode == ROT_MODE_QUAT)
		find_frames(ob, fra, prefix, "rotation_quaternion");
	/*else if (rotmode == ROT_MODE_AXISANGLE)
	   ;*/
}
void AnimationExporter::sample_and_write_bone_animation_matrix(Object *ob_arm, Bone *bone)
{
	bArmature *arm = (bArmature *)ob_arm->data;
	int flag = arm->flag;
	std::vector<float> fra;
	//char prefix[256];

	FCurve *fcu = (FCurve *)ob_arm->adt->action->curves.first;
	while (fcu) {
		std::string bone_name = getObjectBoneName(ob_arm, fcu);
		int val = BLI_strcasecmp((char *)bone_name.c_str(), bone->name);
		if (val == 0) break;
		fcu = fcu->next;
	}

	if (!(fcu)) return; 
	bPoseChannel *pchan = BKE_pose_channel_find_name(ob_arm->pose, bone->name);
	if (!pchan)
		return;

	find_frames(ob_arm, fra);

	if (flag & ARM_RESTPOS) {
		arm->flag &= ~ARM_RESTPOS;
		BKE_pose_where_is(scene, ob_arm);
	}

	if (fra.size()) {
		dae_baked_animation(fra, ob_arm, bone);
	}

	if (flag & ARM_RESTPOS) 
		arm->flag = flag;
	BKE_pose_where_is(scene, ob_arm);
}
void AnimationExporter::make_anim_frames_from_targets(Object *ob, std::vector<float> &frames )
{
	ListBase *conlist = get_active_constraints(ob);
	if (conlist == NULL) return;
	bConstraint *con;
	for (con = (bConstraint *)conlist->first; con; con = con->next) {
		ListBase targets = {NULL, NULL};
		
		bConstraintTypeInfo *cti = BKE_constraint_typeinfo_get(con);
		
		if (!validateConstraints(con)) continue;

		if (cti && cti->get_constraint_targets) {
			bConstraintTarget *ct;
			Object *obtar;
			/* get targets 
			 *  - constraints should use ct->matrix, not directly accessing values
			 *	- ct->matrix members have not yet been calculated here! 
			 */
			cti->get_constraint_targets(con, &targets);

			for (ct = (bConstraintTarget *)targets.first; ct; ct = ct->next) {
				obtar = ct->tar;

				if (obtar)
					find_frames(obtar, frames);
			}

			if (cti->flush_constraint_targets)
				cti->flush_constraint_targets(con, &targets, 1);
		}
	}
}
Exemple #4
0
// Finds contiguous frames of memory to fit n_frames (each 4KB)
// Returns NULL if unable to find; otherwise first frame address
// Use mode = KERNEL_ALLOC to allocation from first 4MB; mode = 
// USER_ALLOC otherwise
void *alloc_frames(uint32_t n_frames, bool mode) {
	int i;
	uint32_t *alloc_base = NULL; // memory address to return

	if (mode==KERNEL_ALLOC && n_frames > (total_frames-264)) return NULL;
	if (mode==USER_ALLOC && n_frames > (total_frames-1024)) return NULL;

	uint32_t start_frame;
	if (mode==KERNEL_ALLOC)
		start_frame = find_frames(n_frames,264,1023); // kernel memory always from first 4MB
	else 
		start_frame = find_frames(n_frames,1024,total_frames); //starting from 4MB mark


	if (start_frame != 0) {
		alloc_base = (uint32_t *)(start_frame*4096);
		// update memory bitmap
		modify_bitmap(start_frame,n_frames,0);
	}
	
	return (void *)alloc_base;
}
void AnimationExporter::sample_and_write_bone_animation_matrix(Object *ob_arm, Bone *bone)
{
	bArmature *arm = (bArmature *)ob_arm->data;
	int flag = arm->flag;
	std::vector<float> fra;
	//char prefix[256];

	//Check if there is a fcurve in the armature for the bone in param
	//when baking this check is not needed, solve every bone for every frame.
	/*FCurve *fcu = (FCurve *)ob_arm->adt->action->curves.first;

	while (fcu) {
		std::string bone_name = getObjectBoneName(ob_arm, fcu);
		int val = BLI_strcasecmp((char *)bone_name.c_str(), bone->name);
		if (val == 0) break;
		fcu = fcu->next;
	}

	if (!(fcu)) return;*/ 

	bPoseChannel *pchan = BKE_pose_channel_find_name(ob_arm->pose, bone->name);
	if (!pchan)
		return;

	//every inserted keyframe of bones.	
	find_frames(ob_arm, fra);

	if (flag & ARM_RESTPOS) {
		arm->flag &= ~ARM_RESTPOS;
		BKE_pose_where_is(scene, ob_arm);
	}

	if (fra.size()) {
		dae_baked_animation(fra, ob_arm, bone);
	}

	if (flag & ARM_RESTPOS) 
		arm->flag = flag;
	BKE_pose_where_is(scene, ob_arm);
}
Exemple #6
0
// Finds contiguous frames of memory to fit count
// bytes (in multiples of 4KB frames)
// Returns NULL if unable to find; otherwise found location + 4bytes
// Writes no. of allocated frames in first 4 bytes of found location
void *alloc_memory(uint32_t count) {
	int i;
	uint32_t *alloc_base = NULL; // memory address to return

	uint32_t n_frames = (count+4)/(4096); // number of 4KB frames
	if ((count+4) % 4096 != 0) n_frames++;

	if (n_frames > (total_frames-1024)) return NULL;

	uint32_t start_frame = find_frames(n_frames);

	if (start_frame != 0) {
		alloc_base = (uint32_t *)(start_frame*4096);

		// the first 4 bytes will store number of frames allocated;
		// will be used when de-allocating
		*alloc_base = n_frames; 
		alloc_base++;

		// update memory bitmap
		/*for (i=start_frame/8; n_frames > 0; i++) {
			if (n_frames >= 8) {
				mem_bitmap[i] = 0;
				n_frames -= 8;
			}
			else {
				mem_bitmap[i] &= (0xFF >> n_frames);
				n_frames = 0;
			}
		}*/
		modify_bitmap(start_frame,n_frames,0);

	}

	return (void *)alloc_base;
}
void AnimationExporter::sample_and_write_bone_animation(Object *ob_arm, Bone *bone, int transform_type)
{
	bArmature *arm = (bArmature *)ob_arm->data;
	int flag = arm->flag;
	std::vector<float> fra;
	char prefix[256];

	BLI_snprintf(prefix, sizeof(prefix), "pose.bones[\"%s\"]", bone->name);

	bPoseChannel *pchan = BKE_pose_channel_find_name(ob_arm->pose, bone->name);
	if (!pchan)
		return;
	//Fill frame array with key frame values framed at \param:transform_type
	switch (transform_type) {
		case 0:
			find_rotation_frames(ob_arm, fra, prefix, pchan->rotmode);
			break;
		case 1:
			find_frames(ob_arm, fra, prefix, "scale");
			break;
		case 2:
			find_frames(ob_arm, fra, prefix, "location");
			break;
		default:
			return;
	}

	// exit rest position
	if (flag & ARM_RESTPOS) {
		arm->flag &= ~ARM_RESTPOS;
		BKE_pose_where_is(scene, ob_arm);
	}
	//v array will hold all values which will be exported. 
	if (fra.size()) {
		float *values = (float *)MEM_callocN(sizeof(float) * 3 * fra.size(), "temp. anim frames");
		sample_animation(values, fra, transform_type, bone, ob_arm, pchan);

		if (transform_type == 0) {
			// write x, y, z curves separately if it is rotation
			float *axisValues = (float *)MEM_callocN(sizeof(float) * fra.size(), "temp. anim frames");

			for (int i = 0; i < 3; i++) {
				for (unsigned int j = 0; j < fra.size(); j++)
					axisValues[j] = values[j * 3 + i];

				dae_bone_animation(fra, axisValues, transform_type, i, id_name(ob_arm), bone->name);
			}
			MEM_freeN(axisValues);
		}
		else {
			// write xyz at once if it is location or scale
			dae_bone_animation(fra, values, transform_type, -1, id_name(ob_arm), bone->name);
		}

		MEM_freeN(values);
	}

	// restore restpos
	if (flag & ARM_RESTPOS) 
		arm->flag = flag;
	BKE_pose_where_is(scene, ob_arm);
}