in the middle of something

This commit is contained in:
Sam Gateau 2019-10-10 17:09:54 -07:00
parent c0e4509095
commit a995f2c09f
10 changed files with 53 additions and 107 deletions

View file

@ -1463,9 +1463,6 @@ HFMModel* FBXSerializer::extractHFMModel(const hifi::VariantHash& mapping, const
// see if any materials have texture children
bool materialsHaveTextures = checkMaterialsHaveTextures(_hfmMaterials, _textureFilenames, _connectionChildMap);
// Note that the transforms in the TransformNodes are initially in world-space, and need to be converted to parent-space
std::vector<hfm::TransformNode> transformNodes;
for (QMap<QString, ExtractedMesh>::iterator it = meshes.begin(); it != meshes.end(); it++) {
const QString& meshID = it.key();
const ExtractedMesh& extracted = it.value();

View file

@ -293,13 +293,6 @@ public:
bool shouldInitCollisions() const { return _collisionsConfig.size() > 0; }
};
// DEPRECATED in favor of using hfm::Joint
class TransformNode {
public:
uint32_t parent { 0 };
Transform transform;
};
// Formerly contained in hfm::Mesh
class Deformer {
public:
@ -343,7 +336,6 @@ public:
std::vector<Material> materials;
std::vector<Deformer> deformers;
std::vector<TransformNode> transforms;
std::vector<DynamicTransform> dynamicTransforms;
std::vector<Joint> joints;

View file

@ -295,7 +295,6 @@ void ModelResource::onGeometryMappingLoaded(bool success) {
if (success && _modelResource) {
_hfmModel = _modelResource->_hfmModel;
_materialMapping = _modelResource->_materialMapping;
// _meshParts = _modelResource->_meshParts;
_meshes = _modelResource->_meshes;
_materials = _modelResource->_materials;

View file

@ -18,8 +18,8 @@
using namespace render;
CauterizedMeshPartPayload::CauterizedMeshPartPayload(ModelPointer model, int meshIndex, int partIndex, int shapeIndex, const Transform& transform, const Transform& offsetTransform)
: ModelMeshPartPayload(model, meshIndex, partIndex, shapeIndex, transform, offsetTransform) {}
CauterizedMeshPartPayload::CauterizedMeshPartPayload(ModelPointer model, int meshIndex, int partIndex, int shapeIndex, const Transform& transform)
: ModelMeshPartPayload(model, meshIndex, partIndex, shapeIndex, transform) {}
void CauterizedMeshPartPayload::updateClusterBuffer(const std::vector<glm::mat4>& clusterMatrices,
const std::vector<glm::mat4>& cauterizedClusterMatrices) {

View file

@ -13,7 +13,7 @@
class CauterizedMeshPartPayload : public ModelMeshPartPayload {
public:
CauterizedMeshPartPayload(ModelPointer model, int meshIndex, int partIndex, int shapeIndex, const Transform& transform, const Transform& offsetTransform);
CauterizedMeshPartPayload(ModelPointer model, int meshIndex, int partIndex, int shapeIndex, const Transform& transform);
// matrix palette skinning
void updateClusterBuffer(const std::vector<glm::mat4>& clusterMatrices,

View file

@ -33,7 +33,20 @@ bool CauterizedModel::updateGeometry() {
if (_isCauterized && needsFullUpdate) {
assert(_cauterizeMeshStates.empty());
const HFMModel& hfmModel = getHFMModel();
foreach (const HFMMesh& mesh, hfmModel.meshes) {
const auto& hfmDynamicTransforms = hfmModel.dynamicTransforms;
for (int i = 0; i < hfmDynamicTransforms.size(); i++) {
const auto& dynT = hfmDynamicTransforms[i];
MeshState state;
if (_useDualQuaternionSkinning) {
state.clusterDualQuaternions.resize(dynT.clusters.size());
} else {
state.clusterMatrices.resize(dynT.clusters.size());
}
_cauterizeMeshStates.append(state);
_meshStates.push_back(state);
}
/* foreach (const HFMMesh& mesh, hfmModel.meshes) {
Model::MeshState state;
if (_useDualQuaternionSkinning) {
state.clusterDualQuaternions.resize(mesh.clusters.size());
@ -42,7 +55,7 @@ bool CauterizedModel::updateGeometry() {
state.clusterMatrices.resize(mesh.clusters.size());
_cauterizeMeshStates.append(state);
}
}
}*/
}
return needsFullUpdate;
}
@ -73,6 +86,8 @@ void CauterizedModel::createRenderItemSet() {
offset.setScale(_scale);
offset.postTranslate(_offset);
Transform::mult(transform, transform, offset);
// Run through all of the meshes, and place them into their segregated, but unsorted buckets
int shapeID = 0;
uint32_t numMeshes = (uint32_t)meshes.size();
@ -85,7 +100,7 @@ void CauterizedModel::createRenderItemSet() {
// Create the render payloads
int numParts = (int)mesh->getNumParts();
for (int partIndex = 0; partIndex < numParts; partIndex++) {
auto ptr = std::make_shared<CauterizedMeshPartPayload>(shared_from_this(), i, partIndex, shapeID, transform, offset);
auto ptr = std::make_shared<CauterizedMeshPartPayload>(shared_from_this(), i, partIndex, shapeID, transform);
_modelMeshRenderItems << std::static_pointer_cast<ModelMeshPartPayload>(ptr);
auto material = getNetworkModel()->getShapeMaterial(shapeID);
_modelMeshMaterialNames.push_back(material ? material->getName() : "");
@ -222,8 +237,11 @@ void CauterizedModel::updateRenderItems() {
auto itemID = self->_modelMeshRenderItemIDs[i];
auto meshIndex = self->_modelMeshRenderItemShapes[i].meshIndex;
auto deformerIndex = self->_modelMeshRenderItemShapes[i].meshIndex;
const auto& shapeState = self->getShapeState(i);
const auto& meshState = self->getMeshState(meshIndex);
const auto& cauterizedMeshState = self->getCauterizeMeshState(meshIndex);
@ -244,38 +262,10 @@ void CauterizedModel::updateRenderItems() {
}
Transform renderTransform = modelTransform;
/*if (useDualQuaternionSkinning) {
if (meshState.clusterDualQuaternions.size() == 1 || meshState.clusterDualQuaternions.size() == 2) {
const auto& dq = meshState.clusterDualQuaternions[0];
Transform transform(dq.getRotation(),
dq.getScale(),
dq.getTranslation());
renderTransform = modelTransform.worldTransform(transform);
}
} else {
if (meshState.clusterMatrices.size() == 1 || meshState.clusterMatrices.size() == 2) {
renderTransform = modelTransform.worldTransform(Transform(meshState.clusterMatrices[0]));
}
}*/
if (meshState.clusterMatrices.size() <= 1) {
if (meshState.clusterMatrices.size() <= 2) {
renderTransform = modelTransform.worldTransform(shapeState._rootFromJointTransform);
}
data.updateTransformForSkinnedMesh(renderTransform, modelTransform);
renderTransform = modelTransform;
if (useDualQuaternionSkinning) {
if (cauterizedMeshState.clusterDualQuaternions.size() == 1 || cauterizedMeshState.clusterDualQuaternions.size() == 2) {
const auto& dq = cauterizedMeshState.clusterDualQuaternions[0];
Transform transform(dq.getRotation(),
dq.getScale(),
dq.getTranslation());
renderTransform = modelTransform.worldTransform(Transform(transform));
}
} else {
if (cauterizedMeshState.clusterMatrices.size() == 1 || cauterizedMeshState.clusterMatrices.size() == 2) {
renderTransform = modelTransform.worldTransform(Transform(cauterizedMeshState.clusterMatrices[0]));
}
}
data.updateTransform(renderTransform);
data.updateTransformForCauterizedMesh(renderTransform);
data.setEnableCauterization(enableCauterization);

View file

@ -64,11 +64,10 @@ void MeshPartPayload::updateMeshPart(const std::shared_ptr<const graphics::Mesh>
}
}
void MeshPartPayload::updateTransform(const Transform& transform, const Transform& offsetTransform) {
_transform = transform;
Transform::mult(_drawTransform, _transform, offsetTransform);
void MeshPartPayload::updateTransform(const Transform& transform) {
_worldFromLocalTransform = transform;
_worldBound = _localBound;
_worldBound.transform(_drawTransform);
_worldBound.transform(_worldFromLocalTransform);
}
void MeshPartPayload::addMaterial(graphics::MaterialLayer material) {
@ -134,7 +133,7 @@ void MeshPartPayload::bindMesh(gpu::Batch& batch) {
}
void MeshPartPayload::bindTransform(gpu::Batch& batch, RenderArgs::RenderMode renderMode) const {
batch.setModelTransform(_drawTransform);
batch.setModelTransform(_worldFromLocalTransform);
}
@ -196,7 +195,7 @@ template <> void payloadRender(const ModelMeshPartPayload::Pointer& payload, Ren
}
ModelMeshPartPayload::ModelMeshPartPayload(ModelPointer model, int meshIndex, int partIndex, int shapeIndex, const Transform& transform, const Transform& offsetTransform) :
ModelMeshPartPayload::ModelMeshPartPayload(ModelPointer model, int meshIndex, int partIndex, int shapeIndex, const Transform& transform) :
_meshIndex(meshIndex),
_shapeID(shapeIndex) {
@ -220,28 +219,10 @@ ModelMeshPartPayload::ModelMeshPartPayload(ModelPointer model, int meshIndex, in
computeAdjustedLocalBound(state.clusterMatrices);
}
updateTransform(transform, offsetTransform);
Transform renderTransform = transform;
/* if (useDualQuaternionSkinning) {
if (state.clusterDualQuaternions.size() == 1) {
const auto& dq = state.clusterDualQuaternions[0];
Transform transform(dq.getRotation(),
dq.getScale(),
dq.getTranslation());
renderTransform = transform.worldTransform(Transform(transform));
}
} else {
if (state.clusterMatrices.size() == 1) {
renderTransform = transform.worldTransform(Transform(state.clusterMatrices[0]));
}
}
*/
Transform renderTransform = transform;
const Model::ShapeState& shapeState = model->getShapeState(shapeIndex);
renderTransform = transform.worldTransform(shapeState._rootFromJointTransform);
updateTransformForSkinnedMesh(renderTransform, transform);
updateTransform(renderTransform);
initCache(model);
@ -323,13 +304,6 @@ void ModelMeshPartPayload::updateClusterBuffer(const std::vector<Model::Transfor
}
}
void ModelMeshPartPayload::updateTransformForSkinnedMesh(const Transform& renderTransform, const Transform& boundTransform) {
_transform = renderTransform;
_worldBound = _adjustedLocalBound;
// _worldBound.transform(boundTransform);
_worldBound.transform(renderTransform);
}
// Note that this method is called for models but not for shapes
void ModelMeshPartPayload::updateKey(const render::ItemKey& key) {
ItemKey::Builder builder(key);
@ -420,7 +394,7 @@ void ModelMeshPartPayload::bindTransform(gpu::Batch& batch, RenderArgs::RenderMo
if (_clusterBuffer) {
batch.setUniformBuffer(graphics::slot::buffer::Skinning, _clusterBuffer);
}
batch.setModelTransform(_transform);
batch.setModelTransform(_worldFromLocalTransform);
}
void ModelMeshPartPayload::render(RenderArgs* args) {

View file

@ -38,7 +38,7 @@ public:
virtual void updateMeshPart(const std::shared_ptr<const graphics::Mesh>& drawMesh, int partIndex);
virtual void notifyLocationChanged() {}
void updateTransform(const Transform& transform, const Transform& offsetTransform);
void updateTransform(const Transform& transform);
// Render Item interface
virtual render::ItemKey getKey() const;
@ -52,8 +52,7 @@ public:
virtual void bindTransform(gpu::Batch& batch, RenderArgs::RenderMode renderMode) const;
// Payload resource cached values
Transform _drawTransform;
Transform _transform;
Transform _worldFromLocalTransform;
int _partIndex = 0;
bool _hasColorAttrib { false };
@ -86,7 +85,7 @@ namespace render {
class ModelMeshPartPayload : public MeshPartPayload {
public:
ModelMeshPartPayload(ModelPointer model, int meshIndex, int partIndex, int shapeIndex, const Transform& transform, const Transform& offsetTransform);
ModelMeshPartPayload(ModelPointer model, int meshIndex, int partIndex, int shapeIndex, const Transform& transform);
typedef render::Payload<ModelMeshPartPayload> Payload;
typedef Payload::DataPointer Pointer;
@ -100,7 +99,6 @@ public:
// dual quaternion skinning
void updateClusterBuffer(const std::vector<Model::TransformDualQuaternion>& clusterDualQuaternions);
void updateTransformForSkinnedMesh(const Transform& renderTransform, const Transform& boundTransform);
// Render Item interface
render::ShapeKey getShapeKey() const override; // shape interface

View file

@ -249,24 +249,10 @@ void Model::updateRenderItems() {
}
Transform renderTransform = modelTransform;
/*if (useDualQuaternionSkinning) {
if (meshState.clusterDualQuaternions.size() == 1 || meshState.clusterDualQuaternions.size() == 2) {
const auto& dq = meshState.clusterDualQuaternions[0];
Transform transform(dq.getRotation(),
dq.getScale(),
dq.getTranslation());
renderTransform = modelTransform.worldTransform(Transform(transform));
}
} else {
if (meshState.clusterMatrices.size() == 1 || meshState.clusterMatrices.size() == 2) {
renderTransform = modelTransform.worldTransform(Transform(meshState.clusterMatrices[0]));
}
}*/
if (meshState.clusterMatrices.size() <= 1) {
renderTransform = modelTransform.worldTransform(shapeState._rootFromJointTransform);
}
data.updateTransformForSkinnedMesh(renderTransform, modelTransform);
data.updateTransform(renderTransform);
data.setCauterized(cauterized);
data.updateKey(renderItemKeyGlobalFlags);
@ -305,7 +291,7 @@ void Model::updateShapeStatesFromRig() {
_shapeStates.resize(shapes.size());
for (int s = 0; s < shapes.size(); ++s) {
uint32_t jointId = shapes[s].transform;
if (jointId < _rig.getJointStateCount()) {
if (jointId < (uint32_t) _rig.getJointStateCount()) {
_shapeStates[s]._rootFromJointTransform = _rig.getJointTransform(shapes[s].transform);
}
}
@ -329,14 +315,24 @@ bool Model::updateGeometry() {
updateShapeStatesFromRig();
const HFMModel& hfmModel = getHFMModel();
int i = 0;
foreach (const HFMMesh& mesh, hfmModel.meshes) {
const auto& hfmDynamicTransforms = hfmModel.dynamicTransforms;
/* int i = 0;
for (const auto& mesh: hfmModel.meshes) {
MeshState state;
state.clusterDualQuaternions.resize(mesh.clusters.size());
state.clusterMatrices.resize(mesh.clusters.size());
_meshStates.push_back(state);
i++;
}
*/
for (int i = 0; i < hfmDynamicTransforms.size(); i++) {
const auto& dynT = hfmDynamicTransforms[i];
MeshState state;
state.clusterDualQuaternions.resize(dynT.clusters.size());
state.clusterMatrices.resize(dynT.clusters.size());
_meshStates.push_back(state);
}
needFullUpdate = true;
emit rigReady();
}
@ -1510,7 +1506,7 @@ void Model::createRenderItemSet() {
// Create the render payloads
int numParts = (int)mesh->getNumParts();
for (int partIndex = 0; partIndex < numParts; partIndex++) {
_modelMeshRenderItems << std::make_shared<ModelMeshPartPayload>(shared_from_this(), i, partIndex, shapeID, transform, offset);
_modelMeshRenderItems << std::make_shared<ModelMeshPartPayload>(shared_from_this(), i, partIndex, shapeID, transform);
auto material = getNetworkModel()->getShapeMaterial(shapeID);
_modelMeshMaterialNames.push_back(material ? material->getName() : "");
_modelMeshRenderItemShapes.emplace_back(ShapeInfo{ (int)i });

View file

@ -473,7 +473,7 @@ protected:
QVector<std::shared_ptr<ModelMeshPartPayload>> _modelMeshRenderItems;
QMap<render::ItemID, render::PayloadPointer> _modelMeshRenderItemsMap;
render::ItemIDs _modelMeshRenderItemIDs;
using ShapeInfo = struct { int meshIndex; };
using ShapeInfo = struct { int meshIndex; int deformerIndex; };
std::vector<ShapeInfo> _modelMeshRenderItemShapes;
std::vector<std::string> _modelMeshMaterialNames;