metaforce/DataSpec/DNACommon/BabeDead.hpp

89 lines
3.7 KiB
C++
Raw Normal View History

2015-09-28 05:19:31 +00:00
#ifndef _DNACOMMON_BABEDEAD_HPP_
#define _DNACOMMON_BABEDEAD_HPP_
#include <BlenderConnection.hpp>
2015-10-12 04:41:28 +00:00
#ifndef _USE_MATH_DEFINES
#define _USE_MATH_DEFINES 1
#endif
#include <math.h>
2016-02-13 09:02:47 +00:00
namespace DataSpec
2015-09-28 05:19:31 +00:00
{
template<class BabeDeadLight>
void ReadBabeDeadLightToBlender(HECL::BlenderConnection::PyOutStream& os,
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,
light.spotCutoff * M_PI / 180.f,
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"
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";
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";
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";
break;
default: break;
}
}
}
#endif // _DNACOMMON_BABEDEAD_HPP_