Showing the changes to libraries/render-utils/src/Model.cpp (1 of 3 files). Show all
Unified · Split
| @@ -1140,147 +1140,6 @@ AABox Model::getPartBounds(int meshIndex, int partIndex) { · 1139 unmodified lines | ||
| 1140 | 1140 | return AABox(); |
| 1141 | 1141 | } |
| 1142 | 1142 | |
| 1143 | −void Model::renderPart(RenderArgs* args, int meshIndex, int partIndex, int shapeID, const MeshPartPayload* payload) { | |
| 1144 | −// PROFILE_RANGE(__FUNCTION__); | |
| 1145 | − PerformanceTimer perfTimer("Model::renderPart"); | |
| 1146 | − if (!_readyWhenAdded) { | |
| 1147 | − return; // bail asap | |
| 1148 | − } | |
| 1149 | − | |
| 1150 | − auto textureCache = DependencyManager::get<TextureCache>(); | |
| 1151 | − | |
| 1152 | − gpu::Batch& batch = *(args->_batch); | |
| 1153 | − auto mode = args->_renderMode; | |
| 1154 | − | |
| 1155 | − auto alphaThreshold = args->_alphaThreshold; //translucent ? TRANSPARENT_ALPHA_THRESHOLD : OPAQUE_ALPHA_THRESHOLD; // FIX ME | |
| 1156 | − | |
| 1157 | − const FBXGeometry& geometry = _geometry->getFBXGeometry(); | |
| 1158 | − const std::vector<std::unique_ptr<NetworkMesh>>& networkMeshes = _geometry->getMeshes(); | |
| 1159 | − | |
| 1160 | − auto networkMaterial = _geometry->getShapeMaterial(shapeID); | |
| 1161 | − if (!networkMaterial) { | |
| 1162 | − return; | |
| 1163 | − }; | |
| 1164 | − auto material = networkMaterial->_material; | |
| 1165 | − if (!material) { | |
| 1166 | − return; | |
| 1167 | − } | |
| 1168 | − | |
| 1169 | − // TODO: Not yet | |
| 1170 | − // auto drawMesh = _geometry->getShapeMesh(shapeID); | |
| 1171 | − // auto drawPart = _geometry->getShapePart(shapeID); | |
| 1172 | − | |
| 1173 | − // guard against partially loaded meshes | |
| 1174 | − if (meshIndex >= (int)networkMeshes.size() || meshIndex >= (int)geometry.meshes.size() || meshIndex >= (int)_meshStates.size() ) { | |
| 1175 | − return; | |
| 1176 | − } | |
| 1177 | − | |
| 1178 | − updateClusterMatrices(); | |
| 1179 | − | |
| 1180 | − const NetworkMesh& networkMesh = *(networkMeshes.at(meshIndex).get()); | |
| 1181 | − const FBXMesh& mesh = geometry.meshes.at(meshIndex); | |
| 1182 | − const MeshState& state = _meshStates.at(meshIndex); | |
| 1183 | − | |
| 1184 | − // if our index is ever out of range for either meshes or networkMeshes, then skip it, and set our _meshGroupsKnown | |
| 1185 | − // to false to rebuild out mesh groups. | |
| 1186 | − if (meshIndex < 0 || meshIndex >= (int)networkMeshes.size() || meshIndex > geometry.meshes.size()) { | |
| 1187 | − _meshGroupsKnown = false; // regenerate these lists next time around. | |
| 1188 | − _readyWhenAdded = false; // in case any of our users are using scenes | |
| 1189 | − invalidCalculatedMeshBoxes(); // if we have to reload, we need to assume our mesh boxes are all invalid | |
| 1190 | − return; // FIXME! | |
| 1191 | − } | |
| 1192 | − | |
| 1193 | − | |
| 1194 | − int vertexCount = mesh.vertices.size(); | |
| 1195 | − if (vertexCount == 0) { | |
| 1196 | − // sanity check | |
| 1197 | − return; // FIXME! | |
| 1198 | − } | |
| 1199 | − | |
| 1200 | − auto drawMaterialKey = material->getKey(); | |
| 1201 | − bool translucentMesh = drawMaterialKey.isTransparent() || drawMaterialKey.isTransparentMap(); | |
| 1202 | − | |
| 1203 | − bool hasTangents = drawMaterialKey.isNormalMap() && !mesh.tangents.isEmpty(); | |
| 1204 | − bool hasSpecular = drawMaterialKey.isGlossMap(); // !drawMaterial->specularTextureName.isEmpty(); //mesh.hasSpecularTexture(); | |
| 1205 | − bool hasLightmap = drawMaterialKey.isLightmapMap(); // !drawMaterial->emissiveTextureName.isEmpty(); //mesh.hasEmissiveTexture(); | |
| 1206 | − bool isSkinned = state.clusterMatrices.size() > 1; | |
| 1207 | − bool wireframe = isWireframe(); | |
| 1208 | − | |
| 1209 | − // render the part bounding box | |
| 1210 | − #ifdef DEBUG_BOUNDING_PARTS | |
| 1211 | − { | |
| 1212 | − AABox partBounds = getPartBounds(meshIndex, partIndex); | |
| 1213 | − bool inView = args->_viewFrustum->boxInFrustum(partBounds) != ViewFrustum::OUTSIDE; | |
| 1214 | − | |
| 1215 | − glm::vec4 cubeColor; | |
| 1216 | − if (isSkinned) { | |
| 1217 | − cubeColor = glm::vec4(0.0f, 1.0f, 1.0f, 1.0f); | |
| 1218 | − } else if (inView) { | |
| 1219 | − cubeColor = glm::vec4(1.0f, 0.0f, 1.0f, 1.0f); | |
| 1220 | − } else { | |
| 1221 | − cubeColor = glm::vec4(1.0f, 1.0f, 0.0f, 1.0f); | |
| 1222 | − } | |
| 1223 | − | |
| 1224 | − Transform transform; | |
| 1225 | − transform.setTranslation(partBounds.calcCenter()); | |
| 1226 | − transform.setScale(partBounds.getDimensions()); | |
| 1227 | − batch.setModelTransform(transform); | |
| 1228 | − DependencyManager::get<DeferredLightingEffect>()->renderWireCube(batch, 1.0f, cubeColor); | |
| 1229 | − } | |
| 1230 | − #endif //def DEBUG_BOUNDING_PARTS | |
| 1231 | − | |
| 1232 | − if (wireframe) { | |
| 1233 | − translucentMesh = hasTangents = hasSpecular = hasLightmap = isSkinned = false; | |
| 1234 | − } | |
| 1235 | − | |
| 1236 | − ModelRender::Locations* locations = nullptr; | |
| 1237 | − ModelRender::pickPrograms(batch, mode, translucentMesh, alphaThreshold, hasLightmap, hasTangents, hasSpecular, isSkinned, wireframe, | |
| 1238 | − args, locations); | |
| 1239 | − | |
| 1240 | − | |
| 1241 | − payload->bindTransform(batch, locations); | |
| 1242 | − | |
| 1243 | − payload->bindMesh(batch); | |
| 1244 | − | |
| 1245 | − // guard against partially loaded meshes | |
| 1246 | − if (partIndex >= mesh.parts.size()) { | |
| 1247 | − return; | |
| 1248 | − } | |
| 1249 | − | |
| 1250 | − | |
| 1251 | − #ifdef WANT_DEBUG | |
| 1252 | − if (material == nullptr) { | |
| 1253 | − qCDebug(renderutils) << "WARNING: material == nullptr!!!"; | |
| 1254 | − } | |
| 1255 | − #endif | |
| 1256 | − | |
| 1257 | − { | |
| 1258 | − // apply material properties | |
| 1259 | − payload->bindMaterial(batch, locations); | |
| 1260 | − | |
| 1261 | − | |
| 1262 | − // TODO: We should be able to do that just in the renderTransparentJob | |
| 1263 | − if (translucentMesh && locations->lightBufferUnit >= 0) { | |
| 1264 | − PerformanceTimer perfTimer("DLE->setupTransparent()"); | |
| 1265 | − | |
| 1266 | − DependencyManager::get<DeferredLightingEffect>()->setupTransparent(args, locations->lightBufferUnit); | |
| 1267 | − } | |
| 1268 | − if (args) { | |
| 1269 | − args->_details._materialSwitches++; | |
| 1270 | − } | |
| 1271 | − } | |
| 1272 | − | |
| 1273 | − { | |
| 1274 | − PerformanceTimer perfTimer("batch.drawIndexed()"); | |
| 1275 | − payload->drawCall(batch); | |
| 1276 | − } | |
| 1277 | − | |
| 1278 | − if (args) { | |
| 1279 | − const int INDICES_PER_TRIANGLE = 3; | |
| 1280 | − args->_details._trianglesRendered += payload->_drawPart._numIndices / INDICES_PER_TRIANGLE; | |
| 1281 | − } | |
| 1282 | −} | |
| 1283 | − | |
| 1284 | 1143 | void Model::segregateMeshGroups() { |
| 1285 | 1144 | const FBXGeometry& geometry = _geometry->getFBXGeometry(); |
| 1286 | 1145 | const std::vector<std::unique_ptr<NetworkMesh>>& networkMeshes = _geometry->getMeshes(); |