private static void LoadData(string cubletName) { ModelImporter importer = new ModelImporter(pathToDataFiles + cubletName + @"\" + cubletName + ".obj"); CubletRenderingData data = new CubletRenderingData(); data.normalArray = importer.normalArray; data.texelArray = importer.texelArray; data.triangleArray = importer.triangleArray; data.vertexArray = importer.vertexArray; cubletDictionary.Add(cubletName, data); }
public void Load_TestObj_ValidNumberOfVertices() { var importer = new ModelImporter(); var model = importer.Load(@"Models\obj\test.obj"); int countVertices = 0; model.Traverse<GeometryModel3D>((geometryModel, transform) => { var mesh = (MeshGeometry3D)geometryModel.Geometry; countVertices += mesh.Positions.Count; }); Assert.AreEqual(17, countVertices); }
private void ScanForAnimations() { List <string> pathsWithExtensions = ValidatorData.GetPathsWithExtensions(ValidatorData.MODEL_EXTENSIONS, null); foreach (string text in pathsWithExtensions) { List <ModelImporterClipAnimation> list = new List <ModelImporterClipAnimation>(); ModelImporter modelImporter = (ModelImporter)AssetImporter.GetAtPath(text); list.AddRange(modelImporter.clipAnimations); list.AddRange(modelImporter.defaultClipAnimations); HashSet <string> hashSet = new HashSet <string>(); for (int i = 0; i < list.Count; i++) { if (!hashSet.Add(list[i].name)) { this.animationCheck.AddPath(text); break; } } } }
protected void OnPreprocessModel() { // Restrict this to the same folders as the standard asset post-processor. if (!ProjectAssetPostprocessor.IsIncludedFolder(assetPath)) { return; } if (!assetPath.ToLower().Contains(SpriteAnimImporterPrefs.NameFilter.ToLower())) { return; } ModelImporter importer = (ModelImporter)assetImporter; importer.importMaterials = true; Debug.Log("SpriteAnimImporter: Asset path " + assetPath + " contained sprite animation marker " + SpriteAnimImporterPrefs.NameFilter.ToLower() + ". Beginning import pre-processing."); }
void OnPreprocessModel() { ModelImporter modelImporter = (ModelImporter)assetImporter; // MATERIAL NAME // ModelImporterMaterialName.BasedOnMaterialName // ModelImporterMaterialName.BasedOnModelNameAndMaterialName // ModelImporterMaterialName.BasedOnTextureName modelImporter.materialName = ModelImporterMaterialName.BasedOnMaterialName; // MATERIAL SEARCH // ModelImporterMaterialSearch.Everywhere // ModelImporterMaterialSearch.Local // ModelImporterMaterialSearch.RecursiveUp modelImporter.materialSearch = ModelImporterMaterialSearch.Everywhere; if (assetPath.Contains("@") && modelImporter.animationType != ModelImporterAnimationType.Human) { modelImporter.animationType = ModelImporterAnimationType.Legacy; } }
/// <summary> /// set AnimationClip /// </summary> private void SetAnimationClips(ModelImporter importer, CustomModelImporterSettingValue customSettings) { var clips = importer.clipAnimations; if (clips == null) { return; } for (int i = 0; i < clips.Length; i++) { var clip = clips[i]; if (customSettings.LoopTime.IsConfigurable) { clip.loopTime = customSettings.LoopTime; } } importer.clipAnimations = clips; }
private void Log(string path, Transform trans, string hierarchy) { ////Debug.Log("Prefab:" + path + System.Environment.NewLine //// + "GameObject " + hierarchy + System.Environment.NewLine //// + "MeshCollider and scale " + trans.localScale + " (lossy " + trans.lossyScale + ")"); // "Prefab\tGameObject\tLocal scale\tLossy scale\tMesh\tMesh Asset\tRead/write\tCheck" MeshCollider mc = trans.GetComponent <MeshCollider>(); Mesh mesh = mc.sharedMesh; string assetPath = mesh ? AssetDatabase.GetAssetPath(mesh) : "-"; ModelImporter meshImporter = mesh ? AssetImporter.GetAtPath(assetPath) as ModelImporter : null; this.csvLog.AppendLine(path + "\t" + hierarchy + "\t" + "(" + trans.localScale.x + "," + trans.localScale.y + "," + trans.localScale.z + ")\t" + "(" + trans.lossyScale.x + "," + trans.lossyScale.y + "," + trans.lossyScale.z + ")\t" + (mesh ? mesh.name : "[null]") + "\t" + (mesh ? AssetDatabase.GetAssetPath(mesh) : "-") + "\t" + (meshImporter ? meshImporter.isReadable.ToString() : "-") + "\t"); }
public void TestFbxReferenceModifier() { var replaceList = new Dictionary <string, string>(); replaceList.Add("BOOTHID", "id"); replaceList.Add("NAME", "name"); AssetDatabase.CreateFolder("Assets", "TestTemplateLoad"); Assert.That(TemplateLoader.Load("Sample_template", replaceList, "Assets/TestTemplateLoad"), Is.True); var modelImporter = ModelImporter.GetAtPath("Assets/TestTemplateLoad/id_name/Models/Sample_object.fbx"); var map = modelImporter.GetExternalObjectMap(); foreach (var pair in map) { if (pair.Value is Material) { var mat = pair.Value as Material; var matPath = AssetDatabase.GetAssetPath(mat.GetInstanceID()); Assert.That(matPath, Is.EqualTo("Assets/TestTemplateLoad/id_name/Materials/Sample Material.mat")); } } }
public static void FormateFbx(ref ModelImporter model) { model.animationType = ModelImporterAnimationType.None; model.importMaterials = false; model.importAnimation = false; model.meshCompression = ModelImporterMeshCompression.High; model.importTangents = ModelImporterTangents.None; model.isReadable = false; model.optimizeMesh = true; model.importBlendShapes = false; model.weldVertices = true; model.addCollider = false; model.importVisibility = false; model.importCameras = false; model.importLights = false; model.preserveHierarchy = false; model.swapUVChannels = false; model.animationCompression = ModelImporterAnimationCompression.Optimal; model.indexFormat = ModelImporterIndexFormat.UInt16; }
static void Change2Generic() { Object _obj = Selection.activeObject; string[] _temp = Directory.GetFiles(AssetDatabase.GetAssetPath(_obj), "*.FBX", SearchOption.AllDirectories); HashSet <string> _paths = new HashSet <string>(); foreach (var item in _temp) { _paths.Add(item); } foreach (var item in _paths) { ModelImporter _ai = ModelImporter.GetAtPath(item) as ModelImporter; _ai.animationType = ModelImporterAnimationType.Generic; _ai.SaveAndReimport(); } AssetDatabase.SaveAssets(); AssetDatabase.Refresh(); Debug.Log("将该目录下的所有fbx改为generic 完成"); }
private static void ApplyModelRule(ModelImporter modelImporter, ModelFolderRule rule) { if (rule == null) { return; } ModelFolderRule newRule = CustomImportRuleFactory.Create(modelImporter, rule); if (null == newRule) { return; } SerializedObject modelSerObj = new SerializedObject(modelImporter); SerializedObjectUtility.CopyInstanceToSerializedObject(modelSerObj.GetIterator(), newRule); modelSerObj.ApplyModifiedProperties(); AssetDatabase.Refresh(); newRule.DoCustomRule(modelImporter); }
public static void OnPostprocessModel(ModelImporter importer) { postprocessorUtils = postprocessorUtils ? postprocessorUtils : SoAssetPostprocessorUtils.GetSoAssetPostprocessorUtils(); var guid = postprocessorUtils.Get(PostprocessorAssetType.Model, importer.assetPath); if (string.IsNullOrEmpty(guid)) { return; } var path = AssetDatabase.GUIDToAssetPath(guid); var so = AssetDatabase.LoadAssetAtPath <SoModelPostprocessor>(path); if (so == null) { so = SoAssetPostprocessor.GetDefault(PostprocessorAssetType.Model) as SoModelPostprocessor; } SetSettings(importer, so); Reimport(importer, so); }
// This method is called just before importing an FBX. void OnPreprocessModel() { Debug.Log("OnPreprocessModel assetPath:" + assetPath); ModelImporter mi = (ModelImporter)assetImporter; mi.globalScale = 1; if (!assetPath.Contains("/Characters/")) { return; } mi.animationCompression = ModelImporterAnimationCompression.Off; // we don't need Materials for Bones and Animation. if (assetPath.Contains("/Models")) { return; } mi.importMaterials = false; }
public Model3D Display3d(string model) { try { ModelImporter import = new ModelImporter(); device = import.Load(model); device.SetName("robot"); // get real size of robot robot3DInfo.Sx = device.Bounds.SizeX; // mm to m robot3DInfo.Sy = device.Bounds.SizeY; robot3DInfo.Sz = device.Bounds.SizeZ; ScaledRobot(GlobalVariables.ROBOT_SCALED, GlobalVariables.ROBOT_SCALED, 0); contentlayer.Children.Add(device3D); } catch (Exception e) { // Handle exception in case can not file 3D model MessageBox.Show("Exception Error : " + e.StackTrace); } return(device); }
public static bool CheckFBXEmbeddedTextures(string fbxPath)/*fbxPath Example : @"Assets\TESTFBX\Demo_10.fbx" */ { BindingFlags flags = BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance; ModelImporter fbx = AssetImporter.GetAtPath(fbxPath) as ModelImporter; var fbx_editor = Editor.CreateEditor(fbx); var tabsProp = fbx_editor.GetType().GetProperty("tabs", flags); System.Array tabs = (System.Array)tabsProp.GetValue(fbx_editor); var modelImporterMaterialEditor = tabs.GetValue(3); var hasEmbeddedTexturesProp = modelImporterMaterialEditor.GetType().GetField("m_HasEmbeddedTextures", flags); SerializedProperty hasEmbeddedTextures = hasEmbeddedTexturesProp.GetValue(modelImporterMaterialEditor) as SerializedProperty; bool result = hasEmbeddedTextures.boolValue; Editor.DestroyImmediate(fbx_editor, false); return(result); }
void OnPreprocessModel() { ModelImporter modelImporter = assetImporter as ModelImporter; // Model Settings modelImporter.importCameras = false; modelImporter.importLights = false; // Rig settings modelImporter.animationType = ModelImporterAnimationType.Human; // Animatino Settings modelImporter.importAnimation = false; // Material if (!modelImporter.ExtractTextures(@"Assets/Textures")) { Debug.LogError("Failed to extract textures"); } }
public void OnPreprocessModel(string importAssetPath, AssetImporter assetImporter) { ModelImporter templateImporter = GetTemplateAssetImporter(importAssetPath) as ModelImporter; if (templateImporter == null) { return; } // 如果模板被更改,那么更新全部资源 if (Path.GetFileName(importAssetPath) == Path.GetFileName(templateImporter.assetPath)) { ProcessAllModel(templateImporter); return; } ModelImporter targetImporter = assetImporter as ModelImporter; ImportCopyer.CopyModelImporter(targetImporter, templateImporter); Debug.Log($"[DefaultProcessor] 资源格式设置完毕 : {importAssetPath}"); }
public static void ConfigureImportSettings(string filename, object customSettings = null) { if (customSettings == null) { customSettings = new { resampleCurves = false, animationType = ModelImporterAnimationType.Legacy, animationCompression = ModelImporterAnimationCompression.Off, importConstraints = true }; } ModelImporter modelImporter = AssetImporter.GetAtPath(filename) as ModelImporter; modelImporter.resampleCurves = (bool)customSettings.GetType().GetProperty("resampleCurves").GetValue(customSettings, null); AssetDatabase.ImportAsset(filename); modelImporter.animationType = (ModelImporterAnimationType)customSettings.GetType().GetProperty("animationType").GetValue(customSettings, null); modelImporter.animationCompression = (ModelImporterAnimationCompression)customSettings.GetType().GetProperty("animationCompression").GetValue(customSettings, null); modelImporter.importConstraints = (bool)customSettings.GetType().GetProperty("importConstraints").GetValue(customSettings, null); AssetDatabase.ImportAsset(filename); }
public void OnPreprocessModel() { Debug.Log(assetImporter.name); //#if !CUTANI // Debug.Log("没有定义 CUTANI"); // return; //#endif //Bean.InitPublicExcelTables(); if (!File.Exists(path)) { Debug.Log("文件不存在 " + path); return; } ModelImporter _modelImporter = (ModelImporter)assetImporter; _modelImporter.animationType = ModelImporterAnimationType.Legacy; //_modelImporter.generateAnimations = ModelImporterGenerateAnimations.GenerateAnimations; string[] strs = File.ReadAllLines(path); Debug.Log(path + " " + strs.Length); string sel = Selection.activeObject.name; if (sel == null || strs[0] != sel) { Debug.LogError("streamingAssetsPath/ani.txt 名字没有修改 :" + sel + ": " + strs[0]); return; } ModelImporterClipAnimation[] _animations = new ModelImporterClipAnimation[strs.Length - 1]; for (int i = 1; i < strs.Length; i++) { string[] aniStrs = strs[i].Split('|'); _animations[i - 1] = SetClipAnimation(i.ToString(), int.Parse(aniStrs[0]), int.Parse(aniStrs[1]), i == 1); } _modelImporter.clipAnimations = _animations; }
private void OnPreprocessModel() { ModelImporter modelImporter = assetImporter as ModelImporter; if( modelImporter != null ) { bool useImportSettings = EditorPrefs.GetBool( "ModelImportManager.UseImportSettings", false ); if( useImportSettings ) { string presetName = EditorPrefs.GetString( "ModelImportManager.CurrentPreset", string.Empty ); string prefix = "ModelImportManager." + presetName; // Meshes modelImporter.globalScale = EditorPrefs.GetFloat( prefix + ".GlobalScale", 1.0f ); modelImporter.meshCompression = (ModelImporterMeshCompression)System.Enum.Parse( typeof(ModelImporterMeshCompression), EditorPrefs.GetString( prefix + ".MeshCompression", "Off" ) ); modelImporter.optimizeMesh = EditorPrefs.GetBool( prefix + ".OptimizeMesh", false ); modelImporter.addCollider = EditorPrefs.GetBool( prefix + ".AddCollider", false ); modelImporter.swapUVChannels = EditorPrefs.GetBool( prefix + ".SwapUVChannels", false ); modelImporter.generateSecondaryUV = EditorPrefs.GetBool( prefix + ".GenerateSecondaryUV", false ); // Normals & Tangents modelImporter.normalImportMode = (ModelImporterTangentSpaceMode)System.Enum.Parse( typeof(ModelImporterTangentSpaceMode), EditorPrefs.GetString( prefix + ".NormalImportMode", "Import" ) ); modelImporter.tangentImportMode = (ModelImporterTangentSpaceMode)System.Enum.Parse( typeof(ModelImporterTangentSpaceMode), EditorPrefs.GetString( prefix + ".TangentImportMode", "Calculate" ) ); modelImporter.normalSmoothingAngle = EditorPrefs.GetFloat( prefix + ".NormalSmoothingAngle", 60.0f ); modelImporter.splitTangentsAcrossSeams = EditorPrefs.GetBool( prefix + ".SplitTangentsAcrossSeams", false ); // Materials modelImporter.importMaterials = EditorPrefs.GetBool( prefix + ".ImportMaterials", false ); modelImporter.materialName = (ModelImporterMaterialName)System.Enum.Parse( typeof(ModelImporterMaterialName), EditorPrefs.GetString( prefix + ".MaterialName", "BasedOnTextureName" ) ); modelImporter.materialSearch = (ModelImporterMaterialSearch)System.Enum.Parse( typeof(ModelImporterMaterialSearch), EditorPrefs.GetString( prefix + ".MaterialSearch", "RecursiveUp" ) ); Debug.Log( "ModelImportProcessor::OnPreprocessModel, Using custom import settings of preset '" + presetName + "'." ); } } }
void ShowUpdateReferenceClip() { if (targets.Length > 1 || m_CopyAvatar.boolValue || !m_Avatar || !m_Avatar.isValid) { return; } string[] paths = new string[0]; ModelImporter importer = target as ModelImporter; if (importer.referencedClips.Length > 0) { foreach (string clipGUID in importer.referencedClips) { ArrayUtility.Add(ref paths, AssetDatabase.GUIDToAssetPath(clipGUID)); } } // Show only button if some clip reference this avatar. if (paths.Length > 0 && GUILayout.Button(Styles.UpdateReferenceClips, GUILayout.Width(150))) { foreach (string path in paths) { SetupReferencedClip(path); } try { AssetDatabase.StartAssetEditing(); foreach (string path in paths) { AssetDatabase.ImportAsset(path); } } finally { AssetDatabase.StopAssetEditing(); } } }
// LGC private void OnPreprocessModel() { string fullPath = Util.GetFullPath(assetImporter.assetPath); ModelImporter mi = assetImporter as ModelImporter; if (AssetMap.ContainsKey(fullPath)) { string texturePath = AssetMap[fullPath]; mi.materialSearch = ModelImporterMaterialSearch.Local; mi.materialName = ModelImporterMaterialName.BasedOnTextureName; mi.normalCalculationMode = ModelImporterNormalCalculationMode.Unweighted_Legacy; mi.importNormals = ModelImporterNormals.Import; mi.importMaterials = true; mi.importAnimation = false; mi.importBlendShapes = false; #if UNITY_2018 mi.materialLocation = ModelImporterMaterialLocation.InPrefab; EditorApplication.delayCall += () => { Material mat = null; Object[] things = AssetDatabase.LoadAllAssetRepresentationsAtPath(assetImporter.assetPath); foreach (Object o in things) { if (o is Material) { mat = o as Material; mat.shader = TheShader; } } if (mat) { EditorApplication.delayCall += () => { mat.mainTexture = AssetDatabase.LoadAssetAtPath <Texture2D>(Util.FixedRelativePath(texturePath)); }; } }; #endif } }
// [MenuItem("L7/批量更改动画文件")] // static void ModifyAnimationBatch() { // string path = AssetDatabase.GetAssetPath(Selection.activeGameObject); // } public static void ModifyAnimationBatch(string existPath) { var path = Path.GetDirectoryName(existPath); if (path != null) { string[] filePaths = Directory.GetFiles(path, "*.meta", SearchOption.TopDirectoryOnly); foreach (var filePath in filePaths) { if (filePath.Contains(@"@")) { ModifyClip(filePath); } if (filePath.Contains(@"@attack")) { ModifyAnimation(filePath, EventType.OnAttack); } else if (filePath.Contains(@"@skill")) { ModifyAnimation(filePath, EventType.OnUseSkill); } else if (filePath.Contains(@"@death")) { ModifyAnimation(filePath, EventType.OnDeathAnimationEnd); } else if (filePath.Contains(@"@idle") || filePath.Contains(@"@run") || filePath.Contains(@"@stand")) { ModifyAnimation(filePath, EventType.None); } if (filePath.Contains(@"@")) { string animationFilePath = filePath.Remove(filePath.LastIndexOf(@".meta", StringComparison.Ordinal)); ModelImporter modelImporter = (ModelImporter)AssetImporter.GetAtPath(animationFilePath); modelImporter.SaveAndReimport(); } } } }
void OnPreprocessModel() { // Check if this is the first import. If not, skip. if (!assetImporter.importSettingsMissing) { return; } LogAction("First import of a model, changing import settings."); ModelImporter modelImporter = assetImporter as ModelImporter; if (ImporterSettings.BlendShapeNormals != ImporterSettingsEnums.BlendShapeNormalsMode.Default) { if (ImporterSettings.BlendShapeNormals == ImporterSettingsEnums.BlendShapeNormalsMode.Import) { // Enable import blendshape normals automatically modelImporter.importBlendShapeNormals = ModelImporterNormals.Import; } else if (ImporterSettings.BlendShapeNormals == ImporterSettingsEnums.BlendShapeNormalsMode.None) { // Disable blendshape normals automatically modelImporter.importBlendShapeNormals = ModelImporterNormals.None; } else { // Set "legacy blend shapes" enabled automatically PropertyInfo legacyBlendShapeNormalsEnabled = modelImporter.GetType().GetProperty("legacyComputeAllNormalsFromSmoothingGroupsWhenMeshHasBlendShapes", BindingFlags.NonPublic | BindingFlags.Instance); legacyBlendShapeNormalsEnabled.SetValue(modelImporter, true); } } // tesselating, are we? modelImporter.keepQuads = ImporterSettings.KeepQuads; modelImporter.importCameras = ImporterSettings.ImportCameras; modelImporter.importTangents = (ModelImporterTangents)ImporterSettings.TangentsMode; }
public void LoadModel(string path, bool transformYup, double scale) { var importer = new ModelImporter(); var mod = importer.Load(path); if (mod == null || mod.Children.Count == 0) { return; } var model = (mod.Children[0] as GeometryModel3D); if (model == null) { return; } var mesh = model.Geometry as MeshGeometry3D; if (mesh == null) { return; } var transform = new Transform3DGroup(); if (transformYup) { transform.Children.Add(new RotateTransform3D(new AxisAngleRotation3D(new Vector3D(1, 0, 0), 90))); } transform.Children.Add(new ScaleTransform3D(scale, scale, scale)); for (int i = 0; i < mesh.Positions.Count; i++) { mesh.Positions[i] = transform.Transform(mesh.Positions[i]); } ScaleHeightOnly = false; Geometry = mesh; }
internal Model3D GetModel3D(string path) { if (string.IsNullOrWhiteSpace(path)) { return(null); } Model3D device = null; try { ModelImporter import = new ModelImporter(); device = import.Load(path); } catch (Exception e) { // Logged exception } return(device); }
public void OnPreprocessModel() { if (Path.GetExtension(assetPath).ToLower() == ".fbx" && !assetPath.Contains("@")) { try { string path = Path.GetDirectoryName(assetPath); string file_name = Path.GetFileNameWithoutExtension(assetPath); string full_txt_path = path + "/" + file_name + ".txt"; if (!File.Exists(full_txt_path)) { return; } using (StreamReader file_stream = new StreamReader(full_txt_path)) { string sAnimList = file_stream.ReadToEnd(); if (EditorUtility.DisplayDialog("FBX Animation Import from file", file_name, "Import", "Cancel")) { List <ModelImporterClipAnimation> list_clip = new List <ModelImporterClipAnimation>(); ParseAnimFile(sAnimList, ref list_clip); ModelImporter modelImporter = assetImporter as ModelImporter; modelImporter.animationType = ModelImporterAnimationType.Legacy; modelImporter.meshCompression = ModelImporterMeshCompression.Medium; modelImporter.clipAnimations = list_clip.ToArray(); EditorUtility.DisplayDialog("Imported animations", "Number of imported clips: " + modelImporter.clipAnimations.GetLength(0).ToString(), "OK"); } } } catch (Exception e) { Debug.LogError("导入出错:" + e.Message); EditorUtility.DisplayDialog("Imported animations", e.Message, "OK"); } } }
/// <summary> /// Create a visible model of the STL file /// </summary> /// <param name="filename">The STL file with full extension</param> public void ViewNewStl(string filename) { // WTF!! No file if (!File.Exists(filename)) { return; } // Check the file extension to be STL FileInfo fileInfo = new FileInfo(filename); if (fileInfo.Extension.ToLower() != ".stl") { return; } ModelColor = configuration.STLcolor; Filename = filename; // Create a model of the STL file ModelImporter modellImporter = new ModelImporter(); modellImporter.DefaultMaterial = new DiffuseMaterial( new SolidColorBrush((Color)ColorConverter.ConvertFromString(modellColor))); Model3DGroup model3DGroup = modellImporter.Load(filename); StlModel.Content = model3DGroup; myViewPort3D.CameraController.ResetCamera(); myViewPort3D.CameraController.ZoomExtents(0); }
void BasicAssetOut.PickAssetAtPath <ElementType>(string path, Taker <ElementType> collector) { try { var contentFullPath = Path.GetDirectoryName(assetUnitInfo.localref) + "/" + path; if (typeof(ElementType) == (typeof(ModelImporter))) { var importer = (ElementType)(object)ModelImporter.GetAtPath(contentFullPath); collector.Take(importer); } else if (typeof(UnityEngine.Object).IsAssignableFrom(typeof(ElementType))) { try { foreach (var asset in AssetDatabase.LoadAllAssetsAtPath(contentFullPath)) { try { var concreteAsset = (ElementType)(object)asset; if (concreteAsset != null) { collector.Take(concreteAsset); break; } } catch { } } } catch { collector.OnFail("StdEditTimeUnityAssetIO.PickAssetAtPath: "); } } else { if (File.Exists(contentFullPath)) { collector.Take(RequiredFuncs.FromJsonAtPath <ElementType>(contentFullPath)); } } } catch (Exception e) { Debug.LogError(e); } collector.OnFinish(); }
private void SetGeometry(string model) { Model3DGroup device = null; try { //Import 3D model file ModelImporter import = new ModelImporter(); System.Windows.Media.Media3D.Material mat = MaterialHelper.CreateMaterial( //new SolidColorBrush(Colors.SaddleBrown)); new SolidColorBrush(Colors.Pink)); import.DefaultMaterial = mat; //Load the 3D model file device = import.Load(model); } catch (Exception e) { // Handle exception in case can not file 3D model MessageBox.Show("Exception Error : " + e.StackTrace); } Visual3DModel = device; }
/// <summary> /// Display 3D Model /// </summary> /// <param name="model">Path to the Model file</param> /// <returns>3D Model Content</returns> private Model3D Display3d(string model) { Model3D device = null; try { //Adding a gesture here viewPort3d.RotateGesture = new MouseGesture(MouseAction.LeftClick); //Import 3D model file ModelImporter import = new ModelImporter(); //Load the 3D model file device = import.Load(model); } catch (Exception e) { // Handle exception in case can not file 3D model MessageBox.Show("Exception Error : " + e.StackTrace); } return(device); }
void OnPreprocessModel() { if (assetPath.Contains("Assets/Art_new/UI/")) { //UI 模型; ModelImporter modelImporter = (ModelImporter)assetImporter; modelImporter.globalScale = 1; modelImporter.meshCompression = ModelImporterMeshCompression.Off; modelImporter.isReadable = false; modelImporter.optimizeMesh = true; modelImporter.addCollider = false; modelImporter.swapUVChannels = false; modelImporter.generateSecondaryUV = false; modelImporter.normalImportMode = ModelImporterTangentSpaceMode.Calculate; modelImporter.tangentImportMode = ModelImporterTangentSpaceMode.Calculate; modelImporter.normalSmoothingAngle = 60; modelImporter.splitTangentsAcrossSeams = true; modelImporter.importMaterials = false; } }