-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExtrudeMeshApp1.cs
126 lines (101 loc) · 4 KB
/
ExtrudeMeshApp1.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using SubsurfaceStudios.MeshOperations;
using UnityEngine;
using UnityEngine.ProBuilder;
using UnityEngine.ProBuilder.MeshOperations;
using UnityEngine.ProBuilder.Shapes;
public class ExtrudeMeshApp1 : MonoBehaviour
{
//[SerializeField] ProBuilderMesh proBuilderMesh;
[SerializeField] Material material;
[SerializeField] Material material2;
[SerializeField] Color color;
[SerializeField] ProBuilderMesh cube;
private Color vertexColor = Color.red;
ProBuilderMesh cube2;
[SerializeField] Camera camera2;
[SerializeField] Rect rect;
Vector3 mousePositionInWorld;
[SerializeField] Color color5;
Face faceToExtrude;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
/*if (Input.GetKeyDown(KeyCode.A))
{*/
//SetTheColor();
MousePosition();
if (Input.GetKeyDown(KeyCode.E))
{
}
/* // List<Edge> newList = new List<Edge>();
//Edge edge = new Edge(1,2);
Vector3 size = new Vector3(1f, 1f, 1f);
cube = ShapeGenerator.GenerateCube(PivotLocation.Center, size);
Face face = new Face(new List<int>() { 0, 1, 2, 3, 4, 5 });
cube.SetMaterial(cube.faces,material);
cube.SetFaceColor(face, material2.color);
// IList<Face> faces = cube.faces;
// newList.Add(edge);
//Material selectedMaterial = new Material(material);
Debug.Log("SetColor");
//proBuilderMesh.SetSelectedEdges(new List<Edge>() {edge});
//proBuilderMesh.SetMaterial(proBuilderMesh.faces,selectedMaterial);
//Bevel.BevelEdges(proBuilderMesh,);
// cube.ToMesh();
cube.Refresh();
// ExtrudeElements.Extrude(proBuilderMesh, proBuilderMesh.faces, ExtrudeMethod.IndividualFaces, 1);*/
}
/*void SetTheColor()
{
color5 = Color.red;
//cube.SetFaceColor(cube.faces[1], color5);
Vector3 size = new Vector3(1f, 1f, 1f);
if (cube2 == null)
{
cube2 = ShapeGenerator.GenerateCube(PivotLocation.Center, size);
cube2.ExtrudeFaces(ExtrudeMethod.IndividualFaces, 1, 1);
}
cube2.SetMaterial(cube2.faces, material);
Color color6 = Color.yellow;
for (int i = 0; i < 2; i++)
{
cube2.SetFaceColor(cube2.faces[i], color6);
}
//cube2.Extrude(cube2.faces, ExtrudeMethod.IndividualFaces, 1);
}*/
void MousePosition()
{
// Check if the left mouse button is pressed
if (Input.GetMouseButtonDown(0))
{
// Get the mouse position in screen coordinates
Vector3 mousePosition = Input.mousePosition;
// Create a ray from the camera through the mouse position
Ray ray = Camera.main.ScreenPointToRay(mousePosition);
// Declare a variable to store the hit information
RaycastHit hit;
Debug.Log("HI");
// Check if the ray hits something in the 3D world
if (Physics.Raycast(ray, out hit))
{
// Get the hit point in 3D world coordinates
mousePositionInWorld = hit.point;
// Now, mousePositionInWorld contains the position of the mouse in Vector3 format
Debug.Log("Mouse Position in World: " + mousePositionInWorld);
// Face faceToExtrude = SelectionPicker.PickFace(camera2, mousePositionInWorld, cube2);
faceToExtrude = SelectionPicker.PickFace(camera2, mousePosition, cube);
cube.SetFaceColor(faceToExtrude, color5);
Debug.Log("Face change color");
cube.ToMesh(MeshTopology.Quads);
cube.Refresh();
}
}
}
}