Commit 1a91d359 authored by Gilles Foucault's avatar Gilles Foucault
Browse files

Merge branch 'Update-03-Juillet' of...

Merge branch 'Update-03-Juillet' of https://gricad-gitlab.univ-grenoble-alpes.fr/vision-r/projets/architool into Update-03-Juillet
parents 22bca6e2 9e478a2f
......@@ -7,7 +7,9 @@
"Unity.TextMeshPro",
"UnityEngine.SpatialTracking",
"PolyToolkit",
"Unity.Scripting.Python.Editor"
"Unity.Scripting.Python.Editor",
"SteamVR_Actions",
"SteamVR"
],
"includePlatforms": [],
"excludePlatforms": [],
......
using UnityEngine;
#if UNITY_EDITOR
using UnityEditor;
#endif
using System;
using UnityEngine.InputNew;
using UnityEditor.Experimental.EditorVR;
using UnityEditor.Experimental.EditorVR.Menus;
using UnityEditor.Experimental.EditorVR.Tools;
using UnityEditor.Experimental.EditorVR.Utilities;
using System.Reflection;
public class freeCADBase : MonoBehaviour, IUsesRayOrigin,
IConnectInterfaces,
IInstantiateUI,
ISelectTool,
IUsesMenuOrigins
{
private GameObject m_ToolMenu;
public Transform menuOrigin { get; set; }
public Transform alternateMenuOrigin { get; set; }
public Transform rayOrigin { get; set; }
private EditorWindow m_VRView = null;
private bool m_SendMouseEvent = true;
// Disable the selection tool to turn of the hover highlight. Not using
// IExclusiveMode because we still want locomotion.
private SelectionTool m_SelectionTool = null;
// Start is called before the first frame update
void Start()
{
m_SelectionTool = gameObject.GetComponent<SelectionTool>();
if (m_SelectionTool != null)
{
m_SelectionTool.enabled = false;
}
// In order to use some HandleUtility functions we'll need access to the OnSceneGUI delegate.
// This hooks up that event.
// @todo - Ask Unity team about making this less hack-y.
foreach (EditorWindow win in Resources.FindObjectsOfTypeAll<EditorWindow>())
{
if (win.GetType().ToString().Contains("VRView"))
{
m_VRView = win;
Type vrViewType = win.GetType();
EventInfo eventInfo = vrViewType.GetEvent("beforeOnGUI", BindingFlags.Public | BindingFlags.Static);
Delegate onGUIDelegate = Delegate.CreateDelegate(eventInfo.EventHandlerType,
this,
typeof(freeCADBase).GetMethod("OnGUIInternal", BindingFlags.Instance | BindingFlags.NonPublic));
eventInfo.AddEventHandler(this, onGUIDelegate);
}
}
}
void Update()
{
#if UNITY_EDITOR
// HACK - ripped from EditorVR pixelraycastmodule
if (m_SendMouseEvent && m_VRView != null)
{
EditorApplication.delayCall += () =>
{
if (this != null) // Because this is a delay call, the component will be null when EditorVR closes
{
m_VRView.SendEvent(new Event() { type = EventType.MouseMove });
}
};
m_SendMouseEvent = false; // Don't allow another one to queue until the current one is processed
}
#endif
}
private void OnDestroy()
{
foreach (EditorWindow win in Resources.FindObjectsOfTypeAll<EditorWindow>())
{
if (win.GetType().ToString().Contains("VRView"))
{
Type vrViewType = win.GetType();
EventInfo eventInfo = vrViewType.GetEvent("beforeOnGUI", BindingFlags.Public | BindingFlags.Static);
Delegate onGUIDelegate = Delegate.CreateDelegate(eventInfo.EventHandlerType,
this,
typeof(freeCADBase).GetMethod("OnGUIInternal", BindingFlags.Instance | BindingFlags.NonPublic));
eventInfo.RemoveEventHandler(this, onGUIDelegate);
}
}
if (m_SelectionTool != null)
m_SelectionTool.enabled = true;
if (m_ToolMenu != null)
{
ObjectUtils.Destroy(m_ToolMenu);
/*UICube.uiCube.dimX = 0;
UICube.uiCube.dimY = 0;
UICube.uiCube.dimZ = 0;*/
}
}
}
using UnityEngine;
#if UNITY_EDITOR
using UnityEditor;
#endif
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using UnityEngine.InputNew;
using UnityEditor.Experimental.EditorVR;
using UnityEditor.Experimental.EditorVR.Utilities;
using UnityEditor.Experimental.EditorVR.Proxies;
using ProBuilder2.Common;
using UnityEditor.Scripting.Python;
namespace ProBuilder2.VR
{
/**
* resize object their normal.
*/
//change name test --> TranslateElementTool
[MainMenuItem("Activate Children", "FreeCAD", "Resize object after op.Boolean.")]
public class AcivateChildren : ProBuilderToolBase,
ITool,
IProcessInput,
IStandardActionMap,
IUsesRaycastResults,
ISetHighlight,
IRayVisibilitySettings,
IUsesRayOrigin
{
[SerializeField] private AudioClip m_Drag;
[SerializeField] private AudioClip m_Trigger;
enum CreateState
{
Start,
Finish
}
#pragma warning disable 414
private ActionMap m_StandardActionMap;
#pragma warning restore 414
public Color32 highlightFaceColor = new Color32(0, 188, 212, 96);
public Color32 directSelectFaceColor = new Color32(212, 0, 171, 96);
private HighlightElementsModule m_HighlightModule = null;
private VRAudioModule m_AudioModule = null;
private HeightGuideModule m_GuideModule = null;
private float m_DirectSelectThreshold = .1f;
private Vector3 m_DragOrigin = Vector3.zero;
private pb_Object m_Object;
private pb_Face m_Face;
private Vector3 pointSelect;
public ActionMap standardActionMap
{
set
{
m_StandardActionMap = value;
}
}
public override void pb_Start()
{
m_HighlightModule = ObjectUtils.CreateGameObjectWithComponent<HighlightElementsModule>();
m_GuideModule = ObjectUtils.CreateGameObjectWithComponent<HeightGuideModule>();
m_AudioModule = ObjectUtils.CreateGameObjectWithComponent<VRAudioModule>();
m_GuideModule.SetVisible(false);
try { m_DirectSelectThreshold = Mathf.Max(m_DirectSelectThreshold, rayOrigin.GetComponentInChildren<DefaultProxyRay>().pointerLength * 1.3f); } catch { }
}
public override void pb_OnDestroy()
{
if (m_HighlightModule != null) ObjectUtils.Destroy(m_HighlightModule.gameObject);
if (m_AudioModule != null) ObjectUtils.Destroy(m_AudioModule.gameObject);
if (m_GuideModule != null) ObjectUtils.Destroy(m_GuideModule.gameObject);
}
public void ProcessInput(ActionMapInput input, ConsumeControlDelegate consumeControl)
{
var standardInput = (Standard)input;
consumeControl(standardInput.action);
GameObject first = this.GetFirstGameObject(rayOrigin);
if (first == null)
{
if (m_HighlightModule != null)
m_HighlightModule.Clear();
return;
}
if (first.name.Contains("Box")|| first.name.Contains("Cylinder")|| first.name.Contains("Sphere")||first.name.Contains("Cut") || first.name.Contains("Fusion") || first.name.Contains("Intersection"))
{
pb_Object pb = first.GetComponent<pb_Object>();
pb_RaycastHit hit;
if (pb_HandleUtility.FaceRaycast(new Ray(rayOrigin.position, rayOrigin.forward), pb, out hit))
{
m_DragOrigin = pb.transform.TransformPoint(hit.point);
if (standardInput.action.wasJustReleased)
{
pointSelect = m_DragOrigin;
Debug.Log("point select : " + pointSelect);
if (first.name.Contains("Cut")|| first.name.Contains("Fusion")|| first.name.Contains("Intersection"))
{
//Dummy argument to FreeCAD
string nameObj = first.name;
float posX = pointSelect.x;
float posY = pointSelect.y;
float posZ = pointSelect.z;
string scriptPath = Application.dataPath + "/python/ActivateObjectEnfant.py";
PythonRunner.RunFile(scriptPath, nameObj + " " + posX + " " + posY + " " + posZ);
//Destroy(first.GetComponent<pb_Object>());
//Destroy(first.GetComponent<pb_Entity>());
}
}
}
}
}
}
}
fileFormatVersion: 2
guid: 307048b0143377442915604954e5af0f
guid: 95d841172542d414791175d7e1a1f072
MonoImporter:
externalObjects: {}
serializedVersion: 2
......
using UnityEngine;
#if UNITY_EDITOR
using UnityEditor;
#endif
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using UnityEngine.InputNew;
using UnityEditor.Experimental.EditorVR;
using UnityEditor.Experimental.EditorVR.Utilities;
using UnityEditor.Experimental.EditorVR.Proxies;
using ProBuilder2.Common;
using UnityEditor.Scripting.Python;
using UnityEditor.Experimental.EditorVR.Modules;
namespace ProBuilder2.VR
{
/**
* resize object their normal.
*/
//change name test --> TranslateElementTool
[MainMenuItem("Intersection Object ", "FreeCAD", "Intersection 2 objects.")]
public class IntersectionObject : ProBuilderToolBase,
ITool,
IProcessInput,
IStandardActionMap,
IUsesRaycastResults,
ISetHighlight,
IRayVisibilitySettings,
IUsesRayOrigin
{
[SerializeField] private AudioClip m_Drag;
[SerializeField] private AudioClip m_Trigger;
enum CreateState
{
Start,
Finish
}
#pragma warning disable 414
private ActionMap m_StandardActionMap;
#pragma warning restore 414
public Color32 highlightFaceColor = new Color32(0, 188, 212, 96);
public Color32 directSelectFaceColor = new Color32(212, 0, 171, 96);
private HighlightElementsModule m_HighlightModule = null;
private VRAudioModule m_AudioModule = null;
private HeightGuideModule m_GuideModule = null;
const float MAX_TRANSLATE_DISTANCE = 100f;
private static readonly Vector3 VECTOR3_ONE = Vector3.one;
private float m_SnapIncrement = Snapping.DEFAULT_INCREMENT;
private float m_DirectSelectThreshold = .1f;
private CreateState m_State = CreateState.Start;
private bool m_Dragging = false;
private bool m_IsDirectSelect = false;
private Vector3 m_DragOrigin = Vector3.zero;
private Vector3 m_DragDirection = Vector3.zero;
private Vector3 m_Offset = Vector3.zero;
private Vector3 m_DraggedPoint = Vector3.zero;
private Vector3 vertexTranslation;
private GameObject[] m_ProBuilderObjectsInScene = null;
private Vector3 m_PreviousVertexTranslation = Vector3.zero;
private VertexSnap m_VertexSnap = new VertexSnap(false, Vector3.zero);
private pb_Object m_Object;
private pb_Face m_Face;
private Vector3 pointSelect;
private IEnumerable<int> m_SelectedIndices;
private Vector3[] m_Positions;
private Vector3[] m_SettingPositions;
private int idFace;
public ActionMap standardActionMap
{
set
{
m_StandardActionMap = value;
}
}
public override void pb_Start()
{
m_HighlightModule = ObjectUtils.CreateGameObjectWithComponent<HighlightElementsModule>();
m_GuideModule = ObjectUtils.CreateGameObjectWithComponent<HeightGuideModule>();
m_AudioModule = ObjectUtils.CreateGameObjectWithComponent<VRAudioModule>();
m_GuideModule.SetVisible(false);
try { m_DirectSelectThreshold = Mathf.Max(m_DirectSelectThreshold, rayOrigin.GetComponentInChildren<DefaultProxyRay>().pointerLength * 1.3f); } catch { }
if (GetObject.getObj.objChoices.Count >= 2)
{
GameObject A = GetObject.getObj.objChoices[GetObject.getObj.objChoices.Count - 2];
Debug.Log("obj 2: " + A.name);
GameObject B = GetObject.getObj.objChoices[GetObject.getObj.objChoices.Count - 1];
Debug.Log("obj 1: " + B.name);
//addSpatialToObject.addSpatial.objectModificable(A);
string nameA = A.name;
string nameB = B.name;
string scriptPath = Application.dataPath + "/python/Intersection.py";
PythonRunner.RunFile(scriptPath, nameA + " " + nameB);
}
}
public override void pb_OnDestroy()
{
if (m_HighlightModule != null) ObjectUtils.Destroy(m_HighlightModule.gameObject);
if (m_AudioModule != null) ObjectUtils.Destroy(m_AudioModule.gameObject);
if (m_GuideModule != null) ObjectUtils.Destroy(m_GuideModule.gameObject);
}
public void ProcessInput(ActionMapInput input, ConsumeControlDelegate consumeControl)
{
}
}
}
fileFormatVersion: 2
guid: 211e05b5bab77d84381730417e21a318
guid: d68bcd3c46ac9e74c833989de955f4ec
MonoImporter:
externalObjects: {}
serializedVersion: 2
......
using UnityEngine;
#if UNITY_EDITOR
using UnityEditor;
#endif
using System;
using System.Linq;
using System.Collections;
using UnityEngine.InputNew;
using UnityEditor.Experimental.EditorVR;
using UnityEditor.Experimental.EditorVR.Utilities;
using UnityEditor.Experimental.EditorVR.Proxies;
using UnityEditor.Scripting.Python;
using UnityEditor.Experimental.EditorVR.Modules;
[MainMenuItem("subtract Elements", "FreeCAD", "Translate selected mesh elements.")]
public class SubtractFreeCAD : MonoBehaviour, ITool, IConnectInterfaces, IInstantiateMenuUI,
IUsesRayOrigin, IUsesSpatialHash, IUsesViewerScale, ISelectTool, IIsHoveringOverUI, IIsMainMenuVisible,
IRayVisibilitySettings, IRequestFeedback, IUsesNode
{
[SerializeField]
ActionMap m_ActionMap;
// Start is called before the first frame update
void Start()
{
if (GetObject.getObj.objChoices.Count >= 2)
{
GameObject A = GetObject.getObj.objChoices[GetObject.getObj.objChoices.Count - 2];
Debug.Log("obj 2: " + A.name);
GameObject B = GetObject.getObj.objChoices[GetObject.getObj.objChoices.Count - 1];
Debug.Log("obj 1: " + B.name);
//addSpatialToObject.addSpatial.objectModificable(A);
string nameA = A.name;
string nameB = B.name;
string scriptPath = Application.dataPath + "/python/Substract.py";
PythonRunner.RunFile(scriptPath, nameA + " " + nameB);
}
}
public ActionMap actionMap { get { return m_ActionMap; } }
public Transform cameraRig { private get; set; }
public Node node { private get; set; }
public Transform rayOrigin { get; set; }
// Update is called once per frame
void Update()
{
}
}
using UnityEngine;
#if UNITY_EDITOR
using UnityEditor;
#endif
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using UnityEngine.InputNew;
using UnityEditor.Experimental.EditorVR;
using UnityEditor.Experimental.EditorVR.Utilities;
using UnityEditor.Experimental.EditorVR.Proxies;
using ProBuilder2.Common;
using UnityEditor.Scripting.Python;
using UnityEditor.Experimental.EditorVR.Modules;
namespace ProBuilder2.VR
{
/**
* resize object their normal.
*/
//change name test --> TranslateElementTool
[MainMenuItem("Subtract Object ", "FreeCAD", "Subtract 2 objects.")]
public class SubtractObject : ProBuilderToolBase,
ITool,
IProcessInput,
IStandardActionMap,
IUsesRaycastResults,
ISetHighlight,
IRayVisibilitySettings,
IUsesRayOrigin
{
enum CreateState
{
Start,
Finish
}
#pragma warning disable 414
private ActionMap m_StandardActionMap;
#pragma warning restore 414
public Color32 highlightFaceColor = new Color32(0, 188, 212, 96);
public Color32 directSelectFaceColor = new Color32(212, 0, 171, 96);
private HighlightElementsModule m_HighlightModule = null;
private VRAudioModule m_AudioModule = null;
private HeightGuideModule m_GuideModule = null;
const float MAX_TRANSLATE_DISTANCE = 100f;
private static readonly Vector3 VECTOR3_ONE = Vector3.one;
private float m_SnapIncrement = Snapping.DEFAULT_INCREMENT;
private float m_DirectSelectThreshold = .1f;
public ActionMap standardActionMap
{
set
{
m_StandardActionMap = value;
}
}
public override void pb_Start()
{
m_HighlightModule = ObjectUtils.CreateGameObjectWithComponent<HighlightElementsModule>();
m_GuideModule = ObjectUtils.CreateGameObjectWithComponent<HeightGuideModule>();
m_AudioModule = ObjectUtils.CreateGameObjectWithComponent<VRAudioModule>();
m_GuideModule.SetVisible(false);
try { m_DirectSelectThreshold = Mathf.Max(m_DirectSelectThreshold, rayOrigin.GetComponentInChildren<DefaultProxyRay>().pointerLength * 1.3f); } catch { }
if (GetObject.getObj.objChoices.Count >= 2)
{
GameObject A = GetObject.getObj.objChoices[GetObject.getObj.objChoices.Count - 2];
Debug.Log("obj 2: " + A.name);
GameObject B = GetObject.getObj.objChoices[GetObject.getObj.objChoices.Count - 1];
Debug.Log("obj 1: " + B.name);
//addSpatialToObject.addSpatial.objectModificable(A);
string nameA = A.name;
string nameB = B.name;
string scriptPath = Application.dataPath + "/python/Subtract.py";
PythonRunner.RunFile(scriptPath, nameA + " " + nameB);
}
}
public override void pb_OnDestroy()
{
if (m_HighlightModule != null) ObjectUtils.Destroy(m_HighlightModule.gameObject);
if (m_AudioModule != null) ObjectUtils.Destroy(m_AudioModule.gameObject);
if (m_GuideModule != null) ObjectUtils.Destroy(m_GuideModule.gameObject);
}
public void ProcessInput(ActionMapInput input, ConsumeControlDelegate consumeControl)
{
}
}
}