张家港网站建设培训学校,梧州最权威的综合性新闻门户网站,贵阳vi设计公司,图书网站建设方案文章目录 1、简介2、下载安装2.1 安装Simlygon插件2.2 安装USD插件 3、使用测试4、Python测试结语 1、简介
Simplygon 带有一个 Unity 插件#xff0c;它公开了优化功能#xff0c;例如缩减、聚合、重新划分网格、冒名顶替者#xff08;SingleView、BillboardCloud / Veget… 文章目录 1、简介2、下载安装2.1 安装Simlygon插件2.2 安装USD插件 3、使用测试4、Python测试结语 1、简介
Simplygon 带有一个 Unity 插件它公开了优化功能例如缩减、聚合、重新划分网格、冒名顶替者SingleView、BillboardCloud / Vegetation、遮挡网格以及支持以下内置着色器的材质烘焙
标准着色器通用渲染管线 URP 预构建着色器高清渲染管线 HDRP 预构建着色器 2、下载安装
https://www.simplygon.com/downloads 将Simlygon插件导入Unity。
2.1 安装Simlygon插件
Simplygon 安装完成后按照 Unity 文档部分提供的指南从 tarball 文件安装包然后浏览以查找 tarball例如。C:\Program Files\SimplygonMajorVersion\Unity\binUnityVersionSimplygon.Unity2022Plugin.tgz 现在每次启动 Unity 时Simplygon Unity 插件都应自动加载。转到 Window - Simplygon 以显示 Simplygon UI如果尚不存在。Simplygon UI 可以停靠到 Unity 中的大多数停靠区域;只需单击并按住 Simplygon 标签并将其放置在您喜欢的位置即可。
1找到Simplygon的dll文件并将其复制到Assets文件夹下 2导入Simplygon后有
2.2 安装USD插件
每个 Unity 项目都需要手动安装 Simplygon Unity 插件由于该插件依赖于 Pixar 的 USD通用场景描述文件格式因此也会安装 Unity 提供的 USD 包。有关如何安装 Simplygon Unity 插件的信息请参阅以下说明。
Simplygon Unity 插件利用 USD 文件格式作为 Unity 和 Simplygon 之间的中间格式。Unity 中未内置 USD 支持因此支持 Unity 包与 Simplygon 插件一起安装。
1打开包管理器Window→Package Manager把Packages切换到PackagesUnity Registry 并搜索USD 2如果能搜到USD的包就点击安装。如果当前Unity版本没有集成USD包资源就选 择从Git仓库添加URL地址com.unity.formats.usd 然后点击Add添加等待USD包安装完成。 开始安装USD包
3、使用测试 1选择Window→Simplygon打开Simplygon面板 2点击Add LOD Component依次点击Template Basic Reduction with material baking。 此处有两种模式Advanced高级的和Basic基本的。根据官方介绍Basic模 式是针对新手的模式在优化参数设置上屏蔽了大多数的可选项如果你是新手或者 你希望简便快速的操作就可以选择Basic。而Advanced模式下提供了所有优化配置 项的设置如果你希望对模型做出选择性的针对性的优化就可以使用Advanced选项。 ①Reduction: 减少面片 ②Reduction with material baking减少面片数并合并材质和贴图若物体有多个材质。 ③Remeshing with material baking官方解释是用更原始的轻量级Mesh网格代替原来的Mesh并合并材质和贴图。这个我没用过可以自行 体验。 ④Aggregation合并网格若有多个Mesh或者子物体含有Mesh最后会合并成一个。 ⑤Aggregation with material baking合并网格并合并材质和贴图。 3参数设置完后点击黄色大Logo执行优化。 Run Mode选择Rum In This Process。看到ReductionSettings下可以设置目标三角面比率若看不到后面数字将窗口拉大点即可默认为0.5即生成模型面数是原来的0.5倍MappingImageSettings下可以设置贴图尺寸默认是1024 x 1024。 4简化结果比较左边是原始资产右边是优化的资产
4、Python测试
https://documentation.simplygon.com/SimplygonSDK_10.2.10100.0/api/examples/reduction/reduction.html
1首先安装包里有Simplyon SDK的Python库如下 2编写Python代码文件进行测试test.py
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License. import math
import os
import sys
import glob
import gc
import threadingfrom pathlib import Path
from simplygon10 import simplygon_loader
from simplygon10 import Simplygondef LoadScene(sg: Simplygon.ISimplygon, path: str):# Create scene importer sgSceneImporter sg.CreateSceneImporter()sgSceneImporter.SetImportFilePath(path)# Run scene importer. importResult sgSceneImporter.Run()if Simplygon.Failed(importResult):raise Exception(Failed to load scene.)sgScene sgSceneImporter.GetScene()return sgScenedef SaveScene(sg: Simplygon.ISimplygon, sgScene: Simplygon.spScene, path: str):# Create scene exporter. sgSceneExporter sg.CreateSceneExporter()outputScenePath .join([output\\, Reduction, _, path])sgSceneExporter.SetExportFilePath(outputScenePath)sgSceneExporter.SetScene(sgScene)# Run scene exporter. exportResult sgSceneExporter.Run()if Simplygon.Failed(exportResult):raise Exception(Failed to save scene.)def CheckLog(sg: Simplygon.ISimplygon):# Check if any errors occurred. hasErrors sg.ErrorOccurred()if hasErrors:errors sg.CreateStringArray()sg.GetErrorMessages(errors)errorCount errors.GetItemCount()if errorCount 0:print(CheckLog: Errors:)for errorIndex in range(errorCount):errorString errors.GetItem(errorIndex)print(errorString)sg.ClearErrorMessages()else:print(CheckLog: No errors.)# Check if any warnings occurred. hasWarnings sg.WarningOccurred()if hasWarnings:warnings sg.CreateStringArray()sg.GetWarningMessages(warnings)warningCount warnings.GetItemCount()if warningCount 0:print(CheckLog: Warnings:)for warningIndex in range(warningCount):warningString warnings.GetItem(warningIndex)print(warningString)sg.ClearWarningMessages()else:print(CheckLog: No warnings.)# Error out if Simplygon has errors. if hasErrors:raise Exception(Processing failed with an error)def RunReduction(sg: Simplygon.ISimplygon):# Load scene to process. print(Load scene to process.)sgScene LoadScene(sg, airplane/11805_airplane_v2_L2.obj)# Create the reduction processor. sgReductionProcessor sg.CreateReductionProcessor()sgReductionProcessor.SetScene( sgScene )sgReductionSettings sgReductionProcessor.GetReductionSettings()# Set reduction target to triangle ratio with a ratio of 50%. sgReductionSettings.SetReductionTargets( Simplygon.EStopCondition_All, True, False, False, False )sgReductionSettings.SetReductionTargetTriangleRatio( 0.5 )# Start the reduction process. print(Start the reduction process.)sgReductionProcessor.RunProcessing()# Save processed scene. print(Save processed scene.)SaveScene(sg, sgScene, Output.fbx)# Check log for any warnings or errors. print(Check log for any warnings or errors.)CheckLog(sg)if __name__ __main__:sg simplygon_loader.init_simplygon()if sg is None:exit(Simplygon.GetLastInitializationError())RunReduction(sg)sg Nonegc.collect()运行结果如下 输出简化模型如下
结语
如果您觉得该方法或代码有一点点用处可以给作者点个赞或打赏杯咖啡╮(▽)╭ 如果您感觉方法或代码不咋地//(ㄒoㄒ)//就在评论处留言作者继续改进o_O??? 如果您需要相关功能的代码定制化开发可以留言私信作者(✿◡‿◡) 感谢各位大佬童鞋们的支持( ´ ▽´ ) ( ´ ▽´)っ