internal static bool TryCreateFromLightProbe(LightProbeGroup lightProbe, out BoundsData boundsData) { var positions = lightProbe.probePositions; if (positions.Length == 0) { boundsData = default(BoundsData); return(false); } var transformer = lightProbe.transform.localToWorldMatrix; var first = transformer.MultiplyPoint3x4(positions[0]); Vector3 min = first; Vector3 max = first; for (int i = 1; i < positions.Length; i++) { var worldPosition = transformer.MultiplyPoint3x4(positions[i]); min = Vector3.Min(min, worldPosition); max = Vector3.Max(max, worldPosition); } var center = (min + max) * 0.5f; var size = max - min; boundsData = new BoundsData(lightProbe, new Bounds(center, size)); return(true); }
private static IEnumerable <BoundsData> GetObjectBounds(GameObject gameObject) { var transform = gameObject.transform; if (transform is RectTransform) { yield return(BoundsData.FromRectTransform((RectTransform)transform)); } else { yield return(BoundsData.FromTransform(transform)); } foreach (var renderer in gameObject.GetComponents <Renderer>()) { yield return(BoundsData.FromRenderer(renderer)); } foreach (var collider in gameObject.GetComponents <Collider>()) { yield return(BoundsData.FromCollider(collider)); } foreach (var lightProbe in gameObject.GetComponents <LightProbeGroup>()) { BoundsData data; if (!BoundsData.TryCreateFromLightProbe(lightProbe, out data)) { continue; } yield return(data); } }
public void Execute(Entity octreeRootNodeEntity, int jobIndex, DynamicBuffer <CollisionInstancesBufferElement> a_collisionInstancesBuffer, ref IsCollidingData isColliding, [ReadOnly] ref BoundsEntityPair4CollisionData boundsEntityPair4Collision) // public void Execute ( int i_arrayIndex ) { // Entity octreeRootNodeEntity = a_collisionChecksEntities [i_arrayIndex] ; // Its value should be 0, if no collision is detected. // And >= 1, if instance collision is detected, or there is more than one collision, // indicating number of collisions. // IsCollidingData isCollidingData = a_isCollidingData [octreeRootNodeEntity] ; // Stores reference to detected colliding instance. // DynamicBuffer <CollisionInstancesBufferElement> a_collisionInstancesBuffer = collisionInstancesBufferElement [octreeRootNodeEntity] ; isColliding.i_nearestInstanceCollisionIndex = 0; isColliding.f_nearestDistance = float.PositiveInfinity; isColliding.i_collisionsCount = 0; // Reset colliding instances counter. RootNodeData rootNode = a_octreeRootNodeData [octreeRootNodeEntity]; DynamicBuffer <NodeBufferElement> a_nodesBuffer = nodeBufferElement [octreeRootNodeEntity]; DynamicBuffer <NodeInstancesIndexBufferElement> a_nodeInstancesIndexBuffer = nodeInstancesIndexBufferElement [octreeRootNodeEntity]; DynamicBuffer <NodeChildrenBufferElement> a_nodeChildrenBuffer = nodeChildrenBufferElement [octreeRootNodeEntity]; DynamicBuffer <InstanceBufferElement> a_instanceBuffer = instanceBufferElement [octreeRootNodeEntity]; // BoundsEntityPair4CollisionData rayEntityPair4CollisionData = a_boundsEntityPair4CollisionData [octreeRootNodeEntity] ; // BoundsEntityPair4CollisionData rayEntityPair4CollisionData = a_boundsEntityPair4CollisionData [octreeRootNodeEntity] ; // Ray entity pair, for collision checks Entity bounds2CheckEntity = boundsEntityPair4Collision.bounds2CheckEntity; // Is target octree active if (a_isActiveTag.Exists(bounds2CheckEntity)) { BoundsData checkBounds = a_boundsData [bounds2CheckEntity]; // To even allow instances collision checks, octree must have at least one instance. if (rootNode.i_totalInstancesCountInTree > 0) { if (GetCollidingBoundsInstances_Common._GetNodeColliding(ref rootNode, rootNode.i_rootNodeIndex, checkBounds.bounds, ref a_collisionInstancesBuffer, ref isColliding, ref a_nodesBuffer, ref a_nodeChildrenBuffer, ref a_nodeInstancesIndexBuffer, ref a_instanceBuffer)) { /* * // Debug * Debug.Log ( "Is colliding." ) ; */ } } } // a_isCollidingData [octreeRootNodeEntity] = isCollidingData ; // Set back. }
public void Execute(int i_arrayIndex) { Entity octreeRayEntity = a_collisionChecksEntities [i_arrayIndex]; BoundsData boundsData = new BoundsData() { bounds = checkBounds }; a_boundsData [octreeRayEntity] = boundsData; }
public void Execute(ref BoundsEntityPair4CollisionData boundsEntityPair4Collision) { // Entity octreeEntity = a_collisionChecksEntities [i_arrayIndex] ; // BoundsEntityPair4CollisionData boundsEntityPair4Collision = a_boundsEntityPair4CollisionData [octreeEntity] ; Entity octreeBoundsEntity = boundsEntityPair4Collision.bounds2CheckEntity; a_boundsData [octreeBoundsEntity] = new BoundsData() { bounds = checkBounds }; }
private BoundsData FindTerrainHeightAtCorners(Bounds bounds, Vector3 trialPosition, Quaternion trialRotation) { float minY = bounds.min.y; float minX = bounds.min.x; float minZ = bounds.min.z; float maxX = bounds.max.x; float maxZ = bounds.max.z; var corner1 = new Vector3(minX, minY, minZ); var corner2 = new Vector3(minX, minY, maxZ); var corner3 = new Vector3(maxX, minY, minZ); var corner4 = new Vector3(maxX, minY, maxZ); var centre = new Vector3(0.5f * (minX + maxX), minY, 0.5f * (minZ + maxZ)); // TODO: add side and centre sampling? var originToCorner1 = corner1 - trialPosition; var originToCorner2 = corner2 - trialPosition; var originToCorner3 = corner3 - trialPosition; var originToCorner4 = corner4 - trialPosition; var originToCentre = centre - trialPosition; float originAboveBase = trialPosition.y - bounds.min.y; originToCorner1 = trialRotation * originToCorner1; originToCorner2 = trialRotation * originToCorner2; originToCorner3 = trialRotation * originToCorner3; originToCorner4 = trialRotation * originToCorner4; originToCentre = trialRotation * originToCentre; corner1 = trialPosition + originToCorner1; corner2 = trialPosition + originToCorner2; corner3 = trialPosition + originToCorner3; corner4 = trialPosition + originToCorner4; centre = trialPosition + originToCentre; float terrainHeightCorner1 = m_mapGenerator.GetTerrainHeight(corner1.x, corner1.z); float terrainHeightCorner2 = m_mapGenerator.GetTerrainHeight(corner2.x, corner2.z); float terrainHeightCorner3 = m_mapGenerator.GetTerrainHeight(corner3.x, corner3.z); float terrainHeightCorner4 = m_mapGenerator.GetTerrainHeight(corner4.x, corner4.z); float terrainHeightCentre = m_mapGenerator.GetTerrainHeight(centre.x, centre.z); float minTerrainHeight = Mathf.Min(terrainHeightCorner1, terrainHeightCorner2, terrainHeightCorner3, terrainHeightCorner4, terrainHeightCentre); float maxTerrainHeight = Mathf.Max(terrainHeightCorner1, terrainHeightCorner2, terrainHeightCorner3, terrainHeightCorner4, terrainHeightCentre); var boundsData = new BoundsData(corner1, corner2, corner3, corner4, centre, minTerrainHeight, maxTerrainHeight, originAboveBase, terrainHeightCorner1, terrainHeightCorner2, terrainHeightCorner3, terrainHeightCorner4, terrainHeightCentre); return(boundsData); }
public void Execute(int i_arrayIndex) { Entity octreeEntity = a_collisionChecksEntities [i_arrayIndex]; BoundsEntityPair4CollisionData boundsEntityPair4CollisionData = a_boundsEntityPair4CollisionData [octreeEntity]; Entity octreeBoundsEntity = boundsEntityPair4CollisionData.bounds2CheckEntity; BoundsData boundsData = new BoundsData() { bounds = checkBounds }; a_boundsData [octreeBoundsEntity] = boundsData; }
public void Execute([ReadOnly] ref BoundsEntityPair4CollisionData boundsEntityPair4Collision) // public void Execute ( int i_arrayIndex ) { // Entity octreeEntity = a_collisionChecksEntities [i_arrayIndex] ; // BoundsEntityPair4CollisionData boundsEntityPair4CollisionData = a_boundsEntityPair4CollisionData [octreeEntity] ; Entity octreeBoundsEntity = boundsEntityPair4Collision.bounds2CheckEntity; a_boundsData [octreeBoundsEntity] = new BoundsData() { bounds = checkBounds }; // a_boundsData [octreeBoundsEntity] = boundsData ; }
public void Execute(int i_arrayIndex) { Entity octreeBoundsEntity = a_collisionChecksEntities [i_arrayIndex]; // Its value should be 0, if no collision is detected. // And >= 1, if instance collision is detected, or there is more than one collision, // indicating number of collisions. IsCollidingData isCollidingData = a_isCollidingData [octreeBoundsEntity]; isCollidingData.i_collisionsCount = 0; // Reset colliding instances counter. // isCollidingData.i_nearestInstanceCollisionIndex = 0 ; // Unused // isCollidingData.f_nearestDistance = float.PositiveInfinity ; // Unused OctreeEntityPair4CollisionData octreeEntityPair4CollisionData = a_octreeEntityPair4CollisionData [octreeBoundsEntity]; BoundsData checkBounds = a_boundsData [octreeBoundsEntity]; // Octree entity pair, for collision checks Entity octreeRootNodeEntity = octreeEntityPair4CollisionData.octree2CheckEntity; // Is target octree active if (a_isActiveTag.Exists(octreeRootNodeEntity)) { RootNodeData octreeRootNodeData = a_octreeRootNodeData [octreeRootNodeEntity]; DynamicBuffer <NodeBufferElement> a_nodesBuffer = nodeBufferElement [octreeRootNodeEntity]; DynamicBuffer <NodeInstancesIndexBufferElement> a_nodeInstancesIndexBuffer = nodeInstancesIndexBufferElement [octreeRootNodeEntity]; DynamicBuffer <NodeChildrenBufferElement> a_nodeChildrenBuffer = nodeChildrenBufferElement [octreeRootNodeEntity]; DynamicBuffer <InstanceBufferElement> a_instanceBuffer = instanceBufferElement [octreeRootNodeEntity]; // To even allow instances collision checks, octree must have at least one instance. if (octreeRootNodeData.i_totalInstancesCountInTree > 0) { // To even allow instances collision checks, octree must have at least one instance. if (IsBoundsColliding_Common._IsNodeColliding(octreeRootNodeData, octreeRootNodeData.i_rootNodeIndex, checkBounds.bounds, ref isCollidingData, a_nodesBuffer, a_nodeChildrenBuffer, a_nodeInstancesIndexBuffer, a_instanceBuffer)) { // Debug.Log ( "Is colliding." ) ; } } } a_isCollidingData [octreeBoundsEntity] = isCollidingData; // Set back. }
private static IEnumerable <BoundsData> GetObjectBounds(GameObject gameObject) { var transform = gameObject.transform; if (transform is RectTransform) { yield return(BoundsData.FromRectTransform((RectTransform)transform)); } else { yield return(BoundsData.FromTransform(transform)); } foreach (var renderer in gameObject.GetComponents <Renderer>()) { yield return(BoundsData.FromRenderer(renderer)); } }
public Box(BoundsData boundsData, string id) { BoundsData = boundsData; Id = id; }
private void AddDebugSpheres(BoundsData boundsData, float y, Transform parent) { boundsData.corner1.y = y - boundsData.originAboveBase; boundsData.corner2.y = y - boundsData.originAboveBase; boundsData.corner3.y = y - boundsData.originAboveBase; boundsData.corner4.y = y - boundsData.originAboveBase; boundsData.centre.y = y - boundsData.originAboveBase; var sphere1 = GameObject.CreatePrimitive(PrimitiveType.Sphere); var sphere2 = GameObject.CreatePrimitive(PrimitiveType.Sphere); var sphere3 = GameObject.CreatePrimitive(PrimitiveType.Sphere); var sphere4 = GameObject.CreatePrimitive(PrimitiveType.Sphere); var sphere5 = GameObject.CreatePrimitive(PrimitiveType.Sphere); sphere1.transform.position = boundsData.corner1; sphere2.transform.position = boundsData.corner2; sphere3.transform.position = boundsData.corner3; sphere4.transform.position = boundsData.corner4; sphere5.transform.position = boundsData.centre; //print(string.Format("Pos: {0}, height: {1}", corner1, terrainHeightCorner1)); //print(string.Format("Pos: {0}, height: {1}", corner2, terrainHeightCorner2)); //print(string.Format("Pos: {0}, height: {1}", corner3, terrainHeightCorner3)); //print(string.Format("Pos: {0}, height: {1}", corner4, terrainHeightCorner4)); var sphere6 = GameObject.CreatePrimitive(PrimitiveType.Sphere); var sphere7 = GameObject.CreatePrimitive(PrimitiveType.Sphere); var sphere8 = GameObject.CreatePrimitive(PrimitiveType.Sphere); var sphere9 = GameObject.CreatePrimitive(PrimitiveType.Sphere); var sphere10 = GameObject.CreatePrimitive(PrimitiveType.Sphere); sphere1.GetComponent <Collider>().enabled = false; sphere2.GetComponent <Collider>().enabled = false; sphere3.GetComponent <Collider>().enabled = false; sphere4.GetComponent <Collider>().enabled = false; sphere5.GetComponent <Collider>().enabled = false; sphere6.GetComponent <Collider>().enabled = false; sphere7.GetComponent <Collider>().enabled = false; sphere8.GetComponent <Collider>().enabled = false; sphere9.GetComponent <Collider>().enabled = false; sphere10.GetComponent <Collider>().enabled = false; boundsData.corner1.y = boundsData.terrainHeightCorner1; boundsData.corner2.y = boundsData.terrainHeightCorner2; boundsData.corner3.y = boundsData.terrainHeightCorner3; boundsData.corner4.y = boundsData.terrainHeightCorner4; boundsData.centre.y = boundsData.terrainHeightCentre; sphere6.transform.position = boundsData.corner1; sphere7.transform.position = boundsData.corner2; sphere8.transform.position = boundsData.corner3; sphere9.transform.position = boundsData.corner4; sphere10.transform.position = boundsData.centre; sphere1.transform.parent = parent; sphere2.transform.parent = parent; sphere3.transform.parent = parent; sphere4.transform.parent = parent; sphere5.transform.parent = parent; sphere6.transform.parent = parent; sphere7.transform.parent = parent; sphere8.transform.parent = parent; sphere9.transform.parent = parent; sphere10.transform.parent = parent; }
internal BoxData(Box[] boxes) { this.boxes = boxes; totalBounds = DeriveTotalBounds(boxes); }
protected BoundsData GetTextBounds(SvgRenderer renderer) { var font = GetFont(renderer); SvgTextBase innerText; SizeF stringBounds; float totalHeight = 0; float totalWidth = 0; var result = new BoundsData(); var nodes = (from n in this.Nodes where (n is SvgContentNode || n is SvgTextBase) && !string.IsNullOrEmpty(n.Content) select n).ToList(); if (nodes.FirstOrDefault() is SvgContentNode && _x.Count > 1) { string ch; var content = nodes.First() as SvgContentNode; nodes.RemoveAt(0); int posCount = Math.Min(content.Content.Length, _x.Count); var text = PrepareText(content.Content, false, (nodes.Count > 1 && nodes[1] is SvgTextBase)); for (var i = 0; i < posCount; i++) { ch = (i == posCount - 1 ? text.Substring(i) : text.Substring(i, 1)); stringBounds = _stringMeasure.MeasureString(ch, font); totalHeight = Math.Max(totalHeight, stringBounds.Height); result.Nodes.Add(new NodeBounds() { Bounds = stringBounds, Node = new SvgContentNode() { Content = ch }, xOffset = (i == 0 ? 0 : _x[i].ToDeviceValue(renderer, UnitRenderingType.Horizontal, this) - _x[0].ToDeviceValue(renderer, UnitRenderingType.Horizontal, this)) }); } } ISvgNode node; for (var i = 0; i < nodes.Count; i++) { node = nodes[i]; lock (_stringMeasure) { innerText = node as SvgTextBase; if (innerText == null) { stringBounds = _stringMeasure.MeasureString(PrepareText(node.Content, i > 0 && nodes[i - 1] is SvgTextBase, i < nodes.Count - 1 && nodes[i + 1] is SvgTextBase), font); result.Nodes.Add(new NodeBounds() { Bounds = stringBounds, Node = node, xOffset = totalWidth }); } else { stringBounds = innerText.GetTextBounds(renderer).Bounds; result.Nodes.Add(new NodeBounds() { Bounds = stringBounds, Node = node, xOffset = totalWidth }); if (innerText.Dx.Count == 1) { totalWidth += innerText.Dx[0].ToDeviceValue(renderer, UnitRenderingType.Horizontal, this); } } totalHeight = Math.Max(totalHeight, stringBounds.Height); totalWidth += stringBounds.Width; } } result.Bounds = new SizeF(totalWidth, totalHeight); return(result); }