Пример #1
0
Object *DocumentImporter::create_instance_node(Object *source_ob, COLLADAFW::Node *source_node, COLLADAFW::Node *instance_node, Scene *sce, bool is_library_node)
{
	fprintf(stderr, "create <instance_node> under node id=%s from node id=%s\n", instance_node ? instance_node->getOriginalId().c_str() : NULL, source_node ? source_node->getOriginalId().c_str() : NULL);

	Object *obn = BKE_object_copy(source_ob);
	DAG_id_tag_update(&obn->id, OB_RECALC_OB | OB_RECALC_DATA | OB_RECALC_TIME);
	BKE_scene_base_add(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, obn->obmat, mat);
			BKE_object_apply_mat4(obn, obn->obmat, 0, 0);
		}
	}
	else {
		anim_importer.read_node_transform(source_node, obn);
	}

	/*DAG_relations_tag_update(CTX_data_main(mContext));*/

	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();
				fprintf(stderr, "Doing %d child nodes\n", (int)node_map.count(id));
				new_child = create_instance_node(object_map.find(id)->second, node_map[id], child_node, sce, is_library_node);
			}
			else {
				new_child = create_instance_node(object_map.find(child_id)->second, child_node, NULL, sce, is_library_node);
			}
			bc_set_parent(new_child, obn, mContext, true);

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

	return obn;
}
Пример #2
0
// A replacement of BKE_object_add() for better performance.
Object *BlenderStrokeRenderer::NewMesh() const
{
	Object *ob;
	Base *base;
	char name[MAX_ID_NAME];
	unsigned int mesh_id = get_stroke_mesh_id();

	/* XXX this is for later review, for now we start names with 27 (DEL) 
	   to allow ignoring them in DAG_ids_check_recalc() */
	BLI_snprintf(name, MAX_ID_NAME, "%c0%08xOB", 27, mesh_id);
	ob = BKE_object_add_only_object(freestyle_bmain, OB_MESH, name);
	BLI_snprintf(name, MAX_ID_NAME, "%c0%08xME", 27, mesh_id);
	ob->data = BKE_mesh_add(freestyle_bmain, name);
	ob->lay = 1;

	base = BKE_scene_base_add(freestyle_scene, ob);
#if 0
	BKE_scene_base_deselect_all(scene);
	BKE_scene_base_select(scene, base);
#else
	(void)base;
#endif
	ob->recalc = OB_RECALC_OB | OB_RECALC_DATA | OB_RECALC_TIME;

	return ob;
}
Object *bc_add_object(Scene *scene, int type, const char *name)
{
	Object *ob = BKE_object_add_only_object(G.main, type, name);

	ob->data = BKE_object_obdata_add_from_type(G.main, type, name);
	ob->lay = scene->lay;
	DAG_id_tag_update(&ob->id, OB_RECALC_OB | OB_RECALC_DATA | OB_RECALC_TIME);

	BKE_scene_base_select(scene, BKE_scene_base_add(scene, ob));

	return ob;
}
/* convert a given grease-pencil layer to a 3d-curve representation (using current view if appropriate) */
static void gp_layer_to_curve(bContext *C, ReportList *reports, bGPdata *gpd, bGPDlayer *gpl, const int mode,
                              const bool norm_weights, const float rad_fac, const bool link_strokes, tGpTimingData *gtd)
{
	struct Main *bmain = CTX_data_main(C);
	View3D *v3d = CTX_wm_view3d(C);  /* may be NULL */
	Scene *scene = CTX_data_scene(C);
	bGPDframe *gpf = gpencil_layer_getframe(gpl, CFRA, 0);
	bGPDstroke *gps, *prev_gps = NULL;
	Object *ob;
	Curve *cu;
	Nurb *nu = NULL;
	Base *base_orig = BASACT, *base_new = NULL;
	float minmax_weights[2] = {1.0f, 0.0f};
	
	/* camera framing */
	rctf subrect, *subrect_ptr = NULL;
	
	/* error checking */
	if (ELEM(NULL, gpd, gpl, gpf))
		return;
	
	/* only convert if there are any strokes on this layer's frame to convert */
	if (BLI_listbase_is_empty(&gpf->strokes))
		return;
	
	/* initialize camera framing */
	if (gp_camera_view_subrect(C, &subrect)) {
		subrect_ptr = &subrect;
	}
	
	/* init the curve object (remove rotation and get curve data from it)
	 *	- must clear transforms set on object, as those skew our results
	 */
	ob = BKE_object_add_only_object(bmain, OB_CURVE, gpl->info);
	cu = ob->data = BKE_curve_add(bmain, gpl->info, OB_CURVE);
	base_new = BKE_scene_base_add(scene, ob);
	
	cu->flag |= CU_3D;
	
	gtd->inittime = ((bGPDstroke *)gpf->strokes.first)->inittime;
	
	/* add points to curve */
	for (gps = gpf->strokes.first; gps; gps = gps->next) {
		const bool add_start_point = (link_strokes && !(prev_gps));
		const bool add_end_point = (link_strokes && !(gps->next));
		
		/* Detect new strokes created because of GP_STROKE_BUFFER_MAX reached, and stitch them to previous one. */
		bool stitch = false;
		if (prev_gps) {
			bGPDspoint *pt1 = &prev_gps->points[prev_gps->totpoints - 1];
			bGPDspoint *pt2 = &gps->points[0];
			
			if ((pt1->x == pt2->x) && (pt1->y == pt2->y)) {
				stitch = true;
			}
		}
		
		/* Decide whether we connect this stroke to previous one */
		if (!(stitch || link_strokes)) {
			nu = NULL;
		}
		
		switch (mode) {
			case GP_STROKECONVERT_PATH:
				gp_stroke_to_path(C, gpl, gps, cu, subrect_ptr, &nu, minmax_weights, rad_fac, stitch,
				                  add_start_point, add_end_point, gtd);
				break;
			case GP_STROKECONVERT_CURVE:
			case GP_STROKECONVERT_POLY:  /* convert after */
				gp_stroke_to_bezier(C, gpl, gps, cu, subrect_ptr, &nu, minmax_weights, rad_fac, stitch,
				                    add_start_point, add_end_point, gtd);
				break;
			default:
				BLI_assert(!"invalid mode");
				break;
		}
		prev_gps = gps;
	}
	
	/* If link_strokes, be sure first and last points have a zero weight/size! */
	if (link_strokes) {
		gp_stroke_finalize_curve_endpoints(cu);
	}
	
	/* Update curve's weights, if needed */
	if (norm_weights && ((minmax_weights[0] > 0.0f) || (minmax_weights[1] < 1.0f))) {
		gp_stroke_norm_curve_weights(cu, minmax_weights);
	}
	
	/* Create the path animation, if needed */
	gp_stroke_path_animation(C, reports, cu, gtd);
	
	if (mode == GP_STROKECONVERT_POLY) {
		for (nu = cu->nurb.first; nu; nu = nu->next) {
			BKE_nurb_type_convert(nu, CU_POLY, false);
		}
	}
	
	/* set the layer and select */
	base_new->lay  = ob->lay  = base_orig ? base_orig->lay : BKE_screen_view3d_layer_active(v3d, scene);
	base_new->flag = ob->flag = base_new->flag | SELECT;
}
Пример #5
0
void KX_LightObject::UpdateScene(KX_Scene *kxscene)
{
	m_lightobj->m_scene = (void*)kxscene;
	m_blenderscene = kxscene->GetBlenderScene();
	m_base = BKE_scene_base_add(m_blenderscene, GetBlenderObject());
}