/************************************************************************* * Copyright © 2018-2023 Liwen All rights reserved. *------------------------------------------------------------------------ * File : OsgbFileLoader.cs * Description : load osgb format tile info *------------------------------------------------------------------------ * Author : Liwen * Version : 1.0.0 * Date : 1/5/2019 * Description : Initial development version. *************************************************************************/ using System.Collections; using System.Collections.Generic; using UnityEngine; using System; using System.Runtime.InteropServices; using System.Linq; using System.IO; namespace AIPagedLod { [System.Serializable] public class PagedLodRangeInfo { public float mSelfMinValue; public float mSelfMaxValue; public float mChildMinValue; public float mChildMaxValue; } public class OsgbFileLoader : PagedLodFileLoader { public List mChildFiles = new List(); public List mChildRangeValues = new List(); public float mBoundRadius; public Vector3 mBoundsCenter = Vector3.zero; public Vector3 mBoundsBoxMin = Vector3.zero; public Vector3 mBoundsBoxMax = Vector3.zero; public OsgbFileLoader(string fileName) { mFileName = fileName; } public override void LoadObjectMeshInfo() { IntPtr ptr = OsgbLoader.OpenOsgbFile(mFileName); if (ptr == IntPtr.Zero) { Debug.LogError("OpenOsgbFile failure " + mFileName); return; } int meshCount = OsgbLoader.GetMeshCount(ptr); for (int i = 0; i < meshCount; ++i) { TileObjectInfo info = new TileObjectInfo(); info.mVertices = OsgbLoader.GetVertexs(ptr, i,mIsDaJiangData); info.mTriangles = OsgbLoader.GetTriangles(ptr, i, mIsDaJiangData); info.mTexCoords = OsgbLoader.GetTexCoords(ptr, i); info.mImageResolutionS = OsgbLoader.GetImageResolutionS(ptr, i); info.mImageResolutionT = OsgbLoader.GetImageResolutionT(ptr, i); info.mImageData = OsgbLoader.GetImageData(ptr, i); info.mTextureFormat = OsgbLoader.GetImageFormat(ptr, i); info.mUnityTextureFormat = TextureFormat.RGB24; if (info.mTextureFormat == 33779) { info.mUnityTextureFormat = TextureFormat.DXT5; } mObjectInfoList.Add(info); } OsgbLoader.CloseOsgbFile(ptr); } public override void LoadObjectBasicInfo() { IntPtr ptr = OsgbLoader.OpenOsgbFileEx(mFileName); if (ptr == IntPtr.Zero) { Debug.LogError("OpenOsgbFile failure " + mFileName); return; } int childCount = OsgbLoader.GetChildFileCount(ptr); for (int i = 0; i < childCount; ++i) { mChildFiles.Add(OsgbLoader.GetChildTileFile(ptr, i)); float[] rangeValues = new float[4]; OsgbLoader.GetRangeList(ptr, i, ref rangeValues[0]); PagedLodRangeInfo rangeInfo = new PagedLodRangeInfo(); rangeInfo.mSelfMinValue = rangeValues[0]; rangeInfo.mSelfMaxValue = rangeValues[1]; rangeInfo.mChildMinValue = rangeValues[2]; rangeInfo.mChildMaxValue = rangeValues[3]; mChildRangeValues.Add(rangeInfo); } if (childCount > 0) { mBoundRadius = OsgbLoader.GetBoundRadius(ptr); float[] center = new float[3]; float[] min = new float[3]; float[] max = new float[3]; OsgbLoader.GetBoundsBox(ptr, ref center[0], ref min[0], ref max[0]); mBoundsCenter = new Vector3(center[0], -center[1], -center[2]); //局部坐标 mBoundsBoxMin = new Vector3(min[0], -min[1], min[2]); //局部坐标 mBoundsBoxMax = new Vector3(max[0], -max[1], max[2]); //局部坐标 } OsgbLoader.CloseOsgbFile(ptr); } } }