//----------------------------------------------------------------------------------- private void UpdateAnimatedByVertexBody( Transform tr, BodyInfo bdInfo ) { BodyMeshInfo bdmeshInfo = (BodyMeshInfo)bdInfo; tr.localPosition = bdmeshInfo.position_; tr.localRotation = bdmeshInfo.orientation_; bool isAnimatedMesh = eManager_.IsBMeshAnimatedByArrPos(bdmeshInfo.idBody_); if ( isAnimatedMesh ) { tr.localScale = Vector3.one; Tuple2<UnityEngine.Mesh, MeshUpdater> meshData = eManager_.GetBodyMeshRenderUpdaterRef(bdInfo.idBody_); UnityEngine.Mesh meshToUpdate = meshData.First; MeshUpdater meshUpdater = meshData.Second; meshToUpdate.vertices = bdmeshInfo.arrVertices_; mcForUpdates.Clear(); mcForUpdates.Set(meshToUpdate, null); CaronteSharp.Tools.UpdateVertexNormalsAndTangents( meshUpdater, mcForUpdates ); meshToUpdate.normals = mcForUpdates.arrNormal_; meshToUpdate.tangents = mcForUpdates.arrTan_; meshToUpdate.RecalculateBounds(); } }
public override void OnInspectorGUI() { base.DrawDefaultInspector(); MeshUpdater meshUpdater = (MeshUpdater)target; // Show the blender path if it is set if (meshUpdater.PathToBlenderSet) { GUI.enabled = false; EditorGUILayout.TextField("Blender Path: ", meshUpdater.PathToBlender); GUI.enabled = true; } // Button to select the blender.exe if (GUILayout.Button("Open Blender directory")) { // open the ProgramFiles directory of this system string blenderpath = EditorUtility.OpenFilePanel("Select blender.exe", Environment.GetEnvironmentVariable("ProgramFiles"), "exe"); // If the user did not select and exe then show dialog if (string.IsNullOrEmpty(blenderpath)) { EditorUtility.DisplayDialog("Select blender.exe", "You must select the blender.exe!", "OK"); } // Else update blender path else { meshUpdater.PathToBlender = blenderpath; } } // Do not show Scan and Update button if blender path is not set if (!meshUpdater.PathToBlenderSet) { return; } if (GUILayout.Button("Scan")) { meshUpdater.Scan(); } if (GUILayout.Button("Update")) { meshUpdater.UpdateModels(); } }
private void UpdateSoftBody( Transform tr, BodyInfo bdInfo ) { SoftBodyInfo softInfo = (SoftBodyInfo)bdInfo; tr.localPosition = softInfo.center_; tr.localRotation = Quaternion.identity; tr.localScale = Vector3.one; GameObject go = tr.gameObject; Caronte_Fx_Body cfxBody = go.GetComponent<Caronte_Fx_Body>(); if (cfxBody != null && entityManager_.HasBodyMeshColliderRef(bdInfo.idBody_) ) { UnityEngine.Mesh meshCollider = entityManager_.GetBodyMeshColliderRef(bdInfo.idBody_); if (meshCollider != null) { meshCollider.vertices = softInfo.arrVerticesCollider_; meshCollider.RecalculateNormals(); meshCollider.RecalculateBounds(); } if (cfxBody.colliderMesh_ != meshCollider) { meshCollider.name = cfxBody.colliderMesh_.name; cfxBody.colliderMesh_ = meshCollider; } } Tuple2<UnityEngine.Mesh, MeshUpdater> meshRenderData = entityManager_.GetBodyMeshRenderUpdaterRef(bdInfo.idBody_); UnityEngine.Mesh meshToUpdate = meshRenderData.First; MeshUpdater meshUpdater = meshRenderData.Second; meshToUpdate.vertices = softInfo.arrVerticesRender_; mcForUpdates.Clear(); mcForUpdates.SetForUpdate(meshToUpdate); CaronteSharp.Tools.UpdateVertexNormalsAndTangents( meshUpdater, mcForUpdates ); meshToUpdate.normals = mcForUpdates.arrNormal_; meshToUpdate.tangents = mcForUpdates.arrTan_; meshToUpdate.RecalculateBounds(); }
public override void OnInspectorGUI() { base.DrawDefaultInspector(); MeshUpdater meshUpdater = (MeshUpdater)target; // Show the blender path if it is set if (meshUpdater.ModelsCurrentState >= UpdaterUtility.State.BlenderPathSet) { //Disable GUI so it can't be edited in UnityEditor GUI.enabled = false; EditorGUILayout.TextField("Blender Path: ", UpdaterUtility.PathToBlender); GUI.enabled = true; } // Button to select the blender.exe if (GUILayout.Button("Open Blender directory")) { // open the ProgramFiles directory of this system string blenderpath = EditorUtility.OpenFilePanel("Select blender.exe", Environment.GetEnvironmentVariable("ProgramFiles"), "exe"); // If the user did not select and exe then show dialog if (string.IsNullOrEmpty(blenderpath)) { EditorUtility.DisplayDialog("Select blender.exe", "You must select the blender.exe!", "OK"); } // Else update blender path else { UpdaterUtility.PathToBlender = blenderpath; meshUpdater.ModelsCurrentState = (UpdaterUtility.State)Mathf.Max((int)UpdaterUtility.State.BlenderPathSet, (int)meshUpdater.ModelsCurrentState); } } // Do not show Scan, Download and Create Prefab button if blender path is not set if (meshUpdater.ModelsCurrentState < UpdaterUtility.State.BlenderPathSet) { return; } if (GUILayout.Button("Scan")) { meshUpdater.Scan(); } // stop here if meshupdater did not scan yet if (meshUpdater.ModelsCurrentState < UpdaterUtility.State.Scanned) { return; } // ? THIS WON'T RESET WHEN DICTIONARY CLEARS ? var keys = new List <string>(meshUpdater.ModelChoiceDictionary.Keys); // show checkboxes for each model entry and update their values foreach (string modelEntryKey in keys) { meshUpdater.ModelChoiceDictionary[modelEntryKey] = EditorGUILayout.Toggle(modelEntryKey, meshUpdater.ModelChoiceDictionary[modelEntryKey]); } // downloads models and converts them to .fbx (models will also be imported into unity) if (GUILayout.Button("Download")) { meshUpdater.UpdateModels(); } // don't show "Create Prefab" before models are imported if (meshUpdater.ModelsCurrentState < UpdaterUtility.State.Downloaded) { return; } // create prefab if (GUILayout.Button("Create Prefab")) { meshUpdater.CreatePrefab(); } }