PeriDyno 1.0.0
Loading...
Searching...
No Matches
JointDeform.cu
Go to the documentation of this file.
1/**
2 * Copyright 2022 Yuzhong Guo
3 *
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
7 *
8 * https://www.apache.org/licenses/LICENSE-2.0
9 *
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.
15 */
16
17#include "JointDeform.h"
18#include <GLPhotorealisticRender.h>
19
20#include <GLPhotorealisticInstanceRender.h>
21
22#include "GltfFunc.h"
23
24namespace dyno
25{
26 /**
27 * @brief A class to facilitate showing the shape information
28 */
29
30 template<typename TDataType>
31 JointDeform<TDataType>::JointDeform()
32 {
33 this->stateTextureMesh()->setDataPtr(std::make_shared<TextureMesh>());
34
35 auto render = std::make_shared<GLPhotorealisticRender>();
36 this->stateTextureMesh()->connect(render->inTextureMesh());
37 this->graphicsPipeline()->pushModule(render);
38
39 auto instanceRender = std::make_shared<GLPhotorealisticInstanceRender>();
40 this->stateTextureMesh()->connect(instanceRender->inTextureMesh());
41 this->inInstanceTransform()->connect(instanceRender->inTransform());
42 this->graphicsPipeline()->pushModule(instanceRender);
43
44
45 }
46
47 template<typename TDataType>
48 JointDeform<TDataType>::~JointDeform()
49 {
50
51 }
52
53 template<typename TDataType>
54 void JointDeform<TDataType>::resetStates()
55 {
56 {
57 auto& joint = this->inJoint()->getData();
58 auto& skin = this->inSkin()->getData();
59
60 if (joint.isEmpty() || skin.isEmpty())
61 {
62 return;
63 }
64
65 auto textureMesh = this->stateTextureMesh()->getDataPtr();
66
67
68 textureMesh->vertices() = skin.mesh->vertices();
69 textureMesh->normals() = skin.mesh->normals();
70 textureMesh->texCoords() = skin.mesh->texCoords();
71 textureMesh->shapeIds() = skin.mesh->shapeIds();
72
73 textureMesh->shapes() = skin.mesh->shapes();
74 textureMesh->materials() = skin.mesh->materials();
75
76 }
77 }
78
79 template<typename TDataType>
80 void JointDeform<TDataType>::updateStates()
81 {
82 {
83 int frameNumber = this->stateFrameNumber()->getValue();
84
85
86 auto& joint = this->inJoint()->getData();
87 auto& skin = this->inSkin()->getData();
88
89 if (joint.isEmpty() || skin.isEmpty())
90 {
91 return;
92 }
93
94
95 updateAnimation(frameNumber);
96 }
97 }
98
99 template<typename TDataType>
100 void JointDeform<TDataType>::updateAnimation(int frameNumber)
101 {
102 {
103 //update Points
104 auto& skinInfo = this->inSkin()->getData();
105 auto& jointInfo = this->inJoint()->getData();
106
107 auto textureMesh = this->stateTextureMesh()->getDataPtr();
108
109
110 for (size_t i = 0; i < skinInfo.size(); i++)//
111 {
112 auto& bindJoint0 = skinInfo.V_jointID_0[i];
113 auto& bindJoint1 = skinInfo.V_jointID_1[i];
114
115 auto& bindWeight0 = skinInfo.V_jointWeight_0[i];
116 auto& bindWeight1 = skinInfo.V_jointWeight_1[i];
117
118 for (size_t j = 0; j < skinInfo.skin_VerticeRange[i].size(); j++)
119 {
120 //
121 Vec2u& range = skinInfo.skin_VerticeRange[i][j];
122
123 skinAnimation(skinInfo.initialPosition,
124 textureMesh->vertices(),
125 jointInfo.mJointInverseBindMatrix,
126 jointInfo.mJointWorldMatrix,
127
128 bindJoint0,
129 bindJoint1,
130 bindWeight0,
131 bindWeight1,
132 Mat4f::identityMatrix(),
133 false,
134 range
135 );
136
137 //update Normals
138
139 skinAnimation(
140 skinInfo.initialNormal,
141 textureMesh->normals(),
142 jointInfo.mJointInverseBindMatrix,
143 jointInfo.mJointWorldMatrix,
144
145 bindJoint0,
146 bindJoint1,
147 bindWeight0,
148 bindWeight1,
149 Mat4f::identityMatrix(),
150 true,
151 range
152 );
153
154 }
155 }
156
157
158 }
159 }
160
161 DEFINE_CLASS(JointDeform);
162}