// 3D ASTEROID GENERATION public GameObject GenerateAsteroid(AsteroidBillboard billboard, BeltChunk chunk) { AsteroidData asteroidData = asteroidDatas[billboard.atlasIndex]; GameObject ret = Instantiate(asteroidData.prefab, billboard.position, Quaternion.identity, chunk.transform); ret.transform.localScale = Vector3.one * billboard.size; return(ret); }
public AsteroidFieldRenderer(AsteroidField field, SystemRenderer sys) { this.field = field; this.sys = sys; //Set up renderDistSq float rdist = 0f; if (field.Zone.Shape is ZoneSphere) { rdist = ((ZoneSphere)field.Zone.Shape).Radius; } else if (field.Zone.Shape is ZoneEllipsoid) { var s = ((ZoneEllipsoid)field.Zone.Shape).Size; rdist = Math.Max(Math.Max(s.X, s.Y), s.Z); } else if (field.Zone.Shape is ZoneBox) { var s = ((ZoneEllipsoid)field.Zone.Shape).Size; rdist = Math.Max(Math.Max(s.X, s.Y), s.Z); } if (field.BillboardCount != -1) { billboardCube = new AsteroidBillboard[field.BillboardCount]; for (int i = 0; i < field.BillboardCount; i++) { billboardCube[i].Spawn(this); } calculatedBillboards = new AsteroidBillboard[field.BillboardCount]; } rdist += field.FillDist; renderDistSq = rdist * rdist; cubes = new CalculatedCube[4000]; _asteroidsCalculation = CalculateAsteroidsTask; if (field.Cube.Count > 0) { CreateBufferObject(); } //Set up band if (field.Band == null) { return; } if (bandShader == null) { bandShader = Shaders.AsteroidBand.Get(); _bsTexture = bandShader.Shader.GetLocation("Texture"); _bsCameraPosition = bandShader.Shader.GetLocation("CameraPosition"); _bsColorShift = bandShader.Shader.GetLocation("ColorShift"); _bsTextureAspect = bandShader.Shader.GetLocation("TextureAspect"); } Vector3 sz; if (field.Zone.Shape is ZoneSphere) { sz = new Vector3(((ZoneSphere)field.Zone.Shape).Radius); } else if (field.Zone.Shape is ZoneEllipsoid) { sz = ((ZoneEllipsoid)field.Zone.Shape).Size; } else { return; } sz.X -= field.Band.OffsetDistance; sz.Z -= field.Band.OffsetDistance; lightingRadius = Math.Max(sz.X, sz.Z); renderBand = true; bandTransform = ( Matrix4x4.CreateScale(sz.X, field.Band.Height / 2, sz.Z) * field.Zone.RotationMatrix * Matrix4x4.CreateTranslation(field.Zone.Position) ); bandCylinder = sys.ResourceManager.GetOpenCylinder(SIDES); }