History

Migrate core avatar rendering functionality to library

Brad Davis committed 9 years ago

Commit 2d0bbf71 parent a7eecdf48 files · +530 −467Browse files

Showing the changes to libraries/render-utils/src/SoftAttachmentModel.cpp (1 of 48 files). Show all

Unified · Split

libraries/render-utils/src/SoftAttachmentModel.cpp+79−0
@@ -0,0 +1,79 @@
1+//
2+// Created by Anthony J. Thibault on 12/17/15.
3+// Copyright 2013 High Fidelity, Inc.
4+//
5+// Distributed under the Apache License, Version 2.0.
6+// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
7+//
8+
9+#include "SoftAttachmentModel.h"
10+
11+SoftAttachmentModel::SoftAttachmentModel(RigPointer rig, QObject* parent, RigPointer rigOverride) :
12+ CauterizedModel(rig, parent),
13+ _rigOverride(rigOverride) {
14+ assert(_rig);
15+ assert(_rigOverride);
16+}
17+
18+SoftAttachmentModel::~SoftAttachmentModel() {
19+}
20+
21+// virtual
22+void SoftAttachmentModel::updateRig(float deltaTime, glm::mat4 parentTransform) {
23+ _needsUpdateClusterMatrices = true;
24+}
25+
26+int SoftAttachmentModel::getJointIndexOverride(int i) const {
27+ QString name = _rig->nameOfJoint(i);
28+ if (name.isEmpty()) {
29+ return -1;
30+ }
31+ return _rigOverride->indexOfJoint(name);
32+}
33+
34+// virtual
35+// use the _rigOverride matrices instead of the Model::_rig
36+void SoftAttachmentModel::updateClusterMatrices() {
37+ if (!_needsUpdateClusterMatrices) {
38+ return;
39+ }
40+ _needsUpdateClusterMatrices = false;
41+
42+ const FBXGeometry& geometry = getFBXGeometry();
43+
44+ for (int i = 0; i < _meshStates.size(); i++) {
45+ MeshState& state = _meshStates[i];
46+ const FBXMesh& mesh = geometry.meshes.at(i);
47+
48+ for (int j = 0; j < mesh.clusters.size(); j++) {
49+ const FBXCluster& cluster = mesh.clusters.at(j);
50+
51+ // TODO: cache these look-ups as an optimization
52+ int jointIndexOverride = getJointIndexOverride(cluster.jointIndex);
53+ glm::mat4 jointMatrix;
54+ if (jointIndexOverride >= 0 && jointIndexOverride < _rigOverride->getJointStateCount()) {
55+ jointMatrix = _rigOverride->getJointTransform(jointIndexOverride);
56+ } else {
57+ jointMatrix = _rig->getJointTransform(cluster.jointIndex);
58+ }
59+ glm_mat4u_mul(jointMatrix, cluster.inverseBindMatrix, state.clusterMatrices[j]);
60+ }
61+
62+ // Once computed the cluster matrices, update the buffer(s)
63+ if (mesh.clusters.size() > 1) {
64+ if (!state.clusterBuffer) {
65+ state.clusterBuffer = std::make_shared<gpu::Buffer>(state.clusterMatrices.size() * sizeof(glm::mat4),
66+ (const gpu::Byte*) state.clusterMatrices.constData());
67+ } else {
68+ state.clusterBuffer->setSubData(0, state.clusterMatrices.size() * sizeof(glm::mat4),
69+ (const gpu::Byte*) state.clusterMatrices.constData());
70+ }
71+ }
72+ }
73+
74+ // post the blender if we're not currently waiting for one to finish
75+ if (geometry.hasBlendedMeshes() && _blendshapeCoefficients != _blendedBlendshapeCoefficients) {
76+ _blendedBlendshapeCoefficients = _blendshapeCoefficients;
77+ DependencyManager::get<ModelBlender>()->noteRequiresBlend(getThisPointer());
78+ }
79+}

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t