public MeshBuilder Create() { CylinderMesh cylinder = new CylinderMesh(); cylinder.radius = radius; cylinder.direction1 = new Vector3(1f, 0f, 0f); cylinder.direction2 = new Vector3(0f, 0f, 1f); cylinder.totalPerimeterVertices = 30; cylinder.height = 0.4f * height; MeshBuilder meshBuilder = cylinder.Create(); meshBuilder.Translate(0.2f * height * Vector3.up); cylinder.radius = 0.7f * radius; cylinder.height = 0.2f * height; meshBuilder = cylinder.Create() .Translate(0.5f * height * Vector3.up) .Join(meshBuilder); ConeMesh cone = new ConeMesh(); cone.radius = 0.9f * radius; cone.height = 0.4f * height; cone.totalVerticalSegments = 5; MeshBuilder coneMeshBuilder = cone.Create() .Translate((height - 0.5f * cone.height) * Vector3.up); meshBuilder = meshBuilder.Join(coneMeshBuilder); return(meshBuilder); }
// Use this for initialization void Start() { MyMesh = (MyMesh)FindObjectOfType(typeof(MyMesh)); cMesh = (CylinderMesh)FindObjectOfType(typeof(CylinderMesh)); Vertex = MyMesh.mSelected; MainController = (MainController)FindObjectOfType(typeof(MainController)); }
//public int animationTrackIndex = 0; //public readonly SyncList<ACMngr> trackedFields; protected override void OnAttach() { base.OnAttach(); Slot visual = Slot.AddSlot("Visual"); visual.LocalRotation = floatQ.Euler(90f, 0f, 0f); visual.LocalPosition = new float3(0, 0, 0); PBS_Metallic material = visual.AttachComponent <PBS_Metallic>(); visual.AttachComponent <SphereCollider>().Radius.Value = 0.025f; ValueMultiplexer <color> vm = visual.AttachComponent <ValueMultiplexer <color> >(); vm.Target.Target = material.EmissiveColor; vm.Values.Add(new color(0, 0.5f, 0, 1)); vm.Values.Add(new color(0.5f, 0, 0, 1)); vm.Values.Add(new color(0.5f, 0.5f, 0, 1)); vm.Values.Add(new color(0, 0, 0.5f, 1)); vm.Index.DriveFrom <int>(state); CylinderMesh mesh = visual.AttachMesh <CylinderMesh>(material); mesh.Radius.Value = 0.015f; mesh.Height.Value = 0.05f; }
float unitRadius = 1f; // radius = 1m private void Awake() { // initialize me // check if the global component object is defined if (m_boidInstanceMaterial == null) { Debug.LogError("The global Variable _boidInstanceMaterial is not defined in Inspector"); // EditorApplication.Exit(0); return; } m_instanceMeshCircle = new CircleMesh(unitRadius); m_instanceMeshCylinder = new CylinderMesh(height, radius, nbSides, nbHeightSeg); m_boidArgsBuffer = new ComputeBuffer( 1, // count m_boidArgs.Length * sizeof(uint), ComputeBufferType.IndirectArguments ); if (m_useCircleMesh) // use 2D boids => creat the mesh in a script { m_boidInstanceMesh = m_instanceMeshCircle.m_mesh; } else { m_boidInstanceMesh = m_instanceMeshCylinder.m_mesh; } // else { // Debug.LogError("useCircleMesh or useSphereMesh should be checked"); // //If we are running in a standalone build of the game // #if UNITY_STANDALONE // //Quit the application // Application.Quit(); // #endif // //If we are running in the editor // #if UNITY_EDITOR // //Stop playing the scene // // UnityEditor.EditorApplication.isPlaying = false; // //Setting isPlaying delays the result until after all script code has completed for this frame. // EditorApplication.Exit(0); // #endif // } //Debug.Log("number of indices="); //Debug.Log(_instanceMesh.GetIndexCount(0)); }
public static void DrawLine(Vector3 start, Vector3 end, float thickness) { Mesh mesh = CreateOrRecycleMesh(); CylinderMesh.GenerateMesh(mesh); Vector3 centre = (start + end) / 2; var rot = Quaternion.FromToRotation(Vector3.up, (start - end).normalized); Vector3 scale = new Vector3(thickness * lineThicknessFactor, (start - end).magnitude, thickness * lineThicknessFactor); CreateVisualElement(mesh, centre, rot, scale); }
public static void DrawLine(Vector3 start, Vector3 end, float thickness, Color colour, Style style = Style.Standard) { Init(); float thicknessFactor = 1 / 25f; Mesh mesh = CreateOrRecycleMesh(); CylinderMesh.GenerateMesh(mesh); Vector3 centre = (start + end) / 2; var rot = Quaternion.FromToRotation(Vector3.up, (start - end).normalized); Vector3 scale = new Vector3(thickness * thicknessFactor, (start - end).magnitude, thickness * thicknessFactor); drawList.Add(new DrawInfo(mesh, centre, rot, scale, colour, style)); }
static void Init() { if (sphereMesh == null) { inactiveMeshes = new Queue <Mesh> (); materialProperties = new MaterialPropertyBlock(); drawList = new List <VisualElement> (); // Generate and cache primitive meshes sphereMesh = new Mesh(); cylinderMesh = new Mesh(); MeshGeneration.SphereMesh.GenerateMesh(sphereMesh); CylinderMesh.GenerateMesh(cylinderMesh); // Create materials materials = new Material[shaderPaths.Length]; for (int i = 0; i < materials.Length; i++) { materials[i] = new Material(Shader.Find(shaderPaths[i])); } } // New frame index, so clear out last frame's draw list if (lastFrameInputReceived != Time.frameCount) { lastFrameInputReceived = Time.frameCount; // Store all unique meshes in inactive queue to be recycled var usedMeshes = new HashSet <Mesh> (); // Don't recycle cached meshes usedMeshes.Add(sphereMesh); usedMeshes.Add(cylinderMesh); for (int i = 0; i < drawList.Count; i++) { if (!usedMeshes.Contains(drawList[i].mesh)) { usedMeshes.Add(drawList[i].mesh); inactiveMeshes.Enqueue(drawList[i].mesh); } } // Clear old draw list drawList.Clear(); } }
private Godot.Mesh CreateCylinder( Link.Geometry.Cylinder cyl, SpatialMaterial mat = null) { CylinderMesh temp = new CylinderMesh(); if (mat != null) { temp.Material = mat; } temp.RadialSegments = 16; temp.TopRadius = (float)cyl.radius; temp.BottomRadius = (float)cyl.radius; temp.Height = (float)cyl.length; return(temp); }
public void CreateTree() { if (DepthRemaining <= 0) { CreateLeaf(); return; } Rotate(Transform.basis.y, (float)GD.RandRange(0, 2 * Mathf.Pi)); CylinderMesh mesh = new CylinderMesh(); mesh.TopRadius = CrossSectionalRadius; mesh.BottomRadius = CrossSectionalRadius; mesh.RadialSegments = 8; mesh.Rings = 1; float length = (float)GD.RandRange(MinLength, MaxLength); mesh.Height = length; MeshInstance meshInstance = new MeshInstance(); meshInstance.Mesh = mesh; meshInstance.Translate(Transform.basis.y * length / 2); meshInstance.SetSurfaceMaterial(0, BranchMaterial); AddChild(meshInstance); // Main Branch AddBranch(1, length, 0.9f, 0, Mathf.Deg2Rad(MainMaxOffsetDegrees)); float subOffsetDegrees = Mathf.Deg2Rad(SubMaxOffsetDegrees); // Sub Branches if (GD.RandRange(0, 1) > 0.5) { AddBranch(1, length, 0.7f, subOffsetDegrees / 2, subOffsetDegrees); } else { AddBranch(1, length, 0.7f, subOffsetDegrees / 2, subOffsetDegrees); //AddBranch(2, length, 0.7f, subOffsetDegrees / 2, subOffsetDegrees); } }
public static GameObject CreateMesh(GeometryType type, bool receiveShadow = true, bool castShadow = true, bool collider = true) { Mesh mesh = null; if (type == GeometryType.Cube) { mesh = new CubeMesh(); } else if (type == GeometryType.Sphere) { mesh = new SphereMesh(1, 64); } else { mesh = new CylinderMesh(); } var gameObject = new GameObject($"Mesh_{type}"); var renderer = gameObject.AddComponent <MeshRenderer>(); renderer.Mesh = mesh; renderer.ReceiveShadow = receiveShadow; renderer.CastShadow = castShadow; if (collider) { gameObject.AddComponent <BoxCollider>(); } if (mesh != null && !mesh.Built) { mesh.Build(); } return(gameObject); }