mirror of
https://github.com/AxioDL/metaforce.git
synced 2025-12-08 14:24:56 +00:00
SIMD refactor
This commit is contained in:
@@ -39,50 +39,53 @@ size_t ComputeBitstreamSize(size_t keyFrameCount, const std::vector<Channel>& ch
|
||||
static inline QuantizedRot QuantizeRotation(const Value& quat, atUint32 div)
|
||||
{
|
||||
float q = M_PIF / 2.0f / float(div);
|
||||
zeus::simd_floats f(quat.simd);
|
||||
return
|
||||
{
|
||||
{
|
||||
atInt32(std::asin(quat.v4.vec[1]) / q),
|
||||
atInt32(std::asin(quat.v4.vec[2]) / q),
|
||||
atInt32(std::asin(quat.v4.vec[3]) / q),
|
||||
atInt32(std::asin(f[1]) / q),
|
||||
atInt32(std::asin(f[2]) / q),
|
||||
atInt32(std::asin(f[3]) / q),
|
||||
},
|
||||
(quat.v4.vec[0] < 0.f) ? true : false
|
||||
(f[0] < 0.f)
|
||||
};
|
||||
}
|
||||
|
||||
static inline Value DequantizeRotation(const QuantizedRot& v, atUint32 div)
|
||||
{
|
||||
float q = M_PIF / 2.0f / float(div);
|
||||
Value retval =
|
||||
{
|
||||
athena::simd_floats f = {
|
||||
0.0f,
|
||||
std::sin(v.v[0] * q),
|
||||
std::sin(v.v[1] * q),
|
||||
std::sin(v.v[2] * q),
|
||||
};
|
||||
retval.v4.vec[0] = std::sqrt(std::max((1.0f -
|
||||
(retval.v4.vec[1] * retval.v4.vec[1] +
|
||||
retval.v4.vec[2] * retval.v4.vec[2] +
|
||||
retval.v4.vec[3] * retval.v4.vec[3])), 0.0f));
|
||||
retval.v4.vec[0] = v.w ? -retval.v4.vec[0] : retval.v4.vec[0];
|
||||
f[0] = std::sqrt(std::max((1.0f -
|
||||
(f[1] * f[1] +
|
||||
f[2] * f[2] +
|
||||
f[3] * f[3])), 0.0f));
|
||||
f[0] = v.w ? -f[0] : f[0];
|
||||
Value retval;
|
||||
retval.simd.copy_from(f);
|
||||
return retval;
|
||||
}
|
||||
|
||||
static inline Value DequantizeRotation_3(const QuantizedRot& v, atUint32 div)
|
||||
{
|
||||
float q = 1.0f / float(div);
|
||||
Value retval =
|
||||
{
|
||||
athena::simd_floats f = {
|
||||
0.0f,
|
||||
v.v[0] * q,
|
||||
v.v[1] * q,
|
||||
v.v[2] * q,
|
||||
};
|
||||
retval.v4.vec[0] = std::sqrt(std::max((1.0f -
|
||||
(retval.v4.vec[1] * retval.v4.vec[1] +
|
||||
retval.v4.vec[2] * retval.v4.vec[2] +
|
||||
retval.v4.vec[3] * retval.v4.vec[3])), 0.0f));
|
||||
retval.v4.vec[0] = v.w ? -retval.v4.vec[0] : retval.v4.vec[0];
|
||||
f[0] = std::sqrt(std::max((1.0f -
|
||||
(f[1] * f[1] +
|
||||
f[2] * f[2] +
|
||||
f[3] * f[3])), 0.0f));
|
||||
f[0] = v.w ? -f[0] : f[0];
|
||||
Value retval;
|
||||
retval.simd.copy_from(f);
|
||||
return retval;
|
||||
}
|
||||
|
||||
@@ -337,9 +340,10 @@ BitstreamWriter::write(const std::vector<std::vector<Value>>& chanKeys,
|
||||
++it)
|
||||
{
|
||||
const Value* key = &*it;
|
||||
maxTransVal = std::max(maxTransVal, std::fabs(key->v3.vec[0]));
|
||||
maxTransVal = std::max(maxTransVal, std::fabs(key->v3.vec[1]));
|
||||
maxTransVal = std::max(maxTransVal, std::fabs(key->v3.vec[2]));
|
||||
zeus::simd_floats f(key->simd);
|
||||
maxTransVal = std::max(maxTransVal, std::fabs(f[0]));
|
||||
maxTransVal = std::max(maxTransVal, std::fabs(f[1]));
|
||||
maxTransVal = std::max(maxTransVal, std::fabs(f[2]));
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -350,9 +354,10 @@ BitstreamWriter::write(const std::vector<std::vector<Value>>& chanKeys,
|
||||
++it)
|
||||
{
|
||||
const Value* key = &*it;
|
||||
maxScaleVal = std::max(maxScaleVal, std::fabs(key->v3.vec[0]));
|
||||
maxScaleVal = std::max(maxScaleVal, std::fabs(key->v3.vec[1]));
|
||||
maxScaleVal = std::max(maxScaleVal, std::fabs(key->v3.vec[2]));
|
||||
zeus::simd_floats f(key->simd);
|
||||
maxScaleVal = std::max(maxScaleVal, std::fabs(f[0]));
|
||||
maxScaleVal = std::max(maxScaleVal, std::fabs(f[1]));
|
||||
maxScaleVal = std::max(maxScaleVal, std::fabs(f[2]));
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -383,17 +388,19 @@ BitstreamWriter::write(const std::vector<std::vector<Value>>& chanKeys,
|
||||
}
|
||||
case Channel::Type::Translation:
|
||||
{
|
||||
chan.i = {atInt32((*kit)[0].v3.vec[0] / transMultOut),
|
||||
atInt32((*kit)[0].v3.vec[1] / transMultOut),
|
||||
atInt32((*kit)[0].v3.vec[2] / transMultOut)};
|
||||
zeus::simd_floats f((*kit)[0].simd);
|
||||
chan.i = {atInt32(f[0] / transMultOut),
|
||||
atInt32(f[1] / transMultOut),
|
||||
atInt32(f[2] / transMultOut)};
|
||||
initVals.push_back(chan.i);
|
||||
break;
|
||||
}
|
||||
case Channel::Type::Scale:
|
||||
{
|
||||
chan.i = {atInt32((*kit)[0].v3.vec[0] / scaleMultOut),
|
||||
atInt32((*kit)[0].v3.vec[1] / scaleMultOut),
|
||||
atInt32((*kit)[0].v3.vec[2] / scaleMultOut)};
|
||||
zeus::simd_floats f((*kit)[0].simd);
|
||||
chan.i = {atInt32(f[0] / scaleMultOut),
|
||||
atInt32(f[1] / scaleMultOut),
|
||||
atInt32(f[2] / scaleMultOut)};
|
||||
initVals.push_back(chan.i);
|
||||
break;
|
||||
}
|
||||
@@ -431,9 +438,10 @@ BitstreamWriter::write(const std::vector<std::vector<Value>>& chanKeys,
|
||||
it != kit->end();
|
||||
++it)
|
||||
{
|
||||
QuantizedValue cur = {atInt32(it->v3.vec[0] / transMultOut),
|
||||
atInt32(it->v3.vec[1] / transMultOut),
|
||||
atInt32(it->v3.vec[2] / transMultOut)};
|
||||
zeus::simd_floats f(it->simd);
|
||||
QuantizedValue cur = {atInt32(f[0] / transMultOut),
|
||||
atInt32(f[1] / transMultOut),
|
||||
atInt32(f[2] / transMultOut)};
|
||||
chan.q[0] = std::max(chan.q[0], atUint8(cur.qFrom(last, 0)));
|
||||
chan.q[1] = std::max(chan.q[1], atUint8(cur.qFrom(last, 1)));
|
||||
chan.q[2] = std::max(chan.q[2], atUint8(cur.qFrom(last, 2)));
|
||||
@@ -447,9 +455,10 @@ BitstreamWriter::write(const std::vector<std::vector<Value>>& chanKeys,
|
||||
it != kit->end();
|
||||
++it)
|
||||
{
|
||||
QuantizedValue cur = {atInt32(it->v3.vec[0] / scaleMultOut),
|
||||
atInt32(it->v3.vec[1] / scaleMultOut),
|
||||
atInt32(it->v3.vec[2] / scaleMultOut)};
|
||||
zeus::simd_floats f(it->simd);
|
||||
QuantizedValue cur = {atInt32(f[0] / scaleMultOut),
|
||||
atInt32(f[1] / scaleMultOut),
|
||||
atInt32(f[2] / scaleMultOut)};
|
||||
chan.q[0] = std::max(chan.q[0], atUint8(cur.qFrom(last, 0)));
|
||||
chan.q[1] = std::max(chan.q[1], atUint8(cur.qFrom(last, 1)));
|
||||
chan.q[2] = std::max(chan.q[2], atUint8(cur.qFrom(last, 2)));
|
||||
@@ -490,9 +499,10 @@ BitstreamWriter::write(const std::vector<std::vector<Value>>& chanKeys,
|
||||
}
|
||||
case Channel::Type::Translation:
|
||||
{
|
||||
QuantizedValue cur = {atInt32(val.v3.vec[0] / transMultOut),
|
||||
atInt32(val.v3.vec[1] / transMultOut),
|
||||
atInt32(val.v3.vec[2] / transMultOut)};
|
||||
zeus::simd_floats f(val.simd);
|
||||
QuantizedValue cur = {atInt32(f[0] / transMultOut),
|
||||
atInt32(f[1] / transMultOut),
|
||||
atInt32(f[2] / transMultOut)};
|
||||
quantize(newData.get(), chan.q[0], cur[0] - last[0]);
|
||||
quantize(newData.get(), chan.q[1], cur[1] - last[1]);
|
||||
quantize(newData.get(), chan.q[2], cur[2] - last[2]);
|
||||
@@ -501,9 +511,10 @@ BitstreamWriter::write(const std::vector<std::vector<Value>>& chanKeys,
|
||||
}
|
||||
case Channel::Type::Scale:
|
||||
{
|
||||
QuantizedValue cur = {atInt32(val.v3.vec[0] / scaleMultOut),
|
||||
atInt32(val.v3.vec[1] / scaleMultOut),
|
||||
atInt32(val.v3.vec[2] / scaleMultOut)};
|
||||
zeus::simd_floats f(val.simd);
|
||||
QuantizedValue cur = {atInt32(f[0] / scaleMultOut),
|
||||
atInt32(f[1] / scaleMultOut),
|
||||
atInt32(f[2] / scaleMultOut)};
|
||||
quantize(newData.get(), chan.q[0], cur[0] - last[0]);
|
||||
quantize(newData.get(), chan.q[1], cur[1] - last[1]);
|
||||
quantize(newData.get(), chan.q[2], cur[2] - last[2]);
|
||||
|
||||
@@ -6,33 +6,22 @@
|
||||
namespace DataSpec::DNAANIM
|
||||
{
|
||||
|
||||
union Value
|
||||
struct Value
|
||||
{
|
||||
atVec3f v3;
|
||||
atVec4f v4;
|
||||
Value(atVec3f v) : v3(v) {}
|
||||
Value(atVec4f v) : v4(v) {}
|
||||
Value(float x, float y, float z)
|
||||
{
|
||||
v3.vec[0] = x;
|
||||
v3.vec[1] = y;
|
||||
v3.vec[2] = z;
|
||||
v4.vec[3] = 0.0;
|
||||
}
|
||||
Value(float w, float x, float y, float z)
|
||||
{
|
||||
v4.vec[0] = w;
|
||||
v4.vec[1] = x;
|
||||
v4.vec[2] = y;
|
||||
v4.vec[3] = z;
|
||||
}
|
||||
athena::simd<float> simd;
|
||||
Value() = default;
|
||||
Value(const athena::simd<float>& s) : simd(s) {}
|
||||
Value(const atVec3f& v) : simd(v.simd) {}
|
||||
Value(const atVec4f& v) : simd(v.simd) {}
|
||||
Value(float x, float y, float z) : simd(x, y, z, 0.f) {}
|
||||
Value(float w, float x, float y, float z) : simd(w, x, y, z) {}
|
||||
};
|
||||
struct QuantizedValue
|
||||
{
|
||||
atInt32 v[4];
|
||||
atInt32& operator[] (size_t idx)
|
||||
{return v[idx];}
|
||||
const atInt32& operator[] (size_t idx) const
|
||||
atInt32 operator[] (size_t idx) const
|
||||
{return v[idx];}
|
||||
|
||||
int qFrom(const QuantizedValue& other, size_t idx) const
|
||||
|
||||
@@ -86,7 +86,7 @@ void AROTBuilder::Node::addChild(int level, int minChildren, const std::vector<z
|
||||
return;
|
||||
}
|
||||
else if (childIndices.size() < minChildren || level == AROT_MAX_LEVEL ||
|
||||
std::max(extents.x, std::max(extents.y, extents.z)) < AROT_MIN_SUBDIV)
|
||||
std::max(extents.x(), std::max(extents.y(), extents.z())) < AROT_MIN_SUBDIV)
|
||||
{
|
||||
typeOut = BspNodeType::Leaf;
|
||||
return;
|
||||
@@ -103,21 +103,21 @@ void AROTBuilder::Node::addChild(int level, int minChildren, const std::vector<z
|
||||
}
|
||||
|
||||
/* Unsubdivide minimum axis dimensions */
|
||||
if (extents.x < AROT_MIN_SUBDIV)
|
||||
if (extents.x() < AROT_MIN_SUBDIV)
|
||||
{
|
||||
mergeSets(0, 1);
|
||||
mergeSets(4, 5);
|
||||
mergeSets(2, 3);
|
||||
mergeSets(6, 7);
|
||||
}
|
||||
if (extents.y < AROT_MIN_SUBDIV)
|
||||
if (extents.y() < AROT_MIN_SUBDIV)
|
||||
{
|
||||
mergeSets(0, 2);
|
||||
mergeSets(1, 3);
|
||||
mergeSets(4, 6);
|
||||
mergeSets(5, 7);
|
||||
}
|
||||
if (extents.z < AROT_MIN_SUBDIV)
|
||||
if (extents.z() < AROT_MIN_SUBDIV)
|
||||
{
|
||||
mergeSets(0, 4);
|
||||
mergeSets(1, 5);
|
||||
|
||||
@@ -17,7 +17,7 @@ void ReadBabeDeadLightToBlender(hecl::blender::PyOutStream& os,
|
||||
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],
|
||||
light.color.simd[0], light.color.simd[1], light.color.simd[2],
|
||||
light.q / 8.f);
|
||||
return;
|
||||
case BabeDeadLight::LightType::Directional:
|
||||
@@ -27,8 +27,8 @@ void ReadBabeDeadLightToBlender(hecl::blender::PyOutStream& os,
|
||||
"lamp_obj.rotation_mode = 'QUATERNION'\n"
|
||||
"lamp_obj.rotation_quaternion = Vector((0,0,-1)).rotation_difference(Vector((%f,%f,%f)))\n"
|
||||
"lamp.shadow_method = '%s'\n"
|
||||
"\n", s, l, light.color.vec[0], light.color.vec[1], light.color.vec[2],
|
||||
light.direction.vec[0], light.direction.vec[1], light.direction.vec[2],
|
||||
"\n", s, l, light.color.simd[0], light.color.simd[1], light.color.simd[2],
|
||||
light.direction.simd[0], light.direction.simd[1], light.direction.simd[2],
|
||||
light.castShadows ? "RAY_SHADOW" : "NOSHADOW");
|
||||
return;
|
||||
case BabeDeadLight::LightType::Custom:
|
||||
@@ -37,7 +37,7 @@ void ReadBabeDeadLightToBlender(hecl::blender::PyOutStream& os,
|
||||
"lamp_obj = bpy.data.objects.new(lamp.name, lamp)\n"
|
||||
"lamp.shadow_soft_size = 1.0\n"
|
||||
"lamp.shadow_method = '%s'\n"
|
||||
"\n", s, l, light.color.vec[0], light.color.vec[1], light.color.vec[2],
|
||||
"\n", s, l, light.color.simd[0], light.color.simd[1], light.color.simd[2],
|
||||
light.castShadows ? "RAY_SHADOW" : "NOSHADOW");
|
||||
break;
|
||||
case BabeDeadLight::LightType::Spot:
|
||||
@@ -50,9 +50,9 @@ void ReadBabeDeadLightToBlender(hecl::blender::PyOutStream& os,
|
||||
"lamp_obj.rotation_quaternion = Vector((0,0,-1)).rotation_difference(Vector((%f,%f,%f)))\n"
|
||||
"lamp.shadow_soft_size = 0.5\n"
|
||||
"lamp.shadow_method = '%s'\n"
|
||||
"\n", s, l, light.color.vec[0], light.color.vec[1], light.color.vec[2],
|
||||
"\n", s, l, light.color.simd[0], light.color.simd[1], light.color.simd[2],
|
||||
zeus::degToRad(light.spotCutoff),
|
||||
light.direction.vec[0], light.direction.vec[1], light.direction.vec[2],
|
||||
light.direction.simd[0], light.direction.simd[1], light.direction.simd[2],
|
||||
light.castShadows ? "RAY_SHADOW" : "NOSHADOW");
|
||||
break;
|
||||
default: return;
|
||||
@@ -73,8 +73,8 @@ void ReadBabeDeadLightToBlender(hecl::blender::PyOutStream& os,
|
||||
"lamp_obj.location = (%f,%f,%f)\n"
|
||||
"bpy.context.scene.objects.link(lamp_obj)\n"
|
||||
"\n", s, light.lightType, light.q / 8.f,
|
||||
light.color.vec[0], light.color.vec[1], light.color.vec[2],
|
||||
light.position.vec[0], light.position.vec[1], light.position.vec[2]);
|
||||
light.color.simd[0], light.color.simd[1], light.color.simd[2],
|
||||
light.position.simd[0], light.position.simd[1], light.position.simd[2]);
|
||||
|
||||
switch (light.falloff)
|
||||
{
|
||||
@@ -150,9 +150,9 @@ void WriteBabeDeadLightFromBlender(BabeDeadLight& lightOut, const hecl::blender:
|
||||
lightOut.color = lightIn.color;
|
||||
lightOut.spotCutoff = zeus::radToDeg(lightIn.spotCutoff);
|
||||
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];
|
||||
lightOut.position.simd[0] = lightIn.sceneXf[0].simd[3];
|
||||
lightOut.position.simd[1] = lightIn.sceneXf[1].simd[3];
|
||||
lightOut.position.simd[2] = lightIn.sceneXf[2].simd[3];
|
||||
|
||||
zeus::CTransform lightXf(&lightIn.sceneXf[0]);
|
||||
lightOut.direction = (lightXf.basis.transposed() * zeus::CVector3f(0.f, 0.f, -1.f)).normalized();
|
||||
|
||||
@@ -786,7 +786,7 @@ atUint32 ReadGeomSectionsToBlender(hecl::blender::PyOutStream& os,
|
||||
positions.push_back(reader.readVec3fBig());
|
||||
const atVec3f& pos = positions.back();
|
||||
os.format("vert = bm.verts.new((%f,%f,%f))\n",
|
||||
pos.vec[0], pos.vec[1], pos.vec[2]);
|
||||
pos.simd[0], pos.simd[1], pos.simd[2]);
|
||||
if (rp.first)
|
||||
{
|
||||
if (SurfaceHeader::UseMatrixSkinning() && !skinIndices.empty())
|
||||
@@ -802,7 +802,7 @@ atUint32 ReadGeomSectionsToBlender(hecl::blender::PyOutStream& os,
|
||||
{
|
||||
const atVec3f& pos = positions[i];
|
||||
os.format("vert = bm.verts.new((%f,%f,%f))\n",
|
||||
pos.vec[0], pos.vec[1], pos.vec[2]);
|
||||
pos.simd[0], pos.simd[1], pos.simd[2]);
|
||||
if (rp.first)
|
||||
{
|
||||
if (SurfaceHeader::UseMatrixSkinning() && !skinIndices.empty())
|
||||
@@ -836,9 +836,9 @@ atUint32 ReadGeomSectionsToBlender(hecl::blender::PyOutStream& os,
|
||||
size_t normCount = secSizes[s] / 12;
|
||||
for (size_t i=0 ; i<normCount ; ++i)
|
||||
{
|
||||
atVec3f norm = reader.readVec3fBig();
|
||||
const atVec3f norm = reader.readVec3fBig();
|
||||
os.format("norm_list.append((%f,%f,%f))\n",
|
||||
norm.vec[0], norm.vec[1], norm.vec[2]);
|
||||
norm.simd[0], norm.simd[1], norm.simd[2]);
|
||||
}
|
||||
}
|
||||
break;
|
||||
@@ -855,9 +855,9 @@ atUint32 ReadGeomSectionsToBlender(hecl::blender::PyOutStream& os,
|
||||
size_t uvCount = secSizes[s] / 8;
|
||||
for (size_t i=0 ; i<uvCount ; ++i)
|
||||
{
|
||||
atVec2f uv = reader.readVec2fBig();
|
||||
const atVec2f uv = reader.readVec2fBig();
|
||||
os.format("uv_list.append((%f,%f))\n",
|
||||
uv.vec[0], uv.vec[1]);
|
||||
uv.simd[0], uv.simd[1]);
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -1461,7 +1461,7 @@ bool WriteCMDL(const hecl::ProjectPath& outPath, const hecl::ProjectPath& inPath
|
||||
{
|
||||
for (int i = 0; i < 3; ++i)
|
||||
{
|
||||
int tmpV = int(norm.vec[i] * 16384.f);
|
||||
int tmpV = int(norm.simd[i] * 16384.f);
|
||||
tmpV = zeus::clamp(-32768, tmpV, 32767);
|
||||
writer.writeInt16Big(atInt16(tmpV));
|
||||
}
|
||||
@@ -1992,7 +1992,7 @@ bool WriteMREASecs(std::vector<std::vector<uint8_t>>& secsOut, const hecl::Proje
|
||||
{
|
||||
for (int i=0 ; i<2 ; ++i)
|
||||
{
|
||||
int tmpV = int(v.val.vec[i] * 32768.f);
|
||||
int tmpV = int(v.val.simd[i] * 32768.f);
|
||||
tmpV = zeus::clamp(-32768, tmpV, 32767);
|
||||
w.writeInt16Big(atInt16(tmpV));
|
||||
}
|
||||
|
||||
@@ -41,20 +41,23 @@ template <> inline void DNAColor::Enumerate<BigDNA::ReadYaml>(typename ReadYaml:
|
||||
size_t count;
|
||||
if (auto v = _r.enterSubVector(nullptr, count))
|
||||
{
|
||||
r = (count >= 1) ? _r.readFloat(nullptr) : 0.f;
|
||||
g = (count >= 2) ? _r.readFloat(nullptr) : 0.f;
|
||||
b = (count >= 3) ? _r.readFloat(nullptr) : 0.f;
|
||||
a = (count >= 4) ? _r.readFloat(nullptr) : 0.f;
|
||||
zeus::simd_floats f;
|
||||
f[0] = (count >= 1) ? _r.readFloat(nullptr) : 0.f;
|
||||
f[1] = (count >= 2) ? _r.readFloat(nullptr) : 0.f;
|
||||
f[2] = (count >= 3) ? _r.readFloat(nullptr) : 0.f;
|
||||
f[3] = (count >= 4) ? _r.readFloat(nullptr) : 0.f;
|
||||
mSimd.copy_from(f);
|
||||
}
|
||||
}
|
||||
template <> inline void DNAColor::Enumerate<BigDNA::WriteYaml>(typename WriteYaml::StreamT& _w)
|
||||
{
|
||||
if (auto v = _w.enterSubVector(nullptr))
|
||||
{
|
||||
_w.writeFloat(nullptr, r);
|
||||
_w.writeFloat(nullptr, g);
|
||||
_w.writeFloat(nullptr, b);
|
||||
_w.writeFloat(nullptr, a);
|
||||
zeus::simd_floats f(mSimd);
|
||||
_w.writeFloat(nullptr, f[0]);
|
||||
_w.writeFloat(nullptr, f[1]);
|
||||
_w.writeFloat(nullptr, f[2]);
|
||||
_w.writeFloat(nullptr, f[3]);
|
||||
}
|
||||
}
|
||||
template <> inline void DNAColor::Enumerate<BigDNA::BinarySize>(typename BinarySize::StreamT& _s)
|
||||
|
||||
@@ -15,10 +15,10 @@ void DeafBabeSendToBlender(hecl::blender::PyOutStream& os, const DEAFBABE& db, b
|
||||
os << "material_index = []\n"
|
||||
"col_bm = bmesh.new()\n";
|
||||
for (const atVec3f& vert : db.verts)
|
||||
os.format("col_bm.verts.new((%f,%f,%f))\n",
|
||||
vert.vec[0],
|
||||
vert.vec[1],
|
||||
vert.vec[2]);
|
||||
{
|
||||
zeus::simd_floats f(vert.simd);
|
||||
os.format("col_bm.verts.new((%f,%f,%f))\n", f[0], f[1], f[2]);
|
||||
}
|
||||
|
||||
os << "col_bm.verts.ensure_lookup_table()\n";
|
||||
|
||||
|
||||
@@ -185,6 +185,9 @@ bool ReadMAPAToBlender(hecl::blender::Connection& conn,
|
||||
if (mapa.version < 5)
|
||||
{
|
||||
const MAPA::MappableObjectMP1_2* moMP12 = static_cast<const MAPA::MappableObjectMP1_2*>(mo.get());
|
||||
zeus::simd_floats mtxF[3];
|
||||
for (int i = 0; i < 3; ++i)
|
||||
moMP12->transformMtx[i].simd.copy_to(mtxF[i]);
|
||||
os.format("obj = bpy.data.objects.new('MAPOBJ_%02d', None)\n"
|
||||
"bpy.context.scene.objects.link(obj)\n"
|
||||
"obj.retro_mappable_type = %d\n"
|
||||
@@ -197,15 +200,18 @@ bool ReadMAPAToBlender(hecl::blender::Connection& conn,
|
||||
"obj.rotation_quaternion = mtxd[1]\n"
|
||||
"obj.scale = mtxd[2]\n",
|
||||
moIdx, moMP12->type, RetroMapObjVisModes[moMP12->visMode], moMP12->sclyId,
|
||||
moMP12->transformMtx[0].vec[0], moMP12->transformMtx[0].vec[1], moMP12->transformMtx[0].vec[2], moMP12->transformMtx[0].vec[3],
|
||||
moMP12->transformMtx[1].vec[0], moMP12->transformMtx[1].vec[1], moMP12->transformMtx[1].vec[2], moMP12->transformMtx[1].vec[3],
|
||||
moMP12->transformMtx[2].vec[0], moMP12->transformMtx[2].vec[1], moMP12->transformMtx[2].vec[2], moMP12->transformMtx[2].vec[3]);
|
||||
mtxF[0][0], mtxF[0][1], mtxF[0][2], mtxF[0][3],
|
||||
mtxF[1][0], mtxF[1][1], mtxF[1][2], mtxF[1][3],
|
||||
mtxF[2][0], mtxF[2][1], mtxF[2][2], mtxF[2][3]);
|
||||
++moIdx;
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
const MAPA::MappableObjectMP3* moMP3 = static_cast<const MAPA::MappableObjectMP3*>(mo.get());
|
||||
zeus::simd_floats mtxF[3];
|
||||
for (int i = 0; i < 3; ++i)
|
||||
moMP3->transformMtx[i].simd.copy_to(mtxF[i]);
|
||||
os.format("obj = bpy.data.objects.new('MAPOBJ_%02d', None)\n"
|
||||
"bpy.context.scene.objects.link(obj)\n"
|
||||
"obj.retro_mappable_type = %d\n"
|
||||
@@ -218,9 +224,9 @@ bool ReadMAPAToBlender(hecl::blender::Connection& conn,
|
||||
"obj.rotation_quaternion = mtxd[1]\n"
|
||||
"obj.scale = mtxd[2]\n",
|
||||
moIdx, moMP3->type, RetroMapObjVisModes[moMP3->visMode], moMP3->sclyId,
|
||||
moMP3->transformMtx[0].vec[0], moMP3->transformMtx[0].vec[1], moMP3->transformMtx[0].vec[2], moMP3->transformMtx[0].vec[3],
|
||||
moMP3->transformMtx[1].vec[0], moMP3->transformMtx[1].vec[1], moMP3->transformMtx[1].vec[2], moMP3->transformMtx[1].vec[3],
|
||||
moMP3->transformMtx[2].vec[0], moMP3->transformMtx[2].vec[1], moMP3->transformMtx[2].vec[2], moMP3->transformMtx[2].vec[3]);
|
||||
mtxF[0][0], mtxF[0][1], mtxF[0][2], mtxF[0][3],
|
||||
mtxF[1][0], mtxF[1][1], mtxF[1][2], mtxF[1][3],
|
||||
mtxF[2][0], mtxF[2][1], mtxF[2][2], mtxF[2][3]);
|
||||
++moIdx;
|
||||
continue;
|
||||
}
|
||||
@@ -232,8 +238,10 @@ bool ReadMAPAToBlender(hecl::blender::Connection& conn,
|
||||
|
||||
/* Read in verts */
|
||||
for (const atVec3f& vert : mapa.vertices)
|
||||
os.format("bm.verts.new((%f,%f,%f))\n",
|
||||
vert.vec[0], vert.vec[1], vert.vec[2]);
|
||||
{
|
||||
zeus::simd_floats f(vert.simd);
|
||||
os.format("bm.verts.new((%f,%f,%f))\n", f[0], f[1], f[2]);
|
||||
}
|
||||
os << "bm.verts.ensure_lookup_table()\n";
|
||||
|
||||
/* Read in surfaces */
|
||||
|
||||
@@ -47,6 +47,10 @@ bool ReadMAPUToBlender(hecl::blender::Connection& conn,
|
||||
{
|
||||
hecl::ProjectPath path = UniqueIDBridge::TranslatePakIdToPath(wld.mlvl);
|
||||
const MAPU::Transform& wldXf = wld.transform;
|
||||
zeus::simd_floats wldXfF[3];
|
||||
for (int i = 0; i < 3; ++i)
|
||||
wldXf.xf[i].simd.copy_to(wldXfF[i]);
|
||||
zeus::simd_floats hexColorF(wld.hexColor.mSimd);
|
||||
os.format("wldObj = bpy.data.objects.new('%s', None)\n"
|
||||
"mtx = Matrix(((%f,%f,%f,%f),(%f,%f,%f,%f),(%f,%f,%f,%f),(0.0,0.0,0.0,1.0)))\n"
|
||||
"mtxd = mtx.decompose()\n"
|
||||
@@ -57,14 +61,17 @@ bool ReadMAPUToBlender(hecl::blender::Connection& conn,
|
||||
"wldObj.retro_mapworld_color = (%f, %f, %f, %f)\n"
|
||||
"wldObj.retro_mapworld_path = '''%s'''\n"
|
||||
"bpy.context.scene.objects.link(wldObj)\n", wld.name.c_str(),
|
||||
wldXf.xf[0].vec[0], wldXf.xf[0].vec[1], wldXf.xf[0].vec[2], wldXf.xf[0].vec[3],
|
||||
wldXf.xf[1].vec[0], wldXf.xf[1].vec[1], wldXf.xf[1].vec[2], wldXf.xf[1].vec[3],
|
||||
wldXf.xf[2].vec[0], wldXf.xf[2].vec[1], wldXf.xf[2].vec[2], wldXf.xf[2].vec[3],
|
||||
wld.hexColor.r, wld.hexColor.g, wld.hexColor.b, wld.hexColor.a,
|
||||
wldXfF[0][0], wldXfF[0][1], wldXfF[0][2], wldXfF[0][3],
|
||||
wldXfF[1][0], wldXfF[1][1], wldXfF[1][2], wldXfF[1][3],
|
||||
wldXfF[2][0], wldXfF[2][1], wldXfF[2][2], wldXfF[2][3],
|
||||
hexColorF[0], hexColorF[1], hexColorF[2], hexColorF[3],
|
||||
path.getParentPath().getRelativePathUTF8().data());
|
||||
int idx = 0;
|
||||
for (const MAPU::Transform& hexXf : wld.hexTransforms)
|
||||
{
|
||||
zeus::simd_floats hexXfF[3];
|
||||
for (int i = 0; i < 3; ++i)
|
||||
hexXf.xf[i].simd.copy_to(hexXfF[i]);
|
||||
os.format("obj = bpy.data.objects.new('%s_%d', hexMesh)\n"
|
||||
"mtx = Matrix(((%f,%f,%f,%f),(%f,%f,%f,%f),(%f,%f,%f,%f),(0.0,0.0,0.0,1.0)))\n"
|
||||
"mtxd = mtx.decompose()\n"
|
||||
@@ -75,9 +82,9 @@ bool ReadMAPUToBlender(hecl::blender::Connection& conn,
|
||||
"bpy.context.scene.objects.link(obj)\n"
|
||||
"obj.parent = wldObj\n",
|
||||
wld.name.c_str(), idx++,
|
||||
hexXf.xf[0].vec[0], hexXf.xf[0].vec[1], hexXf.xf[0].vec[2], hexXf.xf[0].vec[3],
|
||||
hexXf.xf[1].vec[0], hexXf.xf[1].vec[1], hexXf.xf[1].vec[2], hexXf.xf[1].vec[3],
|
||||
hexXf.xf[2].vec[0], hexXf.xf[2].vec[1], hexXf.xf[2].vec[2], hexXf.xf[2].vec[3]);
|
||||
hexXfF[0][0], hexXfF[0][1], hexXfF[0][2], hexXfF[0][3],
|
||||
hexXfF[1][0], hexXfF[1][1], hexXfF[1][2], hexXfF[1][3],
|
||||
hexXfF[2][0], hexXfF[2][1], hexXfF[2][2], hexXfF[2][3]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -44,6 +44,9 @@ bool ReadMLVLToBlender(hecl::blender::Connection& conn,
|
||||
hecl::SystemUTF8Conv areaDirName(*mreaEntry->unique.m_areaName);
|
||||
|
||||
os.AABBToBMesh(area.aabb[0], area.aabb[1]);
|
||||
zeus::simd_floats xfMtxF[3];
|
||||
for (int i = 0; i < 3; ++i)
|
||||
area.transformMtx[i].simd.copy_to(xfMtxF[i]);
|
||||
os.format("box_mesh = bpy.data.meshes.new('''%s''')\n"
|
||||
"bm.to_mesh(box_mesh)\n"
|
||||
"bm.free()\n"
|
||||
@@ -56,9 +59,9 @@ bool ReadMLVLToBlender(hecl::blender::Connection& conn,
|
||||
"box.rotation_quaternion = mtxd[1]\n"
|
||||
"box.scale = mtxd[2]\n",
|
||||
areaDirName.str().data(),
|
||||
area.transformMtx[0].vec[0], area.transformMtx[0].vec[1], area.transformMtx[0].vec[2], area.transformMtx[0].vec[3],
|
||||
area.transformMtx[1].vec[0], area.transformMtx[1].vec[1], area.transformMtx[1].vec[2], area.transformMtx[1].vec[3],
|
||||
area.transformMtx[2].vec[0], area.transformMtx[2].vec[1], area.transformMtx[2].vec[2], area.transformMtx[2].vec[3]);
|
||||
xfMtxF[0][0], xfMtxF[0][1], xfMtxF[0][2], xfMtxF[0][3],
|
||||
xfMtxF[1][0], xfMtxF[1][1], xfMtxF[1][2], xfMtxF[1][3],
|
||||
xfMtxF[2][0], xfMtxF[2][1], xfMtxF[2][2], xfMtxF[2][3]);
|
||||
|
||||
/* Insert dock planes */
|
||||
int dockIdx = 0;
|
||||
@@ -72,7 +75,7 @@ bool ReadMLVLToBlender(hecl::blender::Connection& conn,
|
||||
int idx = 0;
|
||||
for (const atVec3f& pv : dock.planeVerts)
|
||||
{
|
||||
zeus::CVector3f pvRel = zeus::CVector3f(pv) - pvAvg;
|
||||
const zeus::CVector3f pvRel = zeus::CVector3f(pv) - pvAvg;
|
||||
os.format("bm.verts.new((%f,%f,%f))\n"
|
||||
"bm.verts.ensure_lookup_table()\n",
|
||||
pvRel[0], pvRel[1], pvRel[2]);
|
||||
@@ -88,7 +91,7 @@ bool ReadMLVLToBlender(hecl::blender::Connection& conn,
|
||||
"bm.free()\n"
|
||||
"dockObj.parent = box\n";
|
||||
os.format("dockObj.location = (%f,%f,%f)\n",
|
||||
pvAvg[0], pvAvg[1], pvAvg[2]);
|
||||
float(pvAvg[0]), float(pvAvg[1]), float(pvAvg[2]));
|
||||
++dockIdx;
|
||||
}
|
||||
++areaIdx;
|
||||
|
||||
@@ -59,9 +59,9 @@ static FittedOBB BuildFromCovarianceMatrix(gmm::dense_matrix<float>& C,
|
||||
r.normalize(); u.normalize(), f.normalize();
|
||||
|
||||
// set the rotation matrix using the eigvenvectors
|
||||
ret.xf.basis[0][0]=r.x; ret.xf.basis[1][0]=u.x; ret.xf.basis[2][0]=f.x;
|
||||
ret.xf.basis[0][1]=r.y; ret.xf.basis[1][1]=u.y; ret.xf.basis[2][1]=f.y;
|
||||
ret.xf.basis[0][2]=r.z; ret.xf.basis[1][2]=u.z; ret.xf.basis[2][2]=f.z;
|
||||
ret.xf.basis[0] = r;
|
||||
ret.xf.basis[1] = u;
|
||||
ret.xf.basis[2] = f;
|
||||
|
||||
// now build the bounding box extents in the rotated frame
|
||||
zeus::CVector3f minim(1e10f, 1e10f, 1e10f), maxim(-1e10f, -1e10f, -1e10f);
|
||||
@@ -115,11 +115,11 @@ static FittedOBB FitOBB(const ColMesh& mesh, const std::vector<int>& index)
|
||||
Am += Ai;
|
||||
|
||||
// these bits set the c terms to Am*E[xx], Am*E[xy], Am*E[xz]....
|
||||
cxx += ( 9.0*mui.x*mui.x + p.x*p.x + q.x*q.x + r.x*r.x )*(Ai/12.0);
|
||||
cxy += ( 9.0*mui.x*mui.y + p.x*p.y + q.x*q.y + r.x*r.y )*(Ai/12.0);
|
||||
cxz += ( 9.0*mui.x*mui.z + p.x*p.z + q.x*q.z + r.x*r.z )*(Ai/12.0);
|
||||
cyy += ( 9.0*mui.y*mui.y + p.y*p.y + q.y*q.y + r.y*r.y )*(Ai/12.0);
|
||||
cyz += ( 9.0*mui.y*mui.z + p.y*p.z + q.y*q.z + r.y*r.z )*(Ai/12.0);
|
||||
cxx += ( 9.0*mui.x()*mui.x() + p.x()*p.x() + q.x()*q.x() + r.x()*r.x() )*(Ai/12.0);
|
||||
cxy += ( 9.0*mui.x()*mui.y() + p.x()*p.y() + q.x()*q.y() + r.x()*r.y() )*(Ai/12.0);
|
||||
cxz += ( 9.0*mui.x()*mui.z() + p.x()*p.z() + q.x()*q.z() + r.x()*r.z() )*(Ai/12.0);
|
||||
cyy += ( 9.0*mui.y()*mui.y() + p.y()*p.y() + q.y()*q.y() + r.y()*r.y() )*(Ai/12.0);
|
||||
cyz += ( 9.0*mui.y()*mui.z() + p.y()*p.z() + q.y()*q.z() + r.y()*r.z() )*(Ai/12.0);
|
||||
}
|
||||
|
||||
if (zeus::close_enough(Am, 0.f))
|
||||
@@ -131,8 +131,8 @@ static FittedOBB FitOBB(const ColMesh& mesh, const std::vector<int>& index)
|
||||
cxx /= Am; cxy /= Am; cxz /= Am; cyy /= Am; cyz /= Am; czz /= Am;
|
||||
|
||||
// now subtract off the E[x]*E[x], E[x]*E[y], ... terms
|
||||
cxx -= mu.x*mu.x; cxy -= mu.x*mu.y; cxz -= mu.x*mu.z;
|
||||
cyy -= mu.y*mu.y; cyz -= mu.y*mu.z; czz -= mu.z*mu.z;
|
||||
cxx -= mu.x()*mu.x(); cxy -= mu.x()*mu.y(); cxz -= mu.x()*mu.z();
|
||||
cyy -= mu.y()*mu.y(); cyz -= mu.y()*mu.z(); czz -= mu.z()*mu.z();
|
||||
|
||||
// now build the covariance matrix
|
||||
C(0,0)=cxx; C(0,1)=cxy; C(0,2)=cxz;
|
||||
@@ -169,7 +169,7 @@ static std::unique_ptr<Node> RecursiveMakeNode(const ColMesh& mesh, const std::v
|
||||
for (int i = 0; i < 3; ++i)
|
||||
{
|
||||
n->xf[i] = zeus::CVector4f{obb.xf.basis[i]};
|
||||
n->xf[i].vec[3] = obb.xf.origin[i];
|
||||
n->xf[i].simd[3] = float(obb.xf.origin[i]);
|
||||
}
|
||||
n->halfExtent = obb.he;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user