#include "dl_model_loader.h" // Android dl_concept.h 宏名字冲突需要前置 #ifndef DL_DISABLE_RENDER #include "io/dl_log.h" #include "render/dl_model.h" #include "render/dl_model_object.h" namespace dl { std::vector ModelObject::Create(std::string_view path_name, std::string_view res_name) { std::vector ret = g_modelLoader->Load(path_name, res_name); if (ret.empty()) { log_err("模型加载失败:{}", path_name); return {}; } return ret; } void ModelObject::Load(std::string_view path_name) { /*StreamInput s; if (!s.LoadFromFile(path_name, true)) { log_warn("文件加载失败:{}", path_name ); return; } s.Read(&_allVertex); s.Read(&_allVertexBone); s.Read(&_allIndex); s.Read(&_allSub); size_t size; s.Read64(&size); _allMaterial.resize(size); for (size_t i = 0; i < size; ++i) { _allMaterial[i].Load(s); } bool has_bone; s.Read(&has_bone); if (has_bone) { _boneData = new BoneData; _boneData->Load(s); } else _boneData = nullptr;*/ } void ModelObject::SaveToFile(std::string_view path_name) { /*StreamOutput s; s.Write(&_allVertex); s.Write(&_allVertexBone); s.Write(&_allIndex); s.Write(&_allSub); size_t size = _allMaterial.size(); s.Write64(&size); for (size_t i = 0; i < size; ++i) { _allMaterial[i].Save(s); } bool has_bone = _boneData; s.Write(&has_bone); if (has_bone) { _boneData->Save(s); } s.Save(path_name, true);*/ } void ModelAnimationInstance::Update(FloatTime dt) { if (_indexAni > _model->_allAnimation.size()) { log_warn("动画下标越界!"); return; } _t += dt; const ModelAnimation& ani = _model->_allAnimation[_indexAni]; if (_t > ani.end) { _t = 0; } // 动画插值(操作动画控制的节点) bool updated = false; for (const ModelAnimationChannel& channel : ani._allChannel) { ModelNodeRt* node = GetNode(channel.indexNode); const ModelAnimationSampler& sampler = ani._allSampler[channel.samplerIndex]; if (sampler.inputs.size() > sampler.outputsVec4.size()) { continue; } float time = _t; for (size_t i = 0; i < sampler.inputs.size() - 1; i++) { if (time >= sampler.inputs[i] && time <= sampler.inputs[i + 1]) { float u = std::max(0.0f, time - sampler.inputs[i]) / (sampler.inputs[i + 1] - sampler.inputs[i]); if (u <= 1.0f) { switch (channel.path) { case ModelAnimationChannel::PathType::TRANSLATION: sampler.translate(i, time, node); break; case ModelAnimationChannel::PathType::SCALE: sampler.scale(i, time, node); break; case ModelAnimationChannel::PathType::ROTATION: sampler.rotate(i, time, node); break; } updated = true; } } } } // 节点树更新 if (updated) { for (size_t i = 0; i < _treeNode.size(); ++i) { ModelNodeRt& node = _treeNode[i]; node.Update(_model->_allSkin, this); } } int x = 3; } } #endif