void Paint() { if (!paintOn && !ray.busy) { //make a global paint holder for all created objects if (paintGlobal == null) { paintGlobal = new GameObject("Paint_Global"); } //instantiate paint and parent to paintGlobal object curPaint = (GameObject)Instantiate(activeBrush, paintBrushHolder.transform.position, paintBrushHolder.rotation); curPaint.transform.parent = paintGlobal.transform; //get the extrusion target and parent it to controller extrusionTarget = curPaint.transform.GetChild(1); // extrusionTarget.transform.parent = paintBrushHolder.transform; //(this now has been moved in the Update for doing freezongPos) //turn mesh extrusion on extrudeMesh = curPaint.transform.GetChild(0).GetComponent <ExtrudeMesh>(); extrudeMesh.time = Mathf.Infinity; //caps if (paintPallete.buildCaps) { curPaint.transform.GetChild(0).GetComponent <ExtrudeMesh>().buildCaps = true; } //assign size curPaint.transform.localScale = new Vector3(SizeX, SizeY, SizeZ); //assign material curPaint.transform.GetChild(0).GetComponent <Renderer>().material = material; //assign color curPaint.transform.GetChild(0).GetComponent <Renderer>().material.color = color; //assign density extrudeMesh.minDistance = paintDensity;//(this now has been moved in the Update for straight line) //make extrusion target rotate if 'rotateBrush' is On if (rotateBrush) { extrusionTarget.GetComponent <Rotate>().enabled = true; } //test freezing pos and rot - initital transforms initialPaintContactPos = paintBrushHolder.transform.position; // print(paintBrushHolder.transform.position); paintOn = true; //network extended---------------------- onBrushStrokeStart.Invoke(); //OnBrushEnd(); } }
public void Generate() { MeshBuilder baseMesh1 = new MeshBuilder(); QuadMesh.Create(baseMesh1, Vector3.right * baseSize.x, Vector3.forward * baseSize.y); baseMesh1 = ExtrudeMesh.From(baseMesh1, Vector3.up * height1).Join(baseMesh1); MeshBuilder circleMesh = CircleMesh.Create(height2, 0f, 180f, -Vector3.forward, Vector3.up). Translate(Vector3.up * height1 + Vector3.forward * 0.5f * baseSize.y); circleMesh = ExtrudeMesh.From(circleMesh, Vector3.right * baseSize.x).Join(circleMesh); MeshFilter filter = gameObject.GetComponent <MeshFilter>(); Mesh mesh = MeshBuilder.Join(baseMesh1, circleMesh).CreateMesh(); mesh.RecalculateBounds(); filter.mesh = mesh; }
// Update is called once per frame void Update() { if (controller.GetPressDown(Valve.VR.EVRButtonId.k_EButton_Grip)) { Disable(); } if (controller.GetPressDown(SteamVR_Controller.ButtonMask.ApplicationMenu)) { snappingEnabled = !snappingEnabled; if (currentProjector) { if (snappingEnabled) { currentProjector.SendMessage("TrunOnCanny"); } else { currentProjector.SendMessage("TrunOffCanny"); } } } if (snappingEnabled) { snapPoint = GetComponent <CubeSnap>().pointer2.position; } localDeltaEuler = transform.localEulerAngles - lastLocalEuler; lastLocalEuler = transform.localEulerAngles; if (getRayfromCamera) { ray = Camera.main.ScreenPointToRay(Input.mousePosition); } else { ray = new Ray(rayPointer.transform.position, rayPointer.transform.forward); } Debug.DrawRay(ray.origin, ray.direction * 10, Color.yellow); RaycastHit hit; if (Physics.Raycast(ray, out hit)) { linePositions[0] = rayPointer.position; if (snappingEnabled) { snapPoint = GetComponent <CubeSnap>().pointer2.position; } else { snapPoint = hit.point; } linePositions[1] = snapPoint; line.SetColors(hitColor, hitColor); if (shouldPlace) { if (Input.GetMouseButtonDown(0) || controller.GetPressDown(SteamVR_Controller.ButtonMask.Trigger)) { GameObject obj = Instantiate(meshPrefab, snapPoint, meshPrefab.transform.rotation) as GameObject; activeMesh = obj.GetComponent <ExtrudeMesh>(); activeMesh.StartDrawing(this.gameObject); activeMesh.trackedObj = trackedObj; shouldPlace = false; } } } else { linePositions[0] = rayPointer.position; linePositions[1] = rayPointer.position + ray.direction * 30; line.SetColors(emptyColor, emptyColor); } line.SetPositions(linePositions); if (activeMesh) { activeMesh.getRayfromCamera = getRayfromCamera; activeMesh.ray = ray; if (controller.GetAxis(Valve.VR.EVRButtonId.k_EButton_SteamVR_Touchpad).magnitude > 0.0001f && lastPad.magnitude > 0.0001f) { activeMesh.viveAxis = controller.GetAxis(Valve.VR.EVRButtonId.k_EButton_SteamVR_Touchpad) - lastPad; } if ((controller.GetAxis(Valve.VR.EVRButtonId.k_EButton_SteamVR_Touchpad) - lastPad).magnitude < 0.0001f) { activeMesh.viveAxis = new Vector2(0, 0); } lastPad = controller.GetAxis(Valve.VR.EVRButtonId.k_EButton_SteamVR_Touchpad); //(new Vector2(Mathf.Tan(-Mathf.Deg2Rad*localDeltaEuler.y), Mathf.Tan(-Mathf.Deg2Rad * localDeltaEuler.x)))*6f; } }
// Use this for initialization void Start() { GetComponent <MeshCollider>().sharedMesh = ExtrudeMesh.Create2SidedColliderMesh(GetComponent <MeshFilter>().sharedMesh); }