void Start() { //Create a new Cubesphere in code. m_planet = new CubeSphere("Planet", gameObject.transform, planetRadius, resolution, material); m_planet.InitialiseCubeSphere(); m_planet.GetProperties().AddNoiseOctave(2.0f, 0.5f, 50.0f, 2.0f, 1.0f, 2.0f); m_planet.GetProperties().AddNoiseOctave(2.0f, 0.5f, 50.0f, 2.0f, 1.0f, 2.0f); m_planet.GetProperties().AddNoiseOctave(2.0f, 0.25f, 50.0f, 2.0f, 1.0f, 2.0f); m_planet.GenerateMesh(); }
/// <summary> /// for a given object return the location where it should be inserted. /// where the object is inserted is determined by its bounding sphere. /// * if the sphere is bigger than the object or does not intersect -> dont insert /// * if it is bigger than half the size -> insert into own list /// * if it is smaller than that -> insert into a child node /// </summary> private ObjectLocation GetLocation(I3DObject obj) { var boundingSphere = obj.GetBoundingSphere(); if (boundingSphere.Radius > _halfWidth || !CubeSphere.IsSphereIntersectingCube(_center, _halfWidth, boundingSphere)) { return(ObjectLocation.None); } if (boundingSphere.Radius < _halfWidth / 2) { return(ObjectLocation.Child); } return(ObjectLocation.Self); }
public override void OnInspectorGUI() { DrawDefaultInspector(); CubeSphere script = (CubeSphere)target; if (GUI.changed) { script.Generate(); } if (GUILayout.Button("Generate Sphere")) { script.Generate(); } }
public void GeneratePlanet() { ColorVertexes cv = GetComponent <ColorVertexes>(); cv.DirtLevel = terrainRadius - 3; cv.GrassLevel = terrainRadius + 1; cv.RockLevel = terrainRadius + 4; cv.SnowLevel = terrainRadius + 7; CubeSphere cs = GetComponent <CubeSphere>(); cs.radius = terrainRadius; cs.gridSize = detailLevel; cs.Build(); MeshDeformation md = GetComponent <MeshDeformation>(); md.Build(); GetComponent <GenerateTerrain>().GenTerrain(); //water transform.GetChild(0).localScale = new Vector3(terrainRadius * 2, terrainRadius * 2, terrainRadius * 2); transform.GetChild(0).gameObject.SetActive(true); //atmos transform.GetChild(1).localScale = new Vector3((terrainRadius + atmosphereRadius) * 2, (terrainRadius + atmosphereRadius) * 2, (terrainRadius + atmosphereRadius) * 2); transform.GetChild(1).gameObject.SetActive(true); //clouds //ParticleSystem.ShapeModule shapeModule = transform.GetChild(2).GetComponent<ParticleSystem>().shape; //shapeModule.radius = atmosphereRadius + terrainRadius; //ParticleSystem.MainModule mainMondule = transform.GetChild(2).GetComponent<ParticleSystem>().main; //mainMondule.maxParticles = (int)atmosphereRadius * 2; //objects GetComponent <PlanetObjectsHandler>().Build(); }
public void OnEnable() { _this = (CubeSphere)target; }
public void OnValidate() { vertices = CubeSphere.CreateCubeSphere(radius, quadCount); }
/** * Inserts an object into the subtree. The actual algorithms for building the tree are specified by TreeInsertStrategy. * * @param o the object to be added. * @param s the bounding sphere of the object - precomputed for memory and performance reasons * @return false if the object does not intersect/or is not enclosed by this subtree, true otherwise. */ public bool Insert(I3DObject o, Sphere s) { if (s == null) { //objects without bounding sphere will potentially intersect every ray Content.Add(o); return(true); } switch (Strategy) { case TreeInsertStrategy.LeafOnly: if (!CubeSphere.IsSphereIntersectingCube(Center, Width / 2, s)) { return(false); } if (_child != null) { _child[0].Insert(o, s); _child[1].Insert(o, s); _child[2].Insert(o, s); _child[3].Insert(o, s); _child[4].Insert(o, s); _child[5].Insert(o, s); _child[6].Insert(o, s); _child[7].Insert(o, s); } else { Content.Add(o); } if (_child == null && Content.Count > TreeInsertStrategyConstants.MaxElements && Width > TreeInsertStrategyConstants.MinWidth) { Split(); } return(true); case TreeInsertStrategy.FitIntoBox: if (!o.IsEnclosedByCube(Center, Width / 2)) { return(false); } if (_child != null) { if (_child[0].Insert(o, s) || _child[1].Insert(o, s) || _child[2].Insert(o, s) || _child[3].Insert(o, s) || _child[4].Insert(o, s) || _child[5].Insert(o, s) || _child[6].Insert(o, s) || _child[7].Insert(o, s)) { return(true); } } Content.Add(o); if (_child == null && Content.Count > TreeInsertStrategyConstants.MaxElements && Width > TreeInsertStrategyConstants.MinWidth) { Split(); } return(true); case TreeInsertStrategy.Dynamic: //if sphere is not touching cube -> error if (!CubeSphere.IsSphereIntersectingCube(Center, Width / 2, s)) { return(false); } //if object is enclosed by any child, add it there if (_child != null) { foreach (Node n in _child) { if (o.IsEnclosedByCube(n.Center, n.Width / 2)) { return(n.Insert(o, s)); } } } //if object is very small (in relation to the box) - duplicate it to child nodes //add it to this node otherwise if (_child != null && s.Radius / Width < TreeInsertStrategyConstants.DynamicDuplicateMaxSizeRatio) { _child[0].Insert(o, s); _child[1].Insert(o, s); _child[2].Insert(o, s); _child[3].Insert(o, s); _child[4].Insert(o, s); _child[5].Insert(o, s); _child[6].Insert(o, s); _child[7].Insert(o, s); } else { Content.Add(o); } //if node too full split it if (_child == null && Content.Count > 2 /*&&width>TreeInsertStrategy.DYNAMIC_MIN_WIDTH*/) { Split(); } return(true); case TreeInsertStrategy.DynamicTest: //if sphere is not touching cube -> error if (!CubeSphere.IsSphereIntersectingCube(Center, Width / 2, s)) { return(false); } //if object is enclosed by any child, add it there if (_child != null) { foreach (Node n in _child) { if (o.IsEnclosedByCube(n.Center, n.Width / 2)) { return(n.Insert(o, s)); } } bool i0 = CubeSphere.IsSphereIntersectingCube(_child[0].Center, _child[0].Width / 2, s), i1 = CubeSphere.IsSphereIntersectingCube(_child[1].Center, _child[1].Width / 2, s), i2 = CubeSphere.IsSphereIntersectingCube(_child[2].Center, _child[2].Width / 2, s), i3 = CubeSphere.IsSphereIntersectingCube(_child[3].Center, _child[3].Width / 2, s), i4 = CubeSphere.IsSphereIntersectingCube(_child[4].Center, _child[4].Width / 2, s), i5 = CubeSphere.IsSphereIntersectingCube(_child[5].Center, _child[5].Width / 2, s), i6 = CubeSphere.IsSphereIntersectingCube(_child[6].Center, _child[6].Width / 2, s), i7 = CubeSphere.IsSphereIntersectingCube(_child[7].Center, _child[7].Width / 2, s); int intersectionCount = 0; if (i0) { intersectionCount++; } if (i1) { intersectionCount++; } if (i2) { intersectionCount++; } if (i3) { intersectionCount++; } if (i4) { intersectionCount++; } if (i5) { intersectionCount++; } if (i6) { intersectionCount++; } if (i7) { intersectionCount++; } if (intersectionCount == 1 || intersectionCount * s.Radius / Width < 0.35) { if (i0) { _child[0].Insert(o, s); } if (i1) { _child[1].Insert(o, s); } if (i2) { _child[2].Insert(o, s); } if (i3) { _child[3].Insert(o, s); } if (i4) { _child[4].Insert(o, s); } if (i5) { _child[5].Insert(o, s); } if (i6) { _child[6].Insert(o, s); } if (i7) { _child[7].Insert(o, s); } return(true); } } Content.Add(o); //if node too full split it if (_child == null && Content.Count > 2) { Split(); } return(true); case TreeInsertStrategy.FastBuildTest: //if sphere is not touching cube -> error if (!CubeSphere.IsSphereIntersectingCube(Center, Width / 2, s)) { return(false); } //if object is enclosed by any child, add it there if (_child != null) { bool i0 = CubeSphere.IsSphereIntersectingCube(_child[0].Center, _child[0].Width / 2, s), i1 = CubeSphere.IsSphereIntersectingCube(_child[1].Center, _child[1].Width / 2, s), i2 = CubeSphere.IsSphereIntersectingCube(_child[2].Center, _child[2].Width / 2, s), i3 = CubeSphere.IsSphereIntersectingCube(_child[3].Center, _child[3].Width / 2, s), i4 = CubeSphere.IsSphereIntersectingCube(_child[4].Center, _child[4].Width / 2, s), i5 = CubeSphere.IsSphereIntersectingCube(_child[5].Center, _child[5].Width / 2, s), i6 = CubeSphere.IsSphereIntersectingCube(_child[6].Center, _child[6].Width / 2, s), i7 = CubeSphere.IsSphereIntersectingCube(_child[7].Center, _child[7].Width / 2, s); int intersectionCount = 0; if (i0) { intersectionCount++; } if (i1) { intersectionCount++; } if (i2) { intersectionCount++; } if (i3) { intersectionCount++; } if (i4) { intersectionCount++; } if (i5) { intersectionCount++; } if (i6) { intersectionCount++; } if (i7) { intersectionCount++; } if (intersectionCount == 1 || intersectionCount * s.Radius / Width < 0.5) { if (i0) { _child[0].Insert(o, s); } if (i1) { _child[1].Insert(o, s); } if (i2) { _child[2].Insert(o, s); } if (i3) { _child[3].Insert(o, s); } if (i4) { _child[4].Insert(o, s); } if (i5) { _child[5].Insert(o, s); } if (i6) { _child[6].Insert(o, s); } if (i7) { _child[7].Insert(o, s); } return(true); } } Content.Add(o); //if node too full split it if (_child == null && Content.Count > TreeInsertStrategyConstants.MaxElements && Width > TreeInsertStrategyConstants.DynamicMinWidth) { Split(); } return(true); default: throw new Exception("Mode not implemented: " + Strategy); } }
public virtual bool IsEnclosedByCube(Vect3 cCenter, double cWidthHalf) { Sphere s = GetBoundingSphere(); return CubeSphere.IsSphereEnclosedByCube(cCenter, cWidthHalf, s.Position, s.Radius); }