metaforce/DataSpec/DNACommon/BabeDead.hpp

94 lines
4.1 KiB
C++
Raw Normal View History

2015-09-28 05:19:31 +00:00
#ifndef _DNACOMMON_BABEDEAD_HPP_
#define _DNACOMMON_BABEDEAD_HPP_
2016-03-04 23:04:53 +00:00
#include "BlenderConnection.hpp"
#include "zeus/Math.hpp"
2016-03-27 21:02:38 +00:00
#include <cfloat>
2015-10-12 04:41:28 +00:00
2016-02-13 09:02:47 +00:00
namespace DataSpec
2015-09-28 05:19:31 +00:00
{
template<class BabeDeadLight>
2016-03-04 23:04:53 +00:00
void ReadBabeDeadLightToBlender(hecl::BlenderConnection::PyOutStream& os,
2015-09-28 05:19:31 +00:00
const BabeDeadLight& light, unsigned s, unsigned l)
{
switch (light.lightType)
{
2015-11-21 01:16:07 +00:00
case BabeDeadLight::LightType::LocalAmbient:
case BabeDeadLight::LightType::LocalAmbient2:
2015-09-28 05:19:31 +00:00
os.format("bg_node.inputs[0].default_value = (%f,%f,%f,1.0)\n"
"bg_node.inputs[1].default_value = %f\n",
light.color.vec[0], light.color.vec[1], light.color.vec[2],
light.q / 8.0);
return;
2015-11-21 01:16:07 +00:00
case BabeDeadLight::LightType::Directional:
2015-09-28 05:19:31 +00:00
os.format("lamp = bpy.data.lamps.new('LAMP_%01u_%03u', 'SUN')\n"
"lamp_obj = bpy.data.objects.new(lamp.name, lamp)\n"
"lamp_obj.rotation_mode = 'QUATERNION'\n"
"lamp_obj.rotation_quaternion = Vector((0,0,-1)).rotation_difference(Vector((%f,%f,%f)))\n"
"\n", s, l,
light.direction.vec[0], light.direction.vec[1], light.direction.vec[2]);
break;
2015-11-21 01:16:07 +00:00
case BabeDeadLight::LightType::Custom:
2015-09-28 05:19:31 +00:00
os.format("lamp = bpy.data.lamps.new('LAMP_%01u_%03u', 'POINT')\n"
"lamp_obj = bpy.data.objects.new(lamp.name, lamp)\n"
"\n", s, l);
break;
2015-11-21 01:16:07 +00:00
case BabeDeadLight::LightType::Spot:
case BabeDeadLight::LightType::Spot2:
2015-09-28 05:19:31 +00:00
os.format("lamp = bpy.data.lamps.new('LAMP_%01u_%03u', 'SPOT')\n"
"lamp.spot_size = %f\n"
"lamp_obj = bpy.data.objects.new(lamp.name, lamp)\n"
"lamp_obj.rotation_mode = 'QUATERNION'\n"
"lamp_obj.rotation_quaternion = Vector((0,0,-1)).rotation_difference(Vector((%f,%f,%f)))\n"
"\n", s, l,
2016-03-04 23:04:53 +00:00
zeus::degToRad(light.spotCutoff),
2015-09-28 05:19:31 +00:00
light.direction.vec[0], light.direction.vec[1], light.direction.vec[2]);
break;
default: return;
}
os.format("lamp.retro_layer = %u\n"
2015-09-28 06:16:41 +00:00
"lamp.retro_origtype = %u\n"
"lamp.falloff_type = 'INVERSE_COEFFICIENTS'\n"
2016-03-27 21:02:38 +00:00
"lamp.constant_coefficient = 0\n"
2015-09-28 05:19:31 +00:00
"lamp.use_nodes = True\n"
"falloff_node = lamp.node_tree.nodes.new('ShaderNodeLightFalloff')\n"
"lamp.energy = 0.0\n"
"falloff_node.inputs[0].default_value = %f\n"
"hue_sat_node = lamp.node_tree.nodes.new('ShaderNodeHueSaturation')\n"
"hue_sat_node.inputs[1].default_value = 1.25\n"
"hue_sat_node.inputs[4].default_value = (%f,%f,%f,1.0)\n"
"lamp.node_tree.links.new(hue_sat_node.outputs[0], lamp.node_tree.nodes['Emission'].inputs[0])\n"
"lamp_obj.location = (%f,%f,%f)\n"
"bpy.context.scene.objects.link(lamp_obj)\n"
2015-09-28 06:16:41 +00:00
"\n", s, light.lightType, light.q / 8.0,
2015-09-28 05:19:31 +00:00
light.color.vec[0], light.color.vec[1], light.color.vec[2],
light.position.vec[0], light.position.vec[1], light.position.vec[2]);
switch (light.falloff)
{
2015-11-21 01:16:07 +00:00
case BabeDeadLight::Falloff::Constant:
2015-09-28 05:19:31 +00:00
os << "falloff_node.inputs[0].default_value *= 75.0\n"
"lamp.node_tree.links.new(falloff_node.outputs[2], lamp.node_tree.nodes['Emission'].inputs[1])\n";
2016-03-27 21:02:38 +00:00
if (light.q > FLT_EPSILON)
os.format("lamp.constant_coefficient = 2.0 / %f\n", light.q);
2015-09-28 05:19:31 +00:00
break;
2015-11-21 01:16:07 +00:00
case BabeDeadLight::Falloff::Linear:
2015-09-28 05:19:31 +00:00
os << "lamp.node_tree.links.new(falloff_node.outputs[1], lamp.node_tree.nodes['Emission'].inputs[1])\n";
2016-03-27 21:02:38 +00:00
if (light.q > FLT_EPSILON)
os.format("lamp.linear_coefficient = 250 / %f\n", light.q);
2015-09-28 05:19:31 +00:00
break;
2015-11-21 01:16:07 +00:00
case BabeDeadLight::Falloff::Quadratic:
2015-09-28 05:19:31 +00:00
os << "lamp.node_tree.links.new(falloff_node.outputs[0], lamp.node_tree.nodes['Emission'].inputs[1])\n";
2016-03-27 21:02:38 +00:00
if (light.q > FLT_EPSILON)
os.format("lamp.quadratic_coefficient = 25000 / %f\n", light.q);
2015-09-28 05:19:31 +00:00
break;
default: break;
}
}
}
#endif // _DNACOMMON_BABEDEAD_HPP_