Result<Eldritch2::UniquePointer<AssetView>> MeshView::CreateView( Allocator& allocator, Device& device, DeviceMemoryPool& pool, const AssetLibrary& library, const Utf8Char* const name, Range<const char*> rawBytes ) { Eldritch2::UniquePointer<VkVertexInputAttributeDescription[]> attributes( CreateInputAttributeDescriptions( allocator ) ); Eldritch2::UniquePointer<VkVertexInputBindingDescription[]> bindings( CreateVertexInputBindings( allocator ) ); Eldritch2::UniquePointer<Submesh[]> submeshes( CreateSubmeshes( allocator ) ); UniquePointer<VkBuffer> buffer; VkMemoryRequirements memoryRequirements; vkGetBufferMemoryRequirements( device, buffer.Get(), &memoryRequirements ); Result<DeviceMemoryPool::Allocation> allocateMemoryResult( pool.TryAllocateRegion( memoryRequirements.size ) ); if( !allocateMemoryResult ) { library.GetLog()( MessageSeverity::Error, "Unable to allocate device memory for mesh '{}'! (Size: {} bytes)" ET_UTF8_NEWLINE_LITERAL, name, memoryRequirements.size ); return allocateMemoryResult.GetErrorCode(); } const VkResult bindMemoryResult( vkBindBufferMemory( device, buffer.Get(), pool.GetDeviceMemory(), allocateMemoryResult->GetOffsetIntoPoolInBytes() ) ); if( VkResult::VK_SUCCESS != bindMemoryResult ) { library.GetLog()( MessageSeverity::Error, "Unable to bind device memory for mesh '{}'!" ET_UTF8_NEWLINE_LITERAL, name ); } auto result( MakeUnique<MeshView>( allocator, name, eastl::move( buffer ), eastl::move( *allocateMemoryResult ), eastl::move( attributes ), eastl::move( bindings ), eastl::move( submeshes ) ) ); if( !result ) { return Error::OutOfMemory; } return eastl::move( result ); }
web::json::value BabylonMesh::toJson() { auto jobj = BabylonAbstractMesh::toJson(); jobj[L"id"] = web::json::value::string(_id); jobj[L"name"] = web::json::value::string(_id); if (_parentId.size() > 0) jobj[L"parentId"] = web::json::value::string(_parentId); if (_materialId.size() > 0) jobj[L"materialId"] = web::json::value::string(_materialId); jobj[L"isEnabled"] = web::json::value::boolean(_isEnabled); jobj[L"isVisible"] = web::json::value::boolean(_isVisible); jobj[L"pickable"] = web::json::value::boolean(_pickable); jobj[L"hasVertexAlpha"] = web::json::value::boolean(_hasVertexAlpha); jobj[L"checkCollision"] = web::json::value::boolean(_checkCollision); jobj[L"receiveShadows"] = web::json::value::boolean(_receiveShadows); jobj[L"infiniteDistance"] = web::json::value::boolean(_infiniteDistance); jobj[L"billboardMode"] = web::json::value::number(_billboardMode); jobj[L"visibility"] = web::json::value::number(_visibility); jobj[L"skeletonId"] = web::json::value::number(_skeletonId); auto submeshesArray = web::json::value::array(); for (auto ix = 0u; ix < submeshes().size(); ++ix){ submeshesArray[ix] = submeshes()[ix].toJson(); } jobj[L"subMeshes"] = submeshesArray; jobj[L"showBoundingBox"] = web::json::value::boolean(_showBoundingBox); jobj[L"showSubMeshesBoundingBox"] = web::json::value::boolean(_showSubMeshesBoundingBox); jobj[L"applyFog"] = web::json::value::boolean(_applyFog); jobj[L"alphaIndex"] = web::json::value::number(_alphaIndex); if (_positions.size() > 0) jobj[L"positions"] = convertToJson(_positions); if (_normals.size() > 0) jobj[L"normals"] = convertToJson(_normals); if (_uvs.size() > 0) jobj[L"uvs"] = convertToJson(_uvs); if (_uvs2.size() > 0) jobj[L"uvs2"] = convertToJson(_uvs2); if (_uvs3.size() > 0) jobj[L"uvs3"] = convertToJson(_uvs3); if (_uvs4.size() > 0) jobj[L"uvs4"] = convertToJson(_uvs4); if (_uvs5.size() > 0) jobj[L"uvs5"] = convertToJson(_uvs5); if (_uvs6.size() > 0) jobj[L"uvs6"] = convertToJson(_uvs6); if (_colors.size() > 0) jobj[L"colors"] = convertToJson(_colors); if (_indices.size() > 0) jobj[L"indices"] = convertToJson(_indices, false); if (_boneIndices.size() > 0){ jobj[L"matricesIndices"] = convertToJson(_boneIndices); } if (_boneWeights.size() > 0){ jobj[L"matricesWeights"] = convertToJson(_boneWeights); } if (animations.size() == 0 && !associatedSkeleton){ jobj[L"autoAnimate"] = web::json::value::boolean(false); jobj[L"autoAnimateLoop"] = web::json::value::boolean(false); jobj[L"autoAnimateFrom"] = web::json::value::number(0); jobj[L"autoAnimateTo"] = web::json::value::number(0); } else if (animations.size()>0){ jobj[L"autoAnimate"] = web::json::value::boolean(animations[0]->autoAnimate); jobj[L"autoAnimateLoop"] = web::json::value::boolean(animations[0]->autoAnimateLoop); jobj[L"autoAnimateFrom"] = web::json::value::number(animations[0]->autoAnimateFrom); jobj[L"autoAnimateTo"] = web::json::value::number(animations[0]->autoAnimateTo); } else{ jobj[L"autoAnimate"] = web::json::value::boolean(associatedSkeleton->bones[0].animation->autoAnimate); jobj[L"autoAnimateLoop"] = web::json::value::boolean(associatedSkeleton->bones[0].animation->autoAnimateLoop); jobj[L"autoAnimateFrom"] = web::json::value::number(associatedSkeleton->bones[0].animation->autoAnimateFrom); jobj[L"autoAnimateTo"] = web::json::value::number(associatedSkeleton->bones[0].animation->autoAnimateTo); } auto janimations = web::json::value::array(); for (const auto& anim : animations){ janimations[janimations.size()] = anim->toJson(); } jobj[L"animations"] = janimations; FbxMatrix identity; identity.SetIdentity(); if (pivotMatrix != identity){ auto jpivot = web::json::value::array(); for (auto x = 0; x < 4; ++x){ for (auto y = 0; y < 4; ++y){ jpivot[x * 4 + y] = web::json::value::number( pivotMatrix[x][y]); } } jobj[L"pivotMatrix"] = jpivot; } auto jinstances = web::json::value::array(); for (auto& instance : _instances) { jinstances[jinstances.size()] = instance.toJson(); } jobj[L"instances"] = jinstances; return jobj; }