2016-08-11 19:52:22 +00:00
|
|
|
#include "BabeDead.hpp"
|
|
|
|
#include "DataSpec/DNAMP1/MREA.hpp"
|
|
|
|
#include "DataSpec/DNAMP3/MREA.hpp"
|
|
|
|
#include "zeus/CTransform.hpp"
|
2017-12-29 08:08:12 +00:00
|
|
|
#include "hecl/Blender/Connection.hpp"
|
2016-08-11 19:52:22 +00:00
|
|
|
|
|
|
|
namespace DataSpec
|
|
|
|
{
|
|
|
|
|
|
|
|
template<class BabeDeadLight>
|
2017-12-29 08:08:12 +00:00
|
|
|
void ReadBabeDeadLightToBlender(hecl::blender::PyOutStream& os,
|
2016-08-11 19:52:22 +00:00
|
|
|
const BabeDeadLight& light, unsigned s, unsigned l)
|
|
|
|
{
|
|
|
|
switch (light.lightType)
|
|
|
|
{
|
|
|
|
case BabeDeadLight::LightType::LocalAmbient:
|
|
|
|
case BabeDeadLight::LightType::LocalAmbient2:
|
|
|
|
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],
|
2018-01-15 07:39:25 +00:00
|
|
|
light.q / 8.f);
|
2016-08-11 19:52:22 +00:00
|
|
|
return;
|
|
|
|
case BabeDeadLight::LightType::Directional:
|
|
|
|
os.format("lamp = bpy.data.lamps.new('LAMP_%01u_%03u', 'SUN')\n"
|
2018-04-04 08:31:29 +00:00
|
|
|
"lamp.color = (%f,%f,%f)\n"
|
2016-08-11 19:52:22 +00:00
|
|
|
"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"
|
2016-08-11 20:53:33 +00:00
|
|
|
"lamp.shadow_method = '%s'\n"
|
2018-04-04 08:31:29 +00:00
|
|
|
"\n", s, l, light.color.vec[0], light.color.vec[1], light.color.vec[2],
|
2016-08-11 19:52:22 +00:00
|
|
|
light.direction.vec[0], light.direction.vec[1], light.direction.vec[2],
|
|
|
|
light.castShadows ? "RAY_SHADOW" : "NOSHADOW");
|
|
|
|
return;
|
|
|
|
case BabeDeadLight::LightType::Custom:
|
|
|
|
os.format("lamp = bpy.data.lamps.new('LAMP_%01u_%03u', 'POINT')\n"
|
2018-04-04 08:31:29 +00:00
|
|
|
"lamp.color = (%f,%f,%f)\n"
|
2016-08-11 19:52:22 +00:00
|
|
|
"lamp_obj = bpy.data.objects.new(lamp.name, lamp)\n"
|
2018-04-09 00:09:30 +00:00
|
|
|
"lamp.shadow_soft_size = 1.0\n"
|
2016-08-11 20:53:33 +00:00
|
|
|
"lamp.shadow_method = '%s'\n"
|
2018-04-04 08:31:29 +00:00
|
|
|
"\n", s, l, light.color.vec[0], light.color.vec[1], light.color.vec[2],
|
|
|
|
light.castShadows ? "RAY_SHADOW" : "NOSHADOW");
|
2016-08-11 19:52:22 +00:00
|
|
|
break;
|
|
|
|
case BabeDeadLight::LightType::Spot:
|
|
|
|
case BabeDeadLight::LightType::Spot2:
|
|
|
|
os.format("lamp = bpy.data.lamps.new('LAMP_%01u_%03u', 'SPOT')\n"
|
2018-04-04 08:31:29 +00:00
|
|
|
"lamp.color = (%f,%f,%f)\n"
|
2016-08-11 19:52:22 +00:00
|
|
|
"lamp.spot_size = %.6g\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"
|
2018-04-09 00:09:30 +00:00
|
|
|
"lamp.shadow_soft_size = 0.5\n"
|
2016-08-11 20:53:33 +00:00
|
|
|
"lamp.shadow_method = '%s'\n"
|
2018-04-04 08:31:29 +00:00
|
|
|
"\n", s, l, light.color.vec[0], light.color.vec[1], light.color.vec[2],
|
2016-08-11 19:52:22 +00:00
|
|
|
zeus::degToRad(light.spotCutoff),
|
|
|
|
light.direction.vec[0], light.direction.vec[1], light.direction.vec[2],
|
|
|
|
light.castShadows ? "RAY_SHADOW" : "NOSHADOW");
|
|
|
|
break;
|
|
|
|
default: return;
|
|
|
|
}
|
|
|
|
|
|
|
|
os.format("lamp.retro_layer = %u\n"
|
|
|
|
"lamp.retro_origtype = %u\n"
|
|
|
|
"lamp.falloff_type = 'INVERSE_COEFFICIENTS'\n"
|
|
|
|
"lamp.constant_coefficient = 0\n"
|
|
|
|
"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"
|
2018-01-15 07:39:25 +00:00
|
|
|
"\n", s, light.lightType, light.q / 8.f,
|
2016-08-11 19:52:22 +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)
|
|
|
|
{
|
|
|
|
case BabeDeadLight::Falloff::Constant:
|
2018-04-09 00:09:30 +00:00
|
|
|
os << "falloff_node.inputs[0].default_value *= 150.0\n"
|
2016-08-11 19:52:22 +00:00
|
|
|
"lamp.node_tree.links.new(falloff_node.outputs[2], lamp.node_tree.nodes['Emission'].inputs[1])\n";
|
|
|
|
if (light.q > FLT_EPSILON)
|
|
|
|
os.format("lamp.constant_coefficient = 2.0 / %f\n", light.q);
|
|
|
|
break;
|
|
|
|
case BabeDeadLight::Falloff::Linear:
|
|
|
|
os << "lamp.node_tree.links.new(falloff_node.outputs[1], lamp.node_tree.nodes['Emission'].inputs[1])\n";
|
|
|
|
if (light.q > FLT_EPSILON)
|
|
|
|
os.format("lamp.linear_coefficient = 250 / %f\n", light.q);
|
|
|
|
break;
|
|
|
|
case BabeDeadLight::Falloff::Quadratic:
|
|
|
|
os << "lamp.node_tree.links.new(falloff_node.outputs[0], lamp.node_tree.nodes['Emission'].inputs[1])\n";
|
|
|
|
if (light.q > FLT_EPSILON)
|
|
|
|
os.format("lamp.quadratic_coefficient = 25000 / %f\n", light.q);
|
|
|
|
break;
|
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
template void ReadBabeDeadLightToBlender<DNAMP1::MREA::BabeDeadLight>
|
2017-12-29 08:08:12 +00:00
|
|
|
(hecl::blender::PyOutStream& os, const DNAMP1::MREA::BabeDeadLight& light, unsigned s, unsigned l);
|
2016-08-11 19:52:22 +00:00
|
|
|
template void ReadBabeDeadLightToBlender<DNAMP3::MREA::BabeDeadLight>
|
2017-12-29 08:08:12 +00:00
|
|
|
(hecl::blender::PyOutStream& os, const DNAMP3::MREA::BabeDeadLight& light, unsigned s, unsigned l);
|
2016-08-11 19:52:22 +00:00
|
|
|
|
|
|
|
template<class BabeDeadLight>
|
2017-12-29 08:08:12 +00:00
|
|
|
void WriteBabeDeadLightFromBlender(BabeDeadLight& lightOut, const hecl::blender::Light& lightIn)
|
2016-08-11 19:52:22 +00:00
|
|
|
{
|
2017-12-29 08:08:12 +00:00
|
|
|
using InterType = hecl::blender::Light::Type;
|
2016-08-11 19:52:22 +00:00
|
|
|
switch (lightIn.type)
|
|
|
|
{
|
|
|
|
case InterType::Ambient:
|
|
|
|
lightOut.lightType = BabeDeadLight::LightType::LocalAmbient;
|
|
|
|
break;
|
|
|
|
case InterType::Directional:
|
|
|
|
lightOut.lightType = BabeDeadLight::LightType::Directional;
|
|
|
|
break;
|
|
|
|
case InterType::Custom:
|
|
|
|
default:
|
|
|
|
lightOut.lightType = BabeDeadLight::LightType::Custom;
|
|
|
|
break;
|
|
|
|
case InterType::Spot:
|
|
|
|
lightOut.lightType = BabeDeadLight::LightType::Spot;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2018-01-15 07:39:25 +00:00
|
|
|
if (lightIn.type == InterType::Ambient)
|
|
|
|
{
|
|
|
|
lightOut.falloff = BabeDeadLight::Falloff::Constant;
|
|
|
|
lightOut.q = lightIn.energy * 8.f;
|
|
|
|
}
|
|
|
|
else if (lightIn.linear > lightIn.constant &&
|
|
|
|
lightIn.linear > lightIn.quadratic)
|
2016-08-11 19:52:22 +00:00
|
|
|
{
|
|
|
|
lightOut.falloff = BabeDeadLight::Falloff::Linear;
|
2018-04-04 08:31:29 +00:00
|
|
|
lightOut.q = 250.f / lightIn.linear;
|
2016-08-11 19:52:22 +00:00
|
|
|
}
|
|
|
|
else if (lightIn.quadratic > lightIn.constant &&
|
|
|
|
lightIn.quadratic > lightIn.linear)
|
|
|
|
{
|
|
|
|
lightOut.falloff = BabeDeadLight::Falloff::Quadratic;
|
2018-04-04 08:31:29 +00:00
|
|
|
lightOut.q = 25000.f / lightIn.quadratic;
|
2016-08-11 19:52:22 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
lightOut.falloff = BabeDeadLight::Falloff::Constant;
|
2018-04-04 08:31:29 +00:00
|
|
|
lightOut.q = 2.f / lightIn.constant;
|
2016-08-11 19:52:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
lightOut.color = lightIn.color;
|
2016-08-13 01:29:10 +00:00
|
|
|
lightOut.spotCutoff = zeus::radToDeg(lightIn.spotCutoff);
|
2016-08-11 19:52:22 +00:00
|
|
|
lightOut.castShadows = lightIn.shadow;
|
|
|
|
lightOut.position.vec[0] = lightIn.sceneXf[0].vec[3];
|
|
|
|
lightOut.position.vec[1] = lightIn.sceneXf[1].vec[3];
|
|
|
|
lightOut.position.vec[2] = lightIn.sceneXf[2].vec[3];
|
|
|
|
|
|
|
|
zeus::CTransform lightXf(&lightIn.sceneXf[0]);
|
2018-01-15 07:39:25 +00:00
|
|
|
lightOut.direction = (lightXf.basis.transposed() * zeus::CVector3f(0.f, 0.f, -1.f)).normalized();
|
2016-08-11 19:52:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
template void WriteBabeDeadLightFromBlender<DNAMP1::MREA::BabeDeadLight>
|
2017-12-29 08:08:12 +00:00
|
|
|
(DNAMP1::MREA::BabeDeadLight& lightOut, const hecl::blender::Light& lightIn);
|
2016-08-11 19:52:22 +00:00
|
|
|
template void WriteBabeDeadLightFromBlender<DNAMP3::MREA::BabeDeadLight>
|
2017-12-29 08:08:12 +00:00
|
|
|
(DNAMP3::MREA::BabeDeadLight& lightOut, const hecl::blender::Light& lightIn);
|
2016-08-11 19:52:22 +00:00
|
|
|
|
|
|
|
}
|