2 * Copyright 2022 Yuzhong Guo
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * https://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17#include "JointDeform.h"
18#include <GLPhotorealisticRender.h>
20#include <GLPhotorealisticInstanceRender.h>
27 * @brief A class to facilitate showing the shape information
30 template<typename TDataType>
31 JointDeform<TDataType>::JointDeform()
33 this->stateTextureMesh()->setDataPtr(std::make_shared<TextureMesh>());
35 auto render = std::make_shared<GLPhotorealisticRender>();
36 this->stateTextureMesh()->connect(render->inTextureMesh());
37 this->graphicsPipeline()->pushModule(render);
39 auto instanceRender = std::make_shared<GLPhotorealisticInstanceRender>();
40 this->stateTextureMesh()->connect(instanceRender->inTextureMesh());
41 this->inInstanceTransform()->connect(instanceRender->inTransform());
42 this->graphicsPipeline()->pushModule(instanceRender);
47 template<typename TDataType>
48 JointDeform<TDataType>::~JointDeform()
53 template<typename TDataType>
54 void JointDeform<TDataType>::resetStates()
57 auto& joint = this->inJoint()->getData();
58 auto& skin = this->inSkin()->getData();
60 if (joint.isEmpty() || skin.isEmpty())
65 auto textureMesh = this->stateTextureMesh()->getDataPtr();
68 textureMesh->vertices() = skin.mesh->vertices();
69 textureMesh->normals() = skin.mesh->normals();
70 textureMesh->texCoords() = skin.mesh->texCoords();
71 textureMesh->shapeIds() = skin.mesh->shapeIds();
73 textureMesh->shapes() = skin.mesh->shapes();
74 textureMesh->materials() = skin.mesh->materials();
79 template<typename TDataType>
80 void JointDeform<TDataType>::updateStates()
83 int frameNumber = this->stateFrameNumber()->getValue();
86 auto& joint = this->inJoint()->getData();
87 auto& skin = this->inSkin()->getData();
89 if (joint.isEmpty() || skin.isEmpty())
95 updateAnimation(frameNumber);
99 template<typename TDataType>
100 void JointDeform<TDataType>::updateAnimation(int frameNumber)
104 auto& skinInfo = this->inSkin()->getData();
105 auto& jointInfo = this->inJoint()->getData();
107 auto textureMesh = this->stateTextureMesh()->getDataPtr();
110 for (size_t i = 0; i < skinInfo.size(); i++)//
112 auto& bindJoint0 = skinInfo.V_jointID_0[i];
113 auto& bindJoint1 = skinInfo.V_jointID_1[i];
115 auto& bindWeight0 = skinInfo.V_jointWeight_0[i];
116 auto& bindWeight1 = skinInfo.V_jointWeight_1[i];
118 for (size_t j = 0; j < skinInfo.skin_VerticeRange[i].size(); j++)
121 Vec2u& range = skinInfo.skin_VerticeRange[i][j];
123 skinAnimation(skinInfo.initialPosition,
124 textureMesh->vertices(),
125 jointInfo.mJointInverseBindMatrix,
126 jointInfo.mJointWorldMatrix,
132 Mat4f::identityMatrix(),
140 skinInfo.initialNormal,
141 textureMesh->normals(),
142 jointInfo.mJointInverseBindMatrix,
143 jointInfo.mJointWorldMatrix,
149 Mat4f::identityMatrix(),
161 DEFINE_CLASS(JointDeform);