| 2124 | } |
| 2125 | |
| 2126 | void RiggedObject::ApplyBoneMatricesToModel(bool old, int lod_level) { |
| 2127 | Model* model = &Models::Instance()->GetModel(model_id[lod_level]); |
| 2128 | Online* online = Online::Instance(); |
| 2129 | |
| 2130 | std::vector<MorphTarget*> active_morph_targets; |
| 2131 | const bool kMorphTargetsEnabled = true; |
| 2132 | if (kMorphTargetsEnabled) { |
| 2133 | // Determine which morphs are active (have effective weight > 0) |
| 2134 | for (auto& m_t : morph_targets) { |
| 2135 | if (online->IsClient() || m_t.weight > 0.0f || |
| 2136 | (m_t.anim_weight > 0.0f && m_t.script_weight_weight < 1.0f) || |
| 2137 | (m_t.script_weight > 0.0f && m_t.script_weight_weight > 0.0f)) { |
| 2138 | m_t.PreDrawCamera(GetTimeBetweenLastTwoAnimUpdates(), GetTimeSinceLastAnimUpdate(), lod_level, char_id); |
| 2139 | if (online->IsClient() || m_t.weight > 0.0f) { |
| 2140 | active_morph_targets.push_back(&m_t); |
| 2141 | } |
| 2142 | } |
| 2143 | } |
| 2144 | |
| 2145 | // Initialize per-vertex morph accumulators |
| 2146 | for (int j = 0, len = model->vertices.size() / 3; j < len; j++) { |
| 2147 | model->tex_transform_vec[j] = 0.0f; |
| 2148 | model->morph_transform_vec[j] = 0.0f; |
| 2149 | } |
| 2150 | |
| 2151 | // Accumulate the effect of all active morphs |
| 2152 | Models* mi = Models::Instance(); |
| 2153 | int vert_id, vert_id_index; |
| 2154 | for (auto morph : active_morph_targets) { |
| 2155 | const Model* morph_model = &mi->GetModel(morph->model_id[lod_level]); |
| 2156 | const std::vector<int>& modified_tc = morph->modified_tc[lod_level]; |
| 2157 | for (int j : modified_tc) { |
| 2158 | vert_id = j; |
| 2159 | vert_id_index = vert_id * 2; |
| 2160 | model->tex_transform_vec[vert_id] += |
| 2161 | vec2(morph_model->tex_coords[vert_id_index + 0], |
| 2162 | morph_model->tex_coords[vert_id_index + 1]) * |
| 2163 | morph->disp_weight; |
| 2164 | } |
| 2165 | const std::vector<int>& modified_vert = morph->modified_verts[lod_level]; |
| 2166 | |
| 2167 | for (int j : modified_vert) { |
| 2168 | vert_id = j; |
| 2169 | vert_id_index = vert_id * 3; |
| 2170 | |
| 2171 | if (online->IsClient()) { |
| 2172 | MorphTargetStateStorage state; |
| 2173 | if (GetOnlineIncomingMorphTargetState(state, morph->name.c_str())) { |
| 2174 | morph->disp_weight = state.disp_weight; |
| 2175 | } |
| 2176 | } |
| 2177 | model->morph_transform_vec[vert_id][0] += morph_model->vertices[vert_id_index + 0] * morph->disp_weight; |
| 2178 | model->morph_transform_vec[vert_id][1] += morph_model->vertices[vert_id_index + 1] * morph->disp_weight; |
| 2179 | model->morph_transform_vec[vert_id][2] += morph_model->vertices[vert_id_index + 2] * morph->disp_weight; |
| 2180 | } |
| 2181 | } |
| 2182 | |
| 2183 | if (online->IsHosting()) { |
nothing calls this directly
no test coverage detected