[Bf-blender-cvs] [ba7685a] compositor-2016: Code refactor: nodify Cycles camera and fix some mistakes in XML node read.

Brecht Van Lommel noreply at git.blender.org
Wed Jun 8 21:50:45 CEST 2016


Commit: ba7685ae7e2d038e3e18fc718119304c187d1996
Author: Brecht Van Lommel
Date:   Sun May 8 00:28:21 2016 +0200
Branches: compositor-2016
https://developer.blender.org/rBba7685ae7e2d038e3e18fc718119304c187d1996

Code refactor: nodify Cycles camera and fix some mistakes in XML node read.

Differential Revision: https://developer.blender.org/D2016

===================================================================

M	intern/cycles/app/cycles_xml.cpp
M	intern/cycles/blender/blender_camera.cpp
M	intern/cycles/blender/blender_util.h
M	intern/cycles/graph/node.cpp
M	intern/cycles/graph/node.h
M	intern/cycles/graph/node_xml.cpp
M	intern/cycles/render/camera.cpp
M	intern/cycles/render/camera.h

===================================================================

diff --git a/intern/cycles/app/cycles_xml.cpp b/intern/cycles/app/cycles_xml.cpp
index f734d01..bee8fa7 100644
--- a/intern/cycles/app/cycles_xml.cpp
+++ b/intern/cycles/app/cycles_xml.cpp
@@ -281,46 +281,14 @@ static ShaderSocketType xml_read_socket_type(pugi::xml_node node, const char *na
 
 /* Camera */
 
-static void xml_read_camera(const XMLReadState& state, pugi::xml_node node)
+static void xml_read_camera(XMLReadState& state, pugi::xml_node node)
 {
 	Camera *cam = state.scene->camera;
 
 	xml_read_int(&cam->width, node, "width");
 	xml_read_int(&cam->height, node, "height");
 
-	if(xml_read_float(&cam->fov, node, "fov"))
-		cam->fov = DEG2RADF(cam->fov);
-
-	xml_read_float(&cam->nearclip, node, "nearclip");
-	xml_read_float(&cam->farclip, node, "farclip");
-	xml_read_float(&cam->aperturesize, node, "aperturesize"); // 0.5*focallength/fstop
-	xml_read_float(&cam->focaldistance, node, "focaldistance");
-	xml_read_float(&cam->shuttertime, node, "shuttertime");
-	xml_read_float(&cam->aperture_ratio, node, "aperture_ratio");
-
-	if(xml_equal_string(node, "type", "orthographic"))
-		cam->type = CAMERA_ORTHOGRAPHIC;
-	else if(xml_equal_string(node, "type", "perspective"))
-		cam->type = CAMERA_PERSPECTIVE;
-	else if(xml_equal_string(node, "type", "panorama"))
-		cam->type = CAMERA_PANORAMA;
-
-	if(xml_equal_string(node, "panorama_type", "equirectangular"))
-		cam->panorama_type = PANORAMA_EQUIRECTANGULAR;
-	else if(xml_equal_string(node, "panorama_type", "fisheye_equidistant"))
-		cam->panorama_type = PANORAMA_FISHEYE_EQUIDISTANT;
-	else if(xml_equal_string(node, "panorama_type", "fisheye_equisolid"))
-		cam->panorama_type = PANORAMA_FISHEYE_EQUISOLID;
-
-	xml_read_float(&cam->fisheye_fov, node, "fisheye_fov");
-	xml_read_float(&cam->fisheye_lens, node, "fisheye_lens");
-
-	xml_read_bool(&cam->use_spherical_stereo, node, "use_spherical_stereo");
-	xml_read_float(&cam->interocular_distance, node, "interocular_distance");
-	xml_read_float(&cam->convergence_distance, node, "convergence_distance");
-
-	xml_read_float(&cam->sensorwidth, node, "sensorwidth");
-	xml_read_float(&cam->sensorheight, node, "sensorheight");
+	xml_read_node(state, cam, node);
 
 	cam->matrix = state.tfm;
 
diff --git a/intern/cycles/blender/blender_camera.cpp b/intern/cycles/blender/blender_camera.cpp
index 3a0fee2..f02fc55 100644
--- a/intern/cycles/blender/blender_camera.cpp
+++ b/intern/cycles/blender/blender_camera.cpp
@@ -37,7 +37,7 @@ struct BlenderCamera {
 	float lens;
 	float shuttertime;
 	Camera::MotionPosition motion_position;
-	float shutter_curve[RAMP_TABLE_SIZE];
+	array<float> shutter_curve;
 
 	Camera::RollingShutterType rolling_shutter_type;
 	float rolling_shutter_duration;
@@ -460,7 +460,7 @@ static void blender_camera_sync(Camera *cam, BlenderCamera *bcam, int width, int
 	cam->rolling_shutter_type = bcam->rolling_shutter_type;
 	cam->rolling_shutter_duration = bcam->rolling_shutter_duration;
 
-	memcpy(cam->shutter_curve, bcam->shutter_curve, sizeof(cam->shutter_curve));
+	cam->shutter_curve = bcam->shutter_curve;
 
 	/* border */
 	cam->border = bcam->border;
diff --git a/intern/cycles/blender/blender_util.h b/intern/cycles/blender/blender_util.h
index e23d8bf..2510ceb 100644
--- a/intern/cycles/blender/blender_util.h
+++ b/intern/cycles/blender/blender_util.h
@@ -98,11 +98,12 @@ static inline void curvemapping_minmax(/*const*/ BL::CurveMapping& cumap,
 }
 
 static inline void curvemapping_to_array(BL::CurveMapping& cumap,
-                                         float *data,
+                                         array<float>& data,
                                          int size)
 {
 	cumap.update();
 	BL::CurveMap curve = cumap.curves[0];
+	data.resize(size);
 	for(int i = 0; i < size; i++) {
 		float t = (float)i/(float)(size-1);
 		data[i] = curve.evaluate(t);
diff --git a/intern/cycles/graph/node.cpp b/intern/cycles/graph/node.cpp
index d482577..98b66fb 100644
--- a/intern/cycles/graph/node.cpp
+++ b/intern/cycles/graph/node.cpp
@@ -104,6 +104,11 @@ void Node::set(const SocketType& input, float3 value)
 	get_socket_value<float3>(this, input) = value;
 }
 
+void Node::set(const SocketType& input, const char *value)
+{
+	set(input, ustring(value));
+}
+
 void Node::set(const SocketType& input, ustring value)
 {
 	if(input.type == SocketType::STRING) {
diff --git a/intern/cycles/graph/node.h b/intern/cycles/graph/node.h
index 33971fa..de06df1 100644
--- a/intern/cycles/graph/node.h
+++ b/intern/cycles/graph/node.h
@@ -41,6 +41,7 @@ struct Node
 	void set(const SocketType& input, float value);
 	void set(const SocketType& input, float2 value);
 	void set(const SocketType& input, float3 value);
+	void set(const SocketType& input, const char *value);
 	void set(const SocketType& input, ustring value);
 	void set(const SocketType& input, const Transform& value);
 	void set(const SocketType& input, Node *value);
diff --git a/intern/cycles/graph/node_xml.cpp b/intern/cycles/graph/node_xml.cpp
index fe06a24..a604040 100644
--- a/intern/cycles/graph/node_xml.cpp
+++ b/intern/cycles/graph/node_xml.cpp
@@ -117,8 +117,9 @@ void xml_read_node(XMLReader& reader, Node *node, pugi::xml_node xml_node)
 
 				array<int> value;
 				value.resize(tokens.size());
-				for(size_t i = 0; i < value.size(); i++)
+				for(size_t i = 0; i < value.size(); i++) {
 					value[i] = (int)atoi(attr.value());
+				}
 				node->set(socket, value);
 				break;
 			}
@@ -127,7 +128,7 @@ void xml_read_node(XMLReader& reader, Node *node, pugi::xml_node xml_node)
 			case SocketType::POINT:
 			case SocketType::NORMAL:
 			{
-				array<float> value;
+				array<float3> value;
 				xml_read_float_array<3>(value, attr);
 				if(value.size() == 1) {
 					node->set(socket, value[0]);
@@ -161,11 +162,21 @@ void xml_read_node(XMLReader& reader, Node *node, pugi::xml_node xml_node)
 				break;
 			}
 			case SocketType::STRING:
-			case SocketType::ENUM:
 			{
 				node->set(socket, attr.value());
 				break;
 			}
+			case SocketType::ENUM:
+			{
+				ustring value(attr.value());
+				if(socket.enum_values->exists(value)) {
+					node->set(socket, value);
+				}
+				else {
+					fprintf(stderr, "Unknown value \"%s\" for attribute \"%s\".\n", value.c_str(), socket.name.c_str());
+				}
+				break;
+			}
 			case SocketType::STRING_ARRAY:
 			{
 				vector<string> tokens;
@@ -173,8 +184,9 @@ void xml_read_node(XMLReader& reader, Node *node, pugi::xml_node xml_node)
 
 				array<ustring> value;
 				value.resize(tokens.size());
-				for(size_t i = 0; i < value.size(); i++)
+				for(size_t i = 0; i < value.size(); i++) {
 					value[i] = ustring(tokens[i]);
+				}
 				node->set(socket, value);
 				break;
 			}
diff --git a/intern/cycles/render/camera.cpp b/intern/cycles/render/camera.cpp
index d992cac..250357d 100644
--- a/intern/cycles/render/camera.cpp
+++ b/intern/cycles/render/camera.cpp
@@ -30,70 +30,126 @@
 CCL_NAMESPACE_BEGIN
 
 static float shutter_curve_eval(float x,
-                                float shutter_curve[RAMP_TABLE_SIZE])
+                                array<float>& shutter_curve)
 {
-	x *= RAMP_TABLE_SIZE;
+	if (shutter_curve.size() == 0)
+		return 1.0f;
+
+	x *= shutter_curve.size();
 	int index = (int)x;
 	float frac = x - index;
-	if(index < RAMP_TABLE_SIZE - 1) {
+	if(index < shutter_curve.size() - 1) {
 		return lerp(shutter_curve[index], shutter_curve[index + 1], frac);
 	}
 	else {
-		return shutter_curve[RAMP_TABLE_SIZE - 1];
+		return shutter_curve[shutter_curve.size() - 1];
 	}
 }
 
+NODE_DEFINE(Camera)
+{
+	NodeType* type = NodeType::add("camera", create);
+
+	SOCKET_FLOAT(shuttertime, "Shutter Time", 1.0f);
+
+	static NodeEnum motion_position_enum;
+	motion_position_enum.insert("start", MOTION_POSITION_START);
+	motion_position_enum.insert("center", MOTION_POSITION_CENTER);
+	motion_position_enum.insert("end", MOTION_POSITION_END);
+	SOCKET_ENUM(motion_position, "Motion Position", motion_position_enum, MOTION_POSITION_CENTER);
+
+	static NodeEnum rolling_shutter_type_enum;
+	rolling_shutter_type_enum.insert("none", ROLLING_SHUTTER_NONE);
+	rolling_shutter_type_enum.insert("top", ROLLING_SHUTTER_TOP);
+	SOCKET_ENUM(rolling_shutter_type, "Rolling Shutter Type", rolling_shutter_type_enum,  ROLLING_SHUTTER_NONE);
+	SOCKET_FLOAT(rolling_shutter_duration, "Rolling Shutter Duration", 0.1f);
+
+	SOCKET_FLOAT_ARRAY(shutter_curve, "Shutter Curve", array<float>());
+
+	SOCKET_FLOAT(aperturesize, "Aperture Size", 0.0f);
+	SOCKET_FLOAT(focaldistance, "Focal Distance", 10.0f);
+	SOCKET_INT(blades, "Blades", 0);
+	SOCKET_FLOAT(bladesrotation, "Blades Rotation", 0.0f);
+
+	SOCKET_TRANSFORM(matrix, "Matrix", transform_identity());
+
+	SOCKET_FLOAT(aperture_ratio, "Aperture Ratio", 1.0f);
+
+	static NodeEnum type_enum;
+	type_enum.insert("perspective", CAMERA_PERSPECTIVE);
+	type_enum.insert("orthograph", CAMERA_ORTHOGRAPHIC);
+	type_enum.insert("panorama", CAMERA_PANORAMA);
+	SOCKET_ENUM(type, "Type", type_enum, CAMERA_PERSPECTIVE);
+
+	static NodeEnum panorama_type_enum;
+	panorama_type_enum.insert("equirectangular", PANORAMA_EQUIRECTANGULAR);
+	panorama_type_enum.insert("mirrorball", PANORAMA_MIRRORBALL);
+	panorama_type_enum.insert("fisheye_equidistant", PANORAMA_FISHEYE_EQUIDISTANT);
+	panorama_type_enum.insert("fisheye_equisolid", PANORAMA_FISHEYE_EQUISOLID);
+	SOCKET_ENUM(panorama_type, "Panorama Type", panorama_type_enum, PANORAMA_EQUIRECTANGULAR);
+
+	SOCKET_FLOAT(fisheye_fov, "Fisheye FOV", M_PI_F);
+	SOCKET_FLOAT(fisheye_lens, "Fisheye Lens", 10.5f);
+	SOCKET_FLOAT(latitude_min, "Latitude Min", -M_PI_2_F);
+	SOCKET_FLOAT(latitude_max, "Latitude Max", M_PI_2_F);
+	SOCKET_FLOAT(longitude_min, "Longitude Min", -M_PI_F);
+	SOCKET_FLOAT(longitude_max, "Longitude Max", M_PI_F);
+	SOCKET_FLOAT(fov, "FOV", M_PI_4_F);
+	SOCKET_FLOAT(fov_pre, "FOV Pre", M_PI_4_F);
+	SOCKET_FLOAT(fov_post, "FOV Post", M_PI_4_F);
+
+	static NodeEnum stereo_eye_enum;
+	stereo_eye_enum.insert("none", STEREO_NONE);
+	stereo_eye_enum.insert("left", STEREO_LEFT);
+	stereo_eye_enum.insert("right", STEREO_RIGHT);
+	SOCKET_ENUM(stereo_eye, "Stereo Eye", stereo_eye_enum, STEREO_NONE);
+
+	SOCKET_FLOAT(interocular_distance, "Interocular Distance", 0.065f);
+	SOCKET_FLOAT(convergence_distance,

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list