欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 文旅 > 八卦 > Simplygon 使用笔记2

Simplygon 使用笔记2

2024/10/24 7:55:35 来源:https://blog.csdn.net/Eugen009/article/details/142665485  浏览:    关键词:Simplygon 使用笔记2

本文主收集一些实质开发中的一些问题, 大部分时候只能通过文档, 从个别的描述中找到问题的解决方法, 而这里希望能提供一些关键字, 方便具体的问题的分析

1. 怎么从spMaterial 材质中找到对应贴图的名字

  • 这个可能通过获取该GetShadingNetwork的方式获取
  • 但问题是network可能是很多节点组成,可以通过遍历所有的节点方式获取
  • 代码示例:
static string GetTextureName(Simplygon.spMaterial material){var rootNode = material.GetShadingNetwork("Diffuse");if (rootNode == null)return null;var nodeStack = new System.Collections.Generic.Stack<Simplygon.spShadingNode>();nodeStack.Push(rootNode);while (nodeStack.Count > 0){var curNode = nodeStack.Pop();if (curNode.GetName() == "ShadingTextureNode"){var texNode = Simplygon.spShadingTextureNode.SafeCast(curNode);if (texNode != null){return texNode.GetTextureName();}}else if (curNode.GetName() == "ShadingMultiplyNode"){var multiNode = Simplygon.spShadingMultiplyNode.SafeCast(curNode);if (multiNode != null){nodeStack.Push(multiNode.GetInput(0));nodeStack.Push(multiNode.GetInput(1));}}}return null;}

2. 报告错误: “vkDestroySampler: Invalid device [VUID-vkDestroySampler-device-parameter]”

  • 输入的贴图是vulkan不支持的格式
  • 输入的贴图的路径找不到

3. 生成的法线不正确

  • 需要从原始的空间再转到减面的空间
  • Simpygon提供了生成目标的sg_DestinationTangent, sg_DestinationBitangent, sg_DestinationNormal等,可以利用这些值进行转换
  • 这里使用Computer Caster进行转化, 例如
float4 NRMToDestinySpace(float4 nrm, float3 tangent, float3 bitangent, float3 normal,float3 sg_DestinationTangent, float3 sg_DestinationBitangent, float3 sg_DestinationNormal
)
{float  rough;float  metal;float3 n_ts;unpackNRM(nrm, 1.0, rough, metal, n_ts);float3 objSpaceNormal =n_ts.x * normalize(tangent) +n_ts.y * normalize(bitangent) +n_ts.z * normalize(normal);n_ts.x = dot(objSpaceNormal, normalize(sg_DestinationTangent));n_ts.y = dot(objSpaceNormal, normalize(sg_DestinationBitangent));n_ts.z = dot(objSpaceNormal, normalize(sg_DestinationNormal));n_ts = normalize(n_ts);return packNRM(n_ts, rough, metal);}

4. 报错误 pico::render::Image::CreateVkImage()

  • 具体报错内容 pico::render::Image::CreateVkImage(): Call: vmaCreateImage( vulkanDevice->GetMemoryAllocator(), &vkCreateImageInfo, &allocationCreateInfo, &vkImage, &vmaAllocation, nullptr ) failed, returned status_code: vulkan_initialization_failed (“Vulkan error code VkResult::VK_ERROR_INITIALIZATION_FAILED”)
  • 这大概率使用了较低分辨率的贴图,8像素以上貌似没有问题

5. SceneNode设置的位置总是不对?

  • 这个问题主要是因为导出格式的单位与Simplygon使用不一样, 例如Unity导出的FBX单位是米,但Simplygon里用了厘米
  • 另外, 也坐标系不一样的问题, 例如Unity使用的是左手,但simplygon中使用的右手
  • 下面举例如何设置位置
public static void TransSceneNodePos(Simplygon.ISimplygon sg, Simplygon.spSceneNode sceneNode, float[] pos){if (sceneNode == null)return;var spTrans = sg.CreateTransform3();spTrans.PreMultiply();// 乘以100,让米变厘米, x 取负,使用坐标系变成右手spTrans.AddTranslation(-pos[0] *100.0f, pos[1]*100.0f, pos[2]*100.f);sceneNode.GetRelativeTransform().DeepCopy(spTrans.GetMatrix());}

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com