public ErrorType ExportDocumentWithAcvtiveView(Document document) { string exportFolder = ExportEventHandler.Settings.OutputFolder; if (document == null || !Directory.Exists(exportFolder)) { return(ErrorType.Others); } Container.metadata.generator = "NDS"; Container.metadata.type = "Object"; Container.metadata.version = "1.0"; Container.va3cobject.uuid = StringConverter.NewGuid(); Container.va3cobject.type = "Root Object"; Container.va3cobject.name = StringConverter.ToUtf8(Path.GetFileName(document.PathName)); Container.va3cobject.bHasMatrix = true; TransformExporter.GetRootObjectMatrix(ref Container.va3cobject.matrix); //Constructs a new FilteredElementCollector that will search and filter the visible elements in a view. FilteredElementCollector elems = new FilteredElementCollector(document, document.ActiveView.Id).WhereElementIsNotElementType(); if (elems.GetElementCount() == 0) { return(ErrorType.NoElement); } Dictionary <ElementId, List <Element> > elementsDic = new Dictionary <ElementId, List <Element> >(); ClassifyElementsByStructureType(elems, ref elementsDic); if (ExportEventHandler.Settings.StructureType == CommonSettings.StructureTreeType.ByLevel) { if (!LevelExporter.ExportLevels(elementsDic, ref Container.va3cobject, document)) { return(ErrorType.NoElement); } } else if (ExportEventHandler.Settings.StructureType == CommonSettings.StructureTreeType.ByCategory) { if (!CategoryExporter.ExportCategories(elementsDic, ref Container.va3cobject, document)) { return(ErrorType.NoElement); } } MaterialExporter.GetAllMaterials(ref Container.materials); MaterialExporter.CopyTextureFiles(exportFolder); GeometryExporter.GetAllGeometries(ref Container.geometries); PropertyExporter.WritePropertyFiles(exportFolder); if (Container.va3cobject.children.Count == 0 || Container.geometries.Count == 0) { return(ErrorType.NoElement); } if (!Web3DModelWriterManage.Web3DModelWriterManage.WriteWeb3DModelFilesVersion7BufferChunksBvh(ref Container, exportFolder, "model.js", "geom.bin", 2)) { return(ErrorType.UnSupportedGeometry); } return(ErrorType.Success);; }
public DocumentExporter(Application app) { Container = new Va3cContainer(); ElementExporter.Initial(); MaterialExporter.Initial(app); GeometryExporter.Initial(); PropertyExporter.Initial(); }
public static void ExportSkelMeshSections(int index, CSkelMeshLod lod, CMeshSection sect, List <MaterialExporter>?materialExports, MeshBuilder <VERTEX, VertexColorXTextureX, VertexJoints4> mesh) { string materialName; if (sect.Material?.Load <UMaterialInterface>() is { } tex) { materialName = tex.Name; var materialExporter = new MaterialExporter(tex, true); materialExports?.Add(materialExporter); }
void OutputWholeScene() { MaterialExporter matEx = GetComponent <MaterialExporter>(); MeshExporter meshEx = GetComponent <MeshExporter>(); TextureExporter texEx = GetComponent <TextureExporter>(); Dictionary <Material, bool> matDict = new Dictionary <Material, bool>(); Dictionary <Mesh, bool> meshDict = new Dictionary <Mesh, bool>(); Dictionary <Texture2D, bool> texDict = new Dictionary <Texture2D, bool>(); GetSceneData( SceneManager.GetActiveScene(), meshDict, matDict, texDict); void * jsonObjPtr = UnsafeUtility.Malloc((long)MJsonUtility.JsonObjectSize(), 16, Unity.Collections.Allocator.Temp); string jsonPath = folder + "AssetDatabase.json"; fixed(char *c = jsonPath) { MJsonUtility.CreateJsonObject(c, (ulong)jsonPath.Length, jsonObjPtr); } List <Mesh> meshes = new List <Mesh>(meshDict.Count); List <string> meshNames = new List <string>(meshDict.Count); foreach (var i in meshDict) { string guid = AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(i.Key)); string name = folder + i.Key.name + ".vmesh"; meshes.Add(i.Key); meshNames.Add(name); MJsonUtility.UpdateKeyValue(jsonObjPtr, guid.Ptr(), (ulong)guid.Length, name.Ptr(), (ulong)name.Length); } foreach (var i in matDict) { string guid = AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(i.Key)); string name = folder + i.Key.name + ".mat"; MJsonUtility.UpdateKeyValue(jsonObjPtr, guid.Ptr(), (ulong)guid.Length, name.Ptr(), (ulong)name.Length); matEx.testMat = i.Key; matEx.PrintToFile(name); } foreach (var i in texDict) { string guid = AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(i.Key)); string name = folder + i.Key.name + ".vtex"; MJsonUtility.UpdateKeyValue(jsonObjPtr, guid.Ptr(), (ulong)guid.Length, name.Ptr(), (ulong)name.Length); texEx.texture = i.Key; texEx.path = name; texEx.useMipMap = true; texEx.tex2DFormat = TextureData.LoadFormat.LoadFormat_BC7; texEx.Print(); } meshEx.ExportAllMeshes(meshes, meshNames); MJsonUtility.OutputJsonObject(jsonPath.Ptr(), (ulong)jsonPath.Length, jsonObjPtr); MJsonUtility.DisposeJsonObject(jsonObjPtr); }
static public bool ExportGeometryObject(List <GeometryObject> rvtGeometryObjects, ref Va3cContainer.Va3cObject elementObject, Document document) { Dictionary <ElementId, List <Face> > faceGroups = new Dictionary <ElementId, List <Face> >(); Dictionary <ElementId, List <Mesh> > meshGroups = new Dictionary <ElementId, List <Mesh> >(); //按材质分组 List <Curve> curveGroup = new List <Curve>(); List <PolyLine> polylineGroup = new List <PolyLine>(); foreach (GeometryObject rvtGeometryObject in rvtGeometryObjects) { ClassifyGeometryObjects(rvtGeometryObject, document, ref faceGroups, ref meshGroups, ref curveGroup, ref polylineGroup); } //导出face foreach (KeyValuePair <ElementId, List <Face> > faceGroup in faceGroups) { Va3cContainer.Va3cObject faceGroupObject = new Va3cContainer.Va3cObject(); faceGroupObject.uuid = StringConverter.NewGuid(); faceGroupObject.type = "Mesh"; faceGroupObject.name = "Face Group"; Material material = document.GetElement(faceGroup.Key) as Material; Va3cContainer.Va3cGeometry faceGroupGeometry = new Va3cContainer.Va3cGeometry(); faceGroupGeometry.uuid = StringConverter.NewGuid(); faceGroupGeometry.data.nGeometryCategory = eGeometryCategory.Triangle; faceGroupObject.geometry = faceGroupGeometry.uuid; bool bHasUvs; if (ExportFaces(faceGroup.Value, ref faceGroupGeometry, out bHasUvs)) { if (bHasUvs) { MaterialExporter.ExportMaterial(material, typeof(Face), ref faceGroupObject.material); } else { MaterialExporter.ExportMaterial(material, typeof(Mesh), ref faceGroupObject.material); } elementObject.children.Add(faceGroupObject); Geometries.Add(faceGroupGeometry); } } //导出mesh foreach (KeyValuePair <ElementId, List <Mesh> > meshGroup in meshGroups) { Va3cContainer.Va3cObject meshGroupObject = new Va3cContainer.Va3cObject(); meshGroupObject.uuid = StringConverter.NewGuid(); meshGroupObject.type = "Mesh"; meshGroupObject.name = "Mesh Group"; Material material = document.GetElement(meshGroup.Key) as Material; MaterialExporter.ExportMaterial(material, typeof(Mesh), ref meshGroupObject.material); Va3cContainer.Va3cGeometry meshGroupGeometry = new Va3cContainer.Va3cGeometry(); meshGroupGeometry.uuid = StringConverter.NewGuid(); meshGroupGeometry.data.nGeometryCategory = eGeometryCategory.Triangle; meshGroupObject.geometry = meshGroupGeometry.uuid; if (ExportMeshes(meshGroup.Value, ref meshGroupGeometry)) { elementObject.children.Add(meshGroupObject); Geometries.Add(meshGroupGeometry); } } //导出edge Va3cContainer.Va3cObject edgeGroupObject = new Va3cContainer.Va3cObject(); edgeGroupObject.uuid = StringConverter.NewGuid(); edgeGroupObject.type = "LinePieces"; edgeGroupObject.name = "Edge Group"; MaterialExporter.ExportMaterial(null, typeof(Edge), ref edgeGroupObject.material); Va3cContainer.Va3cGeometry edgeGroupGeometry = new Va3cContainer.Va3cGeometry(); edgeGroupGeometry.uuid = StringConverter.NewGuid(); edgeGroupGeometry.data.nGeometryCategory = eGeometryCategory.Line; edgeGroupObject.geometry = edgeGroupGeometry.uuid; if (ExportCurveAndPoliLines(curveGroup, polylineGroup, ref edgeGroupGeometry)) { elementObject.children.Add(edgeGroupObject); Geometries.Add(edgeGroupGeometry); } return(true); }
/// <summary> /// エクスポート可能か検証する /// </summary> /// <returns></returns> public IEnumerable <Validation> Validate() { if (Source == null) { yield return(Validation.Error("Require source")); yield break; } if (Source.transform.position != Vector3.zero || Source.transform.rotation != Quaternion.identity || Source.transform.localScale != Vector3.one) { EditorUtility.DisplayDialog("Error", "The Root transform should have Default translation, rotation and scale.", "ok"); yield return(Validation.Error("The Root transform should have Default translation, rotation and scale.")); } var animator = Source.GetComponent <Animator>(); if (animator == null) { yield return(Validation.Error("Require animator. ")); } else if (animator.avatar == null) { yield return(Validation.Error("Require animator.avatar. ")); } else if (!animator.avatar.isValid) { yield return(Validation.Error("Animator.avatar is not valid. ")); } else if (!animator.avatar.isHuman) { yield return(Validation.Error("Animator.avatar is not humanoid. Please change model's AnimationType to humanoid. ")); } var jaw = animator.GetBoneTransform(HumanBodyBones.Jaw); if (jaw != null) { yield return(Validation.Warning("Jaw bone is included. It may not be what you intended. Please check the humanoid avatar setting screen")); } if (DuplicateBoneNameExists()) { yield return(Validation.Error("Find duplicate Bone names. Please check model's bone names. ")); } if (string.IsNullOrEmpty(Title)) { yield return(Validation.Error("Require Title. ")); } if (string.IsNullOrEmpty(Version)) { yield return(Validation.Error("Require Version. ")); } if (string.IsNullOrEmpty(Author)) { yield return(Validation.Error("Require Author. ")); } if (ReduceBlendshape && Source.GetComponent <VRMBlendShapeProxy>() == null) { yield return(Validation.Error("ReduceBlendshapeSize needs VRMBlendShapeProxy. You need to convert to VRM once.")); } var vertexColor = Source.GetComponentsInChildren <SkinnedMeshRenderer>().Any(x => x.sharedMesh.colors.Length > 0); if (vertexColor) { yield return(Validation.Warning("This model contains vertex color")); } var renderers = Source.GetComponentsInChildren <Renderer>(); if (renderers.All(x => !x.gameObject.activeInHierarchy)) { yield return(Validation.Error("No active mesh")); } var materials = renderers.SelectMany(x => x.sharedMaterials).Distinct(); foreach (var material in materials) { if (material.shader.name == "Standard") { // standard continue; } if (MaterialExporter.UseUnlit(material.shader.name)) { // unlit continue; } if (VRMMaterialExporter.VRMExtensionShaders.Contains(material.shader.name)) { // VRM supported continue; } yield return(Validation.Warning(string.Format("unknown material '{0}' is used. this will export as `Standard` fallback", material.shader.name))); } foreach (var material in materials) { if (IsFileNameLengthTooLong(material.name)) { yield return(Validation.Error(string.Format("FileName '{0}' is too long. ", material.name))); } } var textureNameList = new List <string>(); foreach (var material in materials) { var shader = material.shader; int propertyCount = ShaderUtil.GetPropertyCount(shader); for (int i = 0; i < propertyCount; i++) { if (ShaderUtil.GetPropertyType(shader, i) == ShaderUtil.ShaderPropertyType.TexEnv) { if ((material.GetTexture(ShaderUtil.GetPropertyName(shader, i)) != null)) { var textureName = material.GetTexture(ShaderUtil.GetPropertyName(shader, i)).name; if (!textureNameList.Contains(textureName)) { textureNameList.Add(textureName); } } } } } foreach (var textureName in textureNameList) { if (IsFileNameLengthTooLong(textureName)) { yield return(Validation.Error(string.Format("FileName '{0}' is too long. ", textureName))); } } var vrmMeta = Source.GetComponent <VRMMeta>(); if (vrmMeta != null && vrmMeta.Meta != null && vrmMeta.Meta.Thumbnail != null) { var thumbnailName = vrmMeta.Meta.Thumbnail.name; if (IsFileNameLengthTooLong(thumbnailName)) { yield return(Validation.Error(string.Format("FileName '{0}' is too long. ", thumbnailName))); } } var meshFilters = Source.GetComponentsInChildren <MeshFilter>(); var meshesName = meshFilters.Select(x => x.sharedMesh.name).Distinct(); foreach (var meshName in meshesName) { if (IsFileNameLengthTooLong(meshName)) { yield return(Validation.Error(string.Format("FileName '{0}' is too long. ", meshName))); } } var skinnedmeshRenderers = Source.GetComponentsInChildren <SkinnedMeshRenderer>(); var skinnedmeshesName = skinnedmeshRenderers.Select(x => x.sharedMesh.name).Distinct(); foreach (var skinnedmeshName in skinnedmeshesName) { if (IsFileNameLengthTooLong(skinnedmeshName)) { yield return(Validation.Error(string.Format("FileName '{0}' is too long. ", skinnedmeshName))); } } }
/// <summary> /// エクスポート可能か検証する /// </summary> /// <returns></returns> public IEnumerable <Validation> Validate() { if (Source == null) { yield return(Validation.Error("Require source")); yield break; } var animator = Source.GetComponent <Animator>(); if (animator == null) { yield return(Validation.Error("Require animator. ")); } else if (animator.avatar == null) { yield return(Validation.Error("Require animator.avatar. ")); } else if (!animator.avatar.isValid) { yield return(Validation.Error("Animator.avatar is not valid. ")); } else if (!animator.avatar.isHuman) { yield return(Validation.Error("Animator.avatar is not humanoid. Please change model's AnimationType to humanoid. ")); } var jaw = animator.GetBoneTransform(HumanBodyBones.Jaw); if (jaw != null) { yield return(Validation.Warning("Jaw bone is included. It may not be what you intended. Please check the humanoid avatar setting screen")); } if (DuplicateBoneNameExists()) { yield return(Validation.Error("Find duplicate Bone names. Please check model's bone names. ")); } if (string.IsNullOrEmpty(Title)) { yield return(Validation.Error("Require Title. ")); } if (string.IsNullOrEmpty(Version)) { yield return(Validation.Error("Require Version. ")); } if (string.IsNullOrEmpty(Author)) { yield return(Validation.Error("Require Author. ")); } if (ReduceBlendshape && Source.GetComponent <VRMBlendShapeProxy>() == null) { yield return(Validation.Error("ReduceBlendshapeSize is need VRMBlendShapeProxy, you need to convert to VRM once.")); } var vertexColor = Source.GetComponentsInChildren <SkinnedMeshRenderer>().Any(x => x.sharedMesh.colors.Length > 0); if (vertexColor) { yield return(Validation.Warning("This model contains vertex color")); } var renderers = Source.GetComponentsInChildren <Renderer>(); if (renderers.All(x => !x.gameObject.activeInHierarchy)) { yield return(Validation.Error("No active mesh")); } var materials = renderers.SelectMany(x => x.sharedMaterials).Distinct(); foreach (var material in materials) { if (material.shader.name == "Standard") { // standard continue; } if (MaterialExporter.UseUnlit(material.shader.name)) { // unlit continue; } if (VRMMaterialExporter.VRMExtensionShaders.Contains(material.shader.name)) { // VRM supported continue; } yield return(Validation.Warning(string.Format("unknown material '{0}' is used. this will export as `Standard` fallback", material.shader.name))); } }