コード例 #1
0
Object *bc_add_object(Scene *scene, int type, const char *name)
{
	Object *ob = add_only_object(type, name);

	ob->data= add_obdata_from_type(type);
	ob->lay= scene->lay;
	ob->recalc |= OB_RECALC_OB|OB_RECALC_DATA|OB_RECALC_TIME;

	scene_select_base(scene, scene_add_base(scene, ob));

	return ob;
}
コード例 #2
0
ファイル: DocumentImporter.cpp プロジェクト: BHCLL/blendocv
Object* DocumentImporter::create_instance_node(Object *source_ob, COLLADAFW::Node *source_node, COLLADAFW::Node *instance_node, Scene *sce, Object *par_ob, bool is_library_node)
{
	Object *obn = copy_object(source_ob);
	obn->recalc |= OB_RECALC_OB|OB_RECALC_DATA|OB_RECALC_TIME;
	scene_add_base(sce, obn);

	if (instance_node) {
		anim_importer.read_node_transform(instance_node, obn);
		// if we also have a source_node (always ;), take its
		// transformation matrix and apply it to the newly instantiated
		// object to account for node hierarchy transforms in
		// .dae
		if(source_node) {
			COLLADABU::Math::Matrix4 mat4 = source_node->getTransformationMatrix();
			COLLADABU::Math::Matrix4 bmat4 = mat4.transpose(); // transpose to get blender row-major order
			float mat[4][4];
			for (int i = 0; i < 4; i++) {
				for (int j = 0; j < 4; j++) {
					mat[i][j] = bmat4[i][j];
				}
			}
			// calc new matrix and apply
			mul_m4_m4m4(obn->obmat, mat, obn->obmat);
			object_apply_mat4(obn, obn->obmat, 0, 0);
		}
	}
	else {
		anim_importer.read_node_transform(source_node, obn);
	}

	DAG_scene_sort(CTX_data_main(mContext), sce);
	DAG_ids_flush_update(CTX_data_main(mContext), 0);

	COLLADAFW::NodePointerArray &children = source_node->getChildNodes();
	if (children.getCount()) {
		for (unsigned int i = 0; i < children.getCount(); i++) {
			COLLADAFW::Node *child_node = children[i];
			const COLLADAFW::UniqueId& child_id = child_node->getUniqueId();
			if (object_map.find(child_id) == object_map.end())
				continue;
			COLLADAFW::InstanceNodePointerArray &inodes = child_node->getInstanceNodes();
			Object *new_child = NULL;
			if (inodes.getCount()) { // \todo loop through instance nodes
				const COLLADAFW::UniqueId& id = inodes[0]->getInstanciatedObjectId();
				new_child = create_instance_node(object_map[id], node_map[id], child_node, sce, NULL, is_library_node);
			}
			else {
				new_child = create_instance_node(object_map[child_id], child_node, NULL, sce, NULL, is_library_node);
			}
			bc_set_parent(new_child, obn, mContext, true);

			if (is_library_node)
				libnode_ob.push_back(new_child);
		}
	}

	// when we have an instance_node, don't return the object, because otherwise
	// its correct location gets overwritten in write_node(). Fixes bug #26012.
	if(instance_node) {
		if (par_ob && obn)
			bc_set_parent(obn, par_ob, mContext);
		return NULL;
	}

	else return obn;
}