76 for (
auto& joint:
skinning->getJoints()) {
90 for (
auto j = 0; j < nodeVertices.size(); j++) {
100 for (
auto j = 0; j < nodeNormals.size(); j++) {
111 for (
auto j = 0; j < nodeTextureCoordinates.size(); j++) {
119 if (nodeTangents.size() > 0) {
125 for (
auto j = 0; j < nodeTangents.size(); j++) {
131 if (nodeBitangents.size() > 0) {
137 for (
auto j = 0; j < nodeBitangents.size(); j++) {
147 if (nodeTangents.size() > 0) {
150 if (nodeBitangents.size() > 0) {
156 auto indicesCount = 0;
158 indicesCount += 3 * facesEntity.getFaces().size();
165 for (
auto& face : facesEntity.getFaces())
166 for (
auto& vertexIndex : face.getVertexIndices()) {
167 indices[j++] = nodeVertices.size() * i + vertexIndex;
192 auto& joints =
skinning->getJoints();
193 auto& weights =
skinning->getWeights();
194 auto& jointsWeights =
skinning->getVerticesJointsWeights();
195 for (
auto vertexIndex = 0; vertexIndex < nodeVertices.size(); vertexIndex++) {
196 auto vertexJointWeights = jointsWeights[vertexIndex].size();
201 auto jointWeightIdx = 0;
202 for (
auto& jointWeight : jointsWeights[vertexIndex]) {
203 auto& joint = joints[jointWeight.getJointIndex()];
210 auto jointWeightIdx = 0;
211 for (
auto& jointWeight : jointsWeights[vertexIndex]) {
212 auto& joint = joints[jointWeight.getJointIndex()];
239 auto& jointsWeights =
skinning->getVerticesJointsWeights();
249 float weightNormalized;
256 for (
auto vertexIndex = 0; vertexIndex < nodeVertices.size(); vertexIndex++) {
258 vertex = &nodeVertices[vertexIndex];
259 transformedVertex = &
transformedVertices[nodeVertices.size() * j + vertexIndex].set(0.0f, 0.0f, 0.0f);
260 normal = &nodeNormals[vertexIndex];
261 transformedNormal = &
transformedNormals[nodeVertices.size() * j + vertexIndex].set(0.0f, 0.0f, 0.0f);
262 tangent =
tangents !=
nullptr?&nodeTangent[vertexIndex]:
nullptr;
263 transformedTangent =
tangents !=
nullptr?&
transformedTangents[nodeVertices.size() * j + vertexIndex].set(0.0f, 0.0f, 0.0f):
nullptr;
264 bitangent =
bitangents !=
nullptr?&nodeBitangent[vertexIndex]:
nullptr;
268 for (
auto vertexJointWeightIdx = 0; vertexJointWeightIdx < jointsWeights[vertexIndex].size(); vertexJointWeightIdx++) {
273 transformedVertex->
add(transformationsMatrix.
multiply(*vertex).
scale(weight));
277 if (tangent !=
nullptr && transformedTangent !=
nullptr) {
281 if (bitangent !=
nullptr && transformedBitangent !=
nullptr) {
285 totalWeights += weight;
288 if (Math::abs(totalWeights - 1.0f) > Math::EPSILON) {
289 weightNormalized = 1.0f / totalWeights;
291 transformedVertex->
scale(weightNormalized);
293 transformedNormal->
scale(weightNormalized);
295 if (transformedTangent !=
nullptr) {
296 transformedTangent->
scale(weightNormalized);
299 if (transformedBitangent !=
nullptr) {
300 transformedBitangent->
scale(weightNormalized);
318 for (
auto vertexIndex = 0; vertexIndex < nodeVertices.size(); vertexIndex++) {
322 for (
auto normalIndex = 0; normalIndex < nodeNormals.size(); normalIndex++) {
351 "Object3DNodeMesh::setupVertexIndicesBuffer(): " +
354 "more than 2^16-1 indices: " +
362 sbIndices.
put(index);
371 ibIndices.
put(index);
386 fbTextureCoordinates.
put(textureCoordinate.getArray());
389 renderer->
uploadBufferObject(contextIdx, vboId, fbTextureCoordinates.getPosition() *
sizeof(
float), &fbTextureCoordinates);
397 fbVertices.
put(vertex.getArray());
400 renderer->
uploadBufferObject(contextIdx, vboId, fbVertices.getPosition() *
sizeof(
float), &fbVertices);
408 fbNormals.
put(normal.getArray());
411 renderer->
uploadBufferObject(contextIdx, vboId, fbNormals.getPosition() *
sizeof(
float), &fbNormals);
421 fbTangents.
put(tangent.getArray());
424 renderer->
uploadBufferObject(contextIdx, vboId, fbTangents.getPosition() *
sizeof(
float), &fbTangents);
434 fbBitangents.
put(bitangent.getArray());
437 renderer->
uploadBufferObject(contextIdx, vboId, fbBitangents.getPosition() *
sizeof(
float), &fbBitangents);
443 if (origins.size() == 0)
return;
447 for (
auto& origin: origins) {
448 fbOrigins.
put(origin.getArray());
451 renderer->
uploadBufferObject(contextIdx, vboId, fbOrigins.getPosition() *
sizeof(
float), &fbOrigins);
456 const vector<int32_t>*
indices {
nullptr };
463 "Object3DNodeMesh::setupLodBuffer(): " +
466 "no valid lod level: " + to_string(lodLevel)
470 if (
indices->empty() ==
true) {
472 "Object3DNodeMesh::setupLodBuffer(): " +
482 "Object3DNodeMesh::setupLodBuffer(): " +
485 "more than 2^16-1 indices: " +
493 sbIndices.
put(index);
501 ibIndices.
put(index);
static SkinningShader * getSkinningShader()
AnimationProcessingTarget
Represents a model face, consisting of vertex, normal, tangent and bitangent vectors,...
Node faces entity A node can have multiple entities containing faces and a applied material.
int32_t getFaceCount() const
const vector< Vector3 > & getTangents() const
const vector< Vector3 > & getOrigins() const
const vector< Vector3 > & getBitangents() const
const vector< TextureCoordinate > & getTextureCoordinates() const
const string & getId()
Returns id.
const vector< Vector3 > & getNormals() const
const vector< FacesEntity > & getFacesEntities() const
const vector< Vector3 > & getVertices() const
Skinning definition for nodes.
Class representing texture UV coordinates data.
virtual void uploadIndicesBufferObject(int contextIdx, int32_t bufferObjectId, int32_t size, ShortBuffer *data)=0
Uploads buffer data to buffer object.
virtual bool isUsingShortIndices()=0
virtual void uploadBufferObject(int contextIdx, int32_t bufferObjectId, int32_t size, FloatBuffer *data)=0
Uploads buffer data to buffer object.
const Matrix4x4 & getTransformationsMatrix() const
vector< bool > instanceEnabled
void setCurrentInstance(int currentInstance)
Set current instance.
Object 3D node mesh specifically for rendering.
void setupOriginsBuffer(Renderer *renderer, int contextIdx, int32_t vboId)
Set up render node object origins data buffer.
void setupNormalsBuffer(Renderer *renderer, int contextIdx, int32_t vboId)
Set up normals buffer.
vector< int32_t > indices
void computeTransformations(int contextIdx, Object3DBase *object3DBase)
Computes mesh transformations.
void setupVertexIndicesBuffer(Renderer *renderer, int contextIdx, int32_t vboId)
Set up vertex indices buffer.
vector< vector< float > > cSkinningJointWeight
const vector< Vector3 > * vertices
vector< Vector3 > transformedTangents
Engine::AnimationProcessingTarget animationProcessingTarget
vector< map< string, Matrix4x4 * > * > skinningMatrices
vector< Vector3 > transformedVertices
void setupLodBuffer(Renderer *renderer, int contextIdx, int32_t vboId, int lodLevel)
Set up render node object lod data buffer.
void setupTextureCoordinatesBuffer(Renderer *renderer, int contextIdx, int32_t vboId)
Set up texture coordinates buffer.
const vector< Vector3 > * tangents
const vector< Vector3 > * normals
void recreateBuffers()
Recreates node float buffers.
void setupTangentsBuffer(Renderer *renderer, int contextIdx, int32_t vboId)
Set up tangents buffer.
const vector< TextureCoordinate > * textureCoordinates
bool getRecreatedBuffers()
void setupVerticesBuffer(Renderer *renderer, int contextIdx, int32_t vboId)
Set up vertices buffer.
Object3DNodeRenderer * object3DNodeRenderer
vector< vector< Matrix4x4 * > > jointsSkinningMatrices
void setupBitangentsBuffer(Renderer *renderer, int contextIdx, int32_t vboId)
Set up bitangents buffer.
int32_t cSkinningMaxVertexWeights
vector< TextureCoordinate > transformedTextureCoordinates
const vector< Vector3 > * bitangents
vector< Vector3 > transformedBitangents
Matrix4x4 * cNodeTransformationsMatrix
vector< vector< vector< Matrix4x4 * > > > cSkinningJointTransformationsMatrices
vector< Vector3 > transformedNormals
Object 3D node VBO renderer.
Buffers used to transfer data between main memory to graphics board memory.
static ByteBuffer * getByteBuffer(int contextIdx, int32_t bytes)
Get byte buffer for given context.
Interface to compute shader skinning shader program.
void computeSkinning(int contextIdx, Object3DBase *object3DBase, Object3DNodeMesh *object3DNodeMesh)
Compute skinning.
Matrix4x4 & set(float r0c0, float r1c0, float r2c0, float r3c0, float r0c1, float r1c1, float r2c1, float r3c1, float r0c2, float r1c2, float r2c2, float r3c2, float r0c3, float r1c3, float r2c3, float r3c3)
Set up matrix by values.
Vector3 multiplyNoTranslation(const Vector3 &v) const
Multiplies a vector3 with this matrix ignoring translation.
Vector3 multiply(const Vector3 &v) const
Multiplies a vector3 with this matrix into destination vector.
Vector3 & normalize()
Normalize the vector.
Vector3 & add(const Vector3 &v)
Adds a vector.
Vector3 & scale(float scale)
Scale this vector.
ShortBuffer asShortBuffer()
FloatBuffer asFloatBuffer()
FloatBuffer * put(float value)
Put a float value into float buffer.
IntBuffer * put(int32_t value)
Puts a value into buffer at its current position.
ShortBuffer * put(int16_t value)
Put a value into current position.