//instantiates a new mesh object prefab with all its scripts public void SpawnNewMesh() { //Debug.Log (clone); newgameSound.Play(); if (clone == null) { clone = (GameObject)Instantiate(Resources.Load("TexturePainter-Instances/Sphere"), SpawnPosition); clone.GetComponent <GenerateSphere> ().GenerateMesh(); UIref.assignedAllUI(); PMD.AssignedAllReference(); meshTrans = GameObject.FindGameObjectWithTag("Mesh").GetComponent <GetMeshTransform> (); meshTrans.AssignedMeshTrasformReference(); undoNredo.assignedReference(); dm.assignedUIObjects(); //Debug.Log ("spawned"); newGamePressed = true; } else { Destroy(clone); clone = (GameObject)Instantiate(Resources.Load("TexturePainter-Instances/Sphere"), SpawnPosition); clone.GetComponent <GenerateSphere> ().GenerateMesh(); UIref.assignedAllUI(); PMD.AssignedAllReference(); meshTrans = GameObject.FindGameObjectWithTag("Mesh").GetComponent <GetMeshTransform> (); meshTrans.AssignedMeshTrasformReference(); undoNredo.assignedReference(); dm.assignedUIObjects(); //Debug.Log ("Object already instantiated"); newGamePressed = true; } }
public void AssignedAllReference() { ClayMesh = null; ClayMesh = GameObject.FindGameObjectWithTag("Mesh"); texpaint = GameObject.FindGameObjectWithTag("TP").GetComponent <VRTexturePainter> (); MeshTransform = ClayMesh.GetComponent <GetMeshTransform> (); dm = GameObject.FindGameObjectWithTag("SM").GetComponent <VRSmooth>(); filter = ClayMesh.GetComponent <MeshFilter> (); //currentTool = Tools.Sculpt; point = rightController.GetComponent <VRTK_Pointer>(); }
// Update is called once per frame void FixedUpdate() { try{ if (newGamePressed) { if (meshTrans == null) { meshTrans = GameObject.FindGameObjectWithTag("Mesh").GetComponent <GetMeshTransform> (); meshTrans.AssignedMeshTrasformReference(); } } }catch (Exception ex) { if (ex is NullReferenceException || ex is UnassignedReferenceException) { return; } } }
// Update is called once per frame void FixedUpdate() { try{ RaycastHit tooltipRayCast; //tooltip to show the player where the buttons are located on the controller if (Physics.Raycast(Raypoint.position, Raypoint.forward, out tooltipRayCast, 100f)) { if (tooltipRayCast.collider.tag == "UI" && !tooltipUIIsActive) { //tooltip.touchpadText = "Touchpad"; tooltip.UpdateText(VRTK_ControllerTooltips.TooltipButtons.TouchpadTooltip, "Press Touchpad"); tooltip.UpdateText(VRTK_ControllerTooltips.TooltipButtons.TriggerTooltip, ""); if (tooltip == null) { tooltip = GameObject.FindGameObjectWithTag("tooltip").GetComponent <VRTK_ControllerTooltips> (); } //tooltip.triggerText = ""; tooltipUIIsActive = true; tooltipMESHsActive = false; //tooltip.touchpadText = "Touchpad"; //Debug.Log("tag is UI = " + tooltip.touchpadText); } else if (tooltipRayCast.collider.tag == "Mesh" && !tooltipMESHsActive && UIN.isActive) { tooltip.UpdateText(VRTK_ControllerTooltips.TooltipButtons.TriggerTooltip, "Press Trigger"); tooltip.UpdateText(VRTK_ControllerTooltips.TooltipButtons.TouchpadTooltip, ""); if (tooltip == null) { tooltip = GameObject.FindGameObjectWithTag("tooltip").GetComponent <VRTK_ControllerTooltips> (); } //tooltip.touchpadText = ""; tooltipMESHsActive = true; tooltipUIIsActive = false; //tooltip.triggerText = "Trigger"; //Debug.Log("tag is UI = " + tooltip.triggerText); //Debug.Log("tag is Mesh"); } else if (tooltipRayCast.collider.tag != "UI") { tooltip.UpdateText(VRTK_ControllerTooltips.TooltipButtons.TouchpadTooltip, ""); tooltipUIIsActive = false; } } //manages which tool is being used //using an enum switch (currentTool) { //if sculpt is pressed, this finds the collider with a mesh tag. and //gets the meshfilter so it can be modified. case Tools.Sculpt: try { hit = point.pointerRenderer.GetDestinationHit(); if (hit.transform.gameObject.tag != "Non-Modifiable") { //Debug.Log(hit.collider.name); filter = hit.collider.GetComponent <MeshFilter>(); if (filter) { if (filter != unappliedMesh) { ApplyMeshCollider(); unappliedMesh = filter; } //Mesh Symmetry. simple but it works Vector3 relativePoint = filter.transform.InverseTransformPoint(hit.point); Vector3 inversePoint = relativePoint; inversePoint.x = -relativePoint.x; if (isTriggerOn) { //Debug.Log("is trigger on? " + isTriggerOn); DeformMesh(filter.mesh, relativePoint, pull * Time.deltaTime, radius); if (MeshSymmetryToggle.isOn) { DeformMesh(filter.mesh, inversePoint, pull * Time.deltaTime, radius); } } } } } catch (System.NullReferenceException) { } break; case Tools.Scale: try{ if (MeshTransform == null) { MeshTransform = GameObject.FindGameObjectWithTag("Mesh").GetComponent <GetMeshTransform> (); } //Debug.Log("Scaling"); MeshTransform.Scale(); }catch (Exception ex) { if (ex is NullReferenceException || ex is UnassignedReferenceException) { return; } } break; case Tools.Rotate: try{ if (MeshTransform == null) { MeshTransform = GameObject.FindGameObjectWithTag("Mesh").GetComponent <GetMeshTransform> (); } //Debug.Log("Rotating"); MeshTransform.Rotate(); }catch (Exception ex) { if (ex is NullReferenceException || ex is UnassignedReferenceException) { return; } } break; case Tools.Crease: try { if (UIN == null) { UIN = GameObject.FindGameObjectWithTag("UINref").GetComponent <UINavigationSystem> (); } AddorSubtract.value = 1; pull = -UIN.CreaseStrength.value; radius = .03f; hit = point.pointerRenderer.GetDestinationHit(); if (hit.transform.gameObject.tag != "Non-Modifiable") { filter = hit.collider.GetComponent <MeshFilter>(); if (filter) { if (filter != unappliedMesh) { ApplyMeshCollider(); unappliedMesh = filter; } //Mesh Symmetry. simple but it works Vector3 relativePoint = filter.transform.InverseTransformPoint(hit.point); Vector3 inversePoint = relativePoint; inversePoint.x = -relativePoint.x; if (isTriggerOn) { //Debug.Log("trigger on"); DeformMesh(filter.mesh, relativePoint, pull * Time.deltaTime, radius); //filter.gameObject.GetComponent<MeshCollider> ().sharedMesh = filter.mesh; if (MeshSymmetryToggle.isOn) { radius = .03f; //Debug.Log(pull + " pull value"); DeformMesh(filter.mesh, inversePoint, pull * Time.deltaTime, radius); //filter.gameObject.GetComponent<MeshCollider> ().sharedMesh = filter.mesh; } } } } } catch (System.NullReferenceException) { } break; //get out case Tools.Grab: try{ if (MeshTransform == null) { MeshTransform = GameObject.FindGameObjectWithTag("Mesh").GetComponent <GetMeshTransform> (); } //if (GrabToggle.isOn) { MeshTransform.Grab(); //Debug.Log("Moving"); }catch (Exception ex) { if (ex is NullReferenceException || ex is UnassignedReferenceException) { return; } } break; case Tools.Symmetry: try{ //MeshSymmetryToggle.isOn = true; }catch (Exception ex) { if (ex is NullReferenceException || ex is UnassignedReferenceException) { return; } } break; case Tools.Smooth: //Debug.Log("Moving"); try{ isInSmoothPage = true; if (dm == null) { dm.ClayMesh = ClayMesh.GetComponent <MeshFilter>(); dm = GameObject.FindGameObjectWithTag("Mesh").GetComponent <VRSmooth> (); } }catch (Exception ex) { if (ex is NullReferenceException || ex is UnassignedReferenceException) { return; } } break; case Tools.Paint: //Debug.Log("paint ON"); try{ if (texpaint == null) { texpaint = GameObject.FindGameObjectWithTag("TP").GetComponent <VRTexturePainter> (); } texpaint.enabled = true; }catch (Exception ex) { if (ex is NullReferenceException || ex is UnassignedReferenceException) { return; } } break; } }catch (Exception ex) { if (ex is NullReferenceException || ex is UnassignedReferenceException) { return; } } }