public void Update() { if (reload && gameObjectCollection != null) { LoadShaders(); foreach (GameObject go in gameObjectCollection) { go.GetComponent <MeshRenderer>().material = material; } reload = false; } if (displayLOD) { foreach (GameObject go in gameObjectCollection) { BoundingBoxComponent bbc = go.GetComponent <BoundingBoxComponent>(); Utility.BBDraw.DrawBoundingBox(bbc.boundingBox, bbc.parent, Color.red, false); } } if (screenSize) { if (interpolation != FragInterpolationMode.OFF) { Matrix4x4 invP = (GL.GetGPUProjectionMatrix(renderCamera.projectionMatrix, true)).inverse; material.SetMatrix("_InverseProjMatrix", invP); material.SetFloat("_FOV", Mathf.Deg2Rad * renderCamera.fieldOfView); } Rect screen = renderCamera.pixelRect; material.SetInt("_ScreenWidth", (int)screen.width); material.SetInt("_ScreenHeight", (int)screen.height); } }
// Create Indices private void CreateBoundingBoxIndices(BoundingBoxComponent bbc) { IndexBuffer indexBuffer = new IndexBuffer(bbc.GraphicsDevice, IndexElementSize.SixteenBits, bbc.VertexCount, BufferUsage.WriteOnly); indexBuffer.SetData(Enumerable.Range(0, bbc.VertexCount).Select(i => (short)i).ToArray()); bbc.Indices = indexBuffer; }
public static int CreateBoundingBoxForEnt(GraphicsDevice gd, int entity) { BoundingBoxComponent bbc = new BoundingBoxComponent(gd) { BelongsToID = entity, Render = true }; return(cm.AddEntityWithComponents(bbc)); }
public void Update() { if (reload && gameObjectCollection != null) { LoadShaders(); foreach (GameObject go in gameObjectCollection) { go.GetComponent <MeshRenderer>().material = material; } reload = false; } if (displayLOD) { foreach (GameObject go in gameObjectCollection) { BoundingBoxComponent bbc = go.GetComponent <BoundingBoxComponent>(); Utility.BBDraw.DrawBoundingBox(bbc.boundingBox, bbc.parent, Color.red, false); } } if (screenSize) { if (interpolation != FragInterpolationMode.OFF) { Matrix4x4 invP = (GL.GetGPUProjectionMatrix(renderCamera.projectionMatrix, true)).inverse; material.SetMatrix("_InverseProjMatrix", invP); material.SetFloat("_FOV", Mathf.Deg2Rad * renderCamera.fieldOfView); } Rect screen = renderCamera.pixelRect; material.SetInt("_ScreenWidth", (int)screen.width); material.SetInt("_ScreenHeight", (int)screen.height); } if (enableAdaptivePointSize) { foreach (GameObject go in gameObjectCollection) { BoundingBoxComponent bbc = go.GetComponent <BoundingBoxComponent>(); Utility.BBDraw.DrawBoundingBox(bbc.boundingBox, bbc.parent, Color.red, false); if (go.GetComponent <MeshRenderer>().material.HasProperty("_BBSize")) { List <float> bbcSize = new List <float>(); bbcSize.Add((float)bbc.boundingBox.Size().x); bbcSize.Add((float)bbc.boundingBox.Size().y); bbcSize.Add((float)bbc.boundingBox.Size().z); go.GetComponent <MeshRenderer>().material.SetFloatArray("_BBSize", bbcSize); } } if (material.HasProperty("_VisibleNodes")) { //TODO } } }
public PlayerBrain(GameObject owner) : base(owner) { _movingBody = owner.Components.Get <MovingBody>(); _transform = owner.Components.Get <TransformComponent>(); _spriteRender = owner.Components.Get <SpriteRenderComponent>(); _halfSize = _spriteRender.Sprite.Bounds.Size / 2; _boundingBox = owner.Components.Get <BoundingBoxComponent>(); _boundingBox.OnCollision += (sender, collidedWith) => { this.Owner.Enabled = false; }; }
protected override void Init() { _movingBody = Owner.Components.Get <MovingBody>(); _transformComponent = Owner.Components.Get <TransformComponent>(); _boundingBox = Owner.Components.Get <BoundingBoxComponent>(); _boundingBox.OnCollision += (sender, collidedWith) => { if (collidedWith.Owner.Components.TryGet <AsteroidBrain>(out var _)) { this.Owner.Enabled = false; } }; }
private AsteroidBrain(GameObject owner) : base(owner) { _transform = owner.Components.Get <TransformComponent>(); _boundingBox = owner.Components.Get <BoundingBoxComponent>(); _boundingBox.OnCollision += (sender, collidedWith) => { // check if we're colliding with another asteroid if (!collidedWith.Owner.Components.TryGet <AsteroidBrain>(out var _)) { this.Owner.Enabled = false; } }; }
protected override void Init() { _transform = Owner.Components.Get <TransformComponent>(); _boundingBox = Owner.Components.Get <BoundingBoxComponent>(); _boundingBox.OnCollision += (sender, collidedWith) => { if (collidedWith.Owner.Components.TryGet <AsteroidBrain>(out var _)) { return; } this.Owner.Enabled = false; this.OnDeath?.Invoke(this.Owner); }; }
public override GameObject CreateGameObject(string name, Vector3[] vertexData, Color[] colorData, BoundingBox boundingBox, Transform parent, double spacing) { GameObject gameObject = new GameObject(name); Debug.Log(name + " spacing = " + spacing); Mesh mesh = new Mesh(); MeshFilter filter = gameObject.AddComponent <MeshFilter>(); filter.mesh = mesh; MeshRenderer renderer = gameObject.AddComponent <MeshRenderer>(); renderer.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off; renderer.receiveShadows = false; renderer.material = material; if (enableAdaptivePointSize && material.HasProperty("_OctreeSpacing")) { material.SetFloat("_OctreeSpacing", (float)spacing); } int[] indecies = new int[vertexData.Length]; for (int i = 0; i < vertexData.Length; ++i) { indecies[i] = i; } mesh.vertices = vertexData; mesh.colors = colorData; mesh.SetIndices(indecies, MeshTopology.Points, 0); //Set Translation gameObject.transform.Translate(boundingBox.Min().ToFloatVector()); gameObject.transform.SetParent(parent, false); BoundingBoxComponent bbc = gameObject.AddComponent <BoundingBoxComponent>(); bbc.boundingBox = boundingBox;; bbc.parent = parent; if (gameObjectCollection != null) { gameObjectCollection.Add(gameObject); } return(gameObject); }
protected override void Init() { _movingBody = Owner.Components.Get <MovingBody>(); _transform = Owner.Components.Get <TransformComponent>(); _spriteRender = Owner.Components.Get <SpriteRenderComponent>(); _halfSize = _spriteRender.Sprite.Bounds.Size / 2; _boundingBox = Owner.Components.Get <BoundingBoxComponent>(); _boundingBox.OnCollision += (sender, collidedWith) => { if (collidedWith.Owner.Components.TryGet <AsteroidBrain>(out var _)) { this.Stats.Health--; if (0 == this.Stats.Health) { this.Owner.Enabled = false; this.OnDeath?.Invoke(this.Owner); } } }; }
// Create buffers private void CreateBoundingBoxBuffers(BoundingBoxComponent bbc) { bbc.PrimitiveCount = 24; bbc.VertexCount = 48; VertexBuffer vertexBuffer = new VertexBuffer( bbc.GraphicsDevice, typeof(VertexPositionColor), bbc.VertexCount, BufferUsage.WriteOnly); List <VertexPositionColor> vertices = new List <VertexPositionColor>(); const float ratio = 5.0f; Color c = Color.Red; Vector3 xOffset = new Vector3((bbc.BoundingBox.Max.X - bbc.BoundingBox.Min.X) / ratio, 0, 0); Vector3 yOffset = new Vector3(0, (bbc.BoundingBox.Max.Y - bbc.BoundingBox.Min.Y) / ratio, 0); Vector3 zOffset = new Vector3(0, 0, (bbc.BoundingBox.Max.Z - bbc.BoundingBox.Min.Z) / ratio); Vector3[] corners = bbc.BoundingBox.GetCorners(); // Corner 1. vertices.Add(new VertexPositionColor(corners[0], c)); vertices.Add(new VertexPositionColor(corners[0] + xOffset, c)); vertices.Add(new VertexPositionColor(corners[0], c)); vertices.Add(new VertexPositionColor(corners[0] - yOffset, c)); vertices.Add(new VertexPositionColor(corners[0], c)); vertices.Add(new VertexPositionColor(corners[0] - zOffset, c)); // Corner 2. vertices.Add(new VertexPositionColor(corners[1], c)); vertices.Add(new VertexPositionColor(corners[1] - xOffset, c)); vertices.Add(new VertexPositionColor(corners[1], c)); vertices.Add(new VertexPositionColor(corners[1] - yOffset, c)); vertices.Add(new VertexPositionColor(corners[1], c)); vertices.Add(new VertexPositionColor(corners[1] - zOffset, c)); // Corner 3. vertices.Add(new VertexPositionColor(corners[2], c)); vertices.Add(new VertexPositionColor(corners[2] - xOffset, c)); vertices.Add(new VertexPositionColor(corners[2], c)); vertices.Add(new VertexPositionColor(corners[2] + yOffset, c)); vertices.Add(new VertexPositionColor(corners[2], c)); vertices.Add(new VertexPositionColor(corners[2] - zOffset, c)); // Corner 4. vertices.Add(new VertexPositionColor(corners[3], c)); vertices.Add(new VertexPositionColor(corners[3] + xOffset, c)); vertices.Add(new VertexPositionColor(corners[3], c)); vertices.Add(new VertexPositionColor(corners[3] + yOffset, c)); vertices.Add(new VertexPositionColor(corners[3], c)); vertices.Add(new VertexPositionColor(corners[3] - zOffset, c)); // Corner 5. vertices.Add(new VertexPositionColor(corners[4], c)); vertices.Add(new VertexPositionColor(corners[4] + xOffset, c)); vertices.Add(new VertexPositionColor(corners[4], c)); vertices.Add(new VertexPositionColor(corners[4] - yOffset, c)); vertices.Add(new VertexPositionColor(corners[4], c)); vertices.Add(new VertexPositionColor(corners[4] + zOffset, c)); // Corner 6. vertices.Add(new VertexPositionColor(corners[5], c)); vertices.Add(new VertexPositionColor(corners[5] - xOffset, c)); vertices.Add(new VertexPositionColor(corners[5], c)); vertices.Add(new VertexPositionColor(corners[5] - yOffset, c)); vertices.Add(new VertexPositionColor(corners[5], c)); vertices.Add(new VertexPositionColor(corners[5] + zOffset, c)); // Corner 7. vertices.Add(new VertexPositionColor(corners[6], c)); vertices.Add(new VertexPositionColor(corners[6] - xOffset, c)); vertices.Add(new VertexPositionColor(corners[6], c)); vertices.Add(new VertexPositionColor(corners[6] + yOffset, c)); vertices.Add(new VertexPositionColor(corners[6], c)); vertices.Add(new VertexPositionColor(corners[6] + zOffset, c)); // Corner 8. vertices.Add(new VertexPositionColor(corners[7], c)); vertices.Add(new VertexPositionColor(corners[7] + xOffset, c)); vertices.Add(new VertexPositionColor(corners[7], c)); vertices.Add(new VertexPositionColor(corners[7] + yOffset, c)); vertices.Add(new VertexPositionColor(corners[7], c)); vertices.Add(new VertexPositionColor(corners[7] + zOffset, c)); vertexBuffer.SetData(vertices.ToArray()); bbc.Vertices = vertexBuffer; }