Ejemplo n.º 1
0
 public SphereModel(GameObject prefab, SphereData spheredata)
 {
     SphereData      = spheredata;
     SphereStruct    = spheredata.SphereStruct;
     SphereTransform = prefab.transform;
     SphereCollider  = prefab.gameObject.GetComponent <SphereCollider>();
 }
Ejemplo n.º 2
0
    SphereData ransac_sphere(List <Vector3> points, float tolerance)
    {
        // evaluate
        int        maxVote    = 0;
        SphereData bestSphere = null;

        for (int i = 0; i < 500; i++)
        {
            SphereData s    = ransac_a_sphere(points);
            int        vote = 0;
            foreach (Vector3 p in points)
            {
                float distance = Vector3.Distance(s.center, p);
                if (Mathf.Abs(distance - s.radius) < tolerance)
                {
                    vote++;
                }
            }

            if (maxVote < vote)
            {
                maxVote    = vote;
                bestSphere = s;
            }
        }

        //output the SphereUI data
        print("Ransac: " + maxVote + "Matched / " + points.Count);
        print("Sphere: Center: " + bestSphere.center.x + " , " + bestSphere.center.y + " , " + bestSphere.center.z + "  " + " Radius: " + bestSphere.radius);
        print("Mean Error: " + calMeanError(points, bestSphere));
        print("Standard Error: " + calStdError(points, bestSphere));

        return(bestSphere);
    }
Ejemplo n.º 3
0
    public static SphereData loadSphere()
    {
        sphereLoad = new SphereData(Vector3.zero, -1);

        FileInfo     theSourceFile = null;
        StreamReader reader        = null;

        theSourceFile = new FileInfo("Assets/SphereResource/" + SphereDataWriter.FileName);

        if (!theSourceFile.Exists)
        {
            return(sphereLoad);
        }
        reader = theSourceFile.OpenText();

        String center_string = reader.ReadLine();
        String radius_string = reader.ReadLine();

        sphereLoad = new SphereData(parseCenter(center_string), parseRadius(radius_string));

        reader.Dispose();

        print("SphereDataLoader: Finish Reading");
        print("Center: " + sphereLoad.center);
        print("Radius: " + sphereLoad.radius);
        return(sphereLoad);
    }
Ejemplo n.º 4
0
    void AddPrimitiveData(EntityData entity, PhysicsType type, GameObject go)
    {
        switch (type)
        {
        case PhysicsType.Cube:
            CubeData cube = new CubeData();
            cube.posX = Round(go.transform.localPosition.x);
            cube.posY = Round(go.transform.localPosition.y);
            cube.posZ = Round(go.transform.localPosition.z);

            cube.quaternionX = Round(go.transform.localRotation.x);
            cube.quaternionY = Round(go.transform.localRotation.y);
            cube.quaternionZ = Round(go.transform.localRotation.z);
            cube.quaternionW = Round(go.transform.localRotation.w);

            cube.length = Round(go.transform.localScale.x);
            cube.height = Round(go.transform.localScale.y);
            cube.width  = Round(go.transform.localScale.z);

            entity.cubeData.Add(cube);
            break;

        case PhysicsType.Sphere:
            SphereData sphere = new SphereData();
            sphere.posX = Round(go.transform.localPosition.x);
            sphere.posY = Round(go.transform.localPosition.y);
            sphere.posZ = Round(go.transform.localPosition.z);

            sphere.radius = Round(go.transform.localScale.x / 2);

            entity.sphereData.Add(sphere);
            break;
        }
    }
Ejemplo n.º 5
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            // get plane
            var rc = RhinoGet.GetPlane(out var plane);

            if (rc != Result.Success)
            {
                return(rc);
            }

            // get radius
            double radius = 0;

            rc = RhinoGet.GetNumber("Specify Radius", false, ref radius, 0.1, 1000000);
            if (rc != Result.Success)
            {
                return(rc);
            }

            // create spheredata
            var data = new SphereData(plane, radius);
            // and sphere object
            var sphereObject = data.CreateCustomObject();

            // add sphereObject to doc
            doc.Objects.AddRhinoObject(sphereObject);

            //redraw views
            doc.Views.Redraw();
            // return success
            return(Result.Success);
        }
Ejemplo n.º 6
0
        public Sphere Create(SphereData data)
        {
            Sphere result = GameObject.Instantiate(_bodyPrefab, null, true);

            result.SetData(data);
            result.GenerateMesh();
            return(result);
        }
Ejemplo n.º 7
0
    void CreateScene()
    {
        List <Sphere> allSpheres = new List <Sphere>(FindObjectsOfType <Sphere>());

        allSpheres.Sort((a, b) => a.operation.CompareTo(b.operation));

        List <Sphere> orderedSpheres = new List <Sphere>();

        for (int i = 0; i < allSpheres.Count; i++)
        {
            //top level spheres
            if (allSpheres[i].transform.parent == null)
            {
                Transform parentSphere = allSpheres[i].transform;
                orderedSpheres.Add(allSpheres[i]);
                allSpheres[i].children = parentSphere.childCount;
                for (int j = 0; j < parentSphere.childCount; j++)
                {
                    if (parentSphere.GetChild(j).GetComponent <Sphere>() != null)
                    {
                        orderedSpheres.Add(parentSphere.GetChild(j).GetComponent <Sphere>());
                        orderedSpheres[orderedSpheres.Count - 1].children = 0;
                    }
                }
            }
        }

        SphereData[] sphereData = new SphereData[orderedSpheres.Count];
        for (int i = 0; i < orderedSpheres.Count; i++)
        {
            var sphere = orderedSpheres[i];
            sphereData[i] = new SphereData()
            {
                position  = sphere.Position,
                scale     = sphere.Scale,
                operation = (int)sphere.operation,
                blending  = sphere.blending * 3,
                children  = sphere.children
            };
        }

        //Noise = orderedSpheres[0].Noise; //TODO: the 2d noise isn't working out. I'll probably remove it.
        //if (Noise)
        //{
        rayMarcher.SetInt("noiseIterations", orderedSpheres[0].noiseIterations);
        //rayMarcher.SetTexture(0,"Noise",Noise);
        //}

        int           dataSize     = sizeof(float) * 7 + sizeof(int) * 2;
        ComputeBuffer sphereBuffer = new ComputeBuffer(sphereData.Length, dataSize);

        sphereBuffer.SetData(sphereData);
        rayMarcher.SetBuffer(0, "scene", sphereBuffer);
        rayMarcher.SetInt("totalShapes", sphereData.Length);

        buffers.Add(sphereBuffer);
    }
        internal static Vec3 CalculateCenterOfMass(PhysicsShape body)
        {
            if ((NativeObject)body == (NativeObject)null)
            {
                return(Vec3.Zero);
            }
            Vec3  zero = Vec3.Zero;
            float num1 = 0.0f;
            int   num2 = body.CapsuleCount();

            for (int index = 0; index < num2; ++index)
            {
                CapsuleData data = new CapsuleData();
                body.GetCapsule(ref data, index);
                Vec3  vec3 = (data.P1 + data.P2) * 0.5f;
                float num3 = data.P1.Distance(data.P2);
                float num4 = (float)((double)data.Radius * (double)data.Radius * 3.14159274101257 * (1.33333337306976 * (double)data.Radius + (double)num3));
                num1 += num4;
                zero += vec3 * num4;
            }
            int num5 = body.SphereCount();

            for (int index = 0; index < num5; ++index)
            {
                SphereData data = new SphereData();
                body.GetSphere(ref data, index);
                float num3 = 4.18879f * data.Radius * data.Radius * data.Radius;
                num1 += num3;
                zero += data.Origin * num3;
            }
            Vec3 vec3_1;

            if ((double)num1 > 0.0)
            {
                vec3_1 = zero / num1;
                if ((double)Math.Abs(vec3_1.x) < 0.00999999977648258)
                {
                    vec3_1.x = 0.0f;
                }
                if ((double)Math.Abs(vec3_1.y) < 0.00999999977648258)
                {
                    vec3_1.y = 0.0f;
                }
                if ((double)Math.Abs(vec3_1.z) < 0.00999999977648258)
                {
                    vec3_1.z = 0.0f;
                }
            }
            else
            {
                vec3_1 = Vec3.Zero;
            }
            return(vec3_1);
        }
Ejemplo n.º 9
0
    public void RegisterSphere(RaySphere s)
    {
        SphereData d = new SphereData();

        d.col = new Vector3(s.renderColor.r, s.renderColor.g, s.renderColor.b);
        d.pos = (s.transform.position);

        //s.GetComponent<SphereCollider>().radius * (float)multiplier *
        d.details = new Vector3(s.transform.localScale.x / 2, s.shininess, s.specIntensity);

        spheres.Add(d);
    }
Ejemplo n.º 10
0
    void LoadSpheres(byte[] buffer)
    {
        NetworkReader nr = new NetworkReader(buffer);

        List <NetworkData> tmpList = new List <NetworkData>();
        NetworkData        tmpData;

        // Read to the end
        while (nr.Position != buffer.Length)
        {
            // Deserialize
            tmpData.id  = nr.ReadInt32();
            tmpData.pos = nr.ReadVector3();
            tmpData.r   = nr.ReadSingle();
            tmpData.g   = nr.ReadSingle();
            tmpData.b   = nr.ReadSingle();
            tmpList.Add(tmpData);
        }

        // Clean up null game objects
        sphereList.RemoveAll(item => item.obj == null);

        SphereData sd;

        foreach (var networkData in tmpList)
        {
            sd = sphereList.FirstOrDefault(item => item.id == networkData.id);
            // Do we have this sphere already?
            if (sd != null)
            {
                // Update position
                sd.obj.transform.position = networkData.pos;
                sd.lastUpdate             = Time.realtimeSinceStartup;
            }
            else
            {
                // Create new object
                GameObject sphere = GameObject.CreatePrimitive(PrimitiveType.Sphere);
                // No rigidbody here!
                // Set position
                sphere.transform.position = networkData.pos;
                // Set color
                sphere.GetComponent <Renderer>().material.color = new Color(networkData.r, networkData.g, networkData.b);

                sd            = new SphereData();
                sd.id         = networkData.id;
                sd.obj        = sphere;
                sd.lastUpdate = Time.realtimeSinceStartup;
                sphereList.Add(sd);
            }
        }
    }
Ejemplo n.º 11
0
    public CreatureStateBody(string typeName, UnityEngine.GameObject parent)
    {
        creatureStateBodyPhysics = new CreatureStateBodyPhysics();
        creatureStateBodyVisual  = new CreatureStateBodyVisual();

        var jsonNode = Bootstrap.GetDataStore().staticData.GetNode("creatures")[typeName]; //creatures

        if (null == jsonNode)
        {
            Bootstrap.Warn("creature not found:" + typeName, parent);
            return;
        }

        height = jsonNode["height"].AsFloat;
        //height = 0.5f;

        {
            var jsonBodyDataArray = jsonNode["body_data_array"];
            if ((null != jsonBodyDataArray) && (true == jsonBodyDataArray.IsArray))
            {
                for (int index = 0; index < jsonBodyDataArray.Count; ++index)
                {
                    var bodyData = BodyData.Factory(jsonBodyDataArray[index]);
                    bodyDataArray.Add(bodyData);
                    _mapBodyRadius[bodyData.m_name] = bodyData.m_radius * 0.5f;
                }
            }
        }
        {
            var jsonSplineDataArray = jsonNode["spline_data_array"];
            if ((null != jsonSplineDataArray) && (true == jsonSplineDataArray.IsArray))
            {
                for (int index = 0; index < jsonSplineDataArray.Count; ++index)
                {
                    splineDataArray.Add(SplineData.Factory(jsonSplineDataArray[index]));
                }
            }
        }
        {
            var jsonSphereDataArray = jsonNode["sphere_data_array"];
            if ((null != jsonSphereDataArray) && (true == jsonSphereDataArray.IsArray))
            {
                for (int index = 0; index < jsonSphereDataArray.Count; ++index)
                {
                    sphereDataArray.Add(SphereData.Factory(jsonSphereDataArray[index]));
                }
            }
        }

        faceData = FaceData.Factory(jsonNode);
    }
Ejemplo n.º 12
0
    private float calMeanError(List <Vector3> points, SphereData s)
    {
        float total_error = 0f;

        for (int i = 0; i < points.Count; i++)
        {
            float distance = Vector3.Distance(s.center, points[i]);
            total_error += Mathf.Abs(distance - s.radius);
        }

        total_error /= points.Count;

        return(total_error);
    }
Ejemplo n.º 13
0
    void OnEndSampling()
    {
        onSampling = false;
        // apply offset to SphereUI

        if (points.Count > 0)
        {
            hSphere = ransac_sphere(points, 0.001f);
            ActionEventManager.instance.setUpSphereUIs(hSphere, forwardAngle);
            Destroy(SphereUI);
            //clear the points visualizer
            spherepointvisualizer.clear();
        }
    }
Ejemplo n.º 14
0
    private float calStdError(List <Vector3> points, SphereData s)
    {
        float mean = calMeanError(points, s);
        float std  = 0;

        for (int i = 0; i < points.Count; i++)
        {
            float difference = Mathf.Abs(Vector3.Distance(s.center, points[i]) - s.radius);
            std += (difference - mean) * (difference - mean);
        }

        std /= points.Count;

        std = Mathf.Sqrt(std);

        return(std);
    }
    public void setUpSphereUIs(SphereData hSphere, float forwardAngle)
    {
        this.sphereData = hSphere;
        //[Modify]
        SphereRight = eyeCenter.transform.right;
        Vector3 hmdPosition = eyeCenter.transform.position;

        for (int i = 0; i < Sphere_UI.Length; i++)
        {
            Sphere_UI[i].transform.position         = hmdPosition + sphereData.center;
            Sphere_UI[i].transform.localScale       = 1.001f * (new Vector3(sphereData.radius / RADIUS_TO_SCALE_CONSTANS, sphereData.radius / RADIUS_TO_SCALE_CONSTANS, sphereData.radius / RADIUS_TO_SCALE_CONSTANS));
            Sphere_UI[i].transform.rotation         = Quaternion.identity;
            Sphere_UI[i].transform.localEulerAngles = new Vector3(0, eyeCenter.transform.localEulerAngles.y, 0);
            Sphere_UI[i].GetComponent <SphereCollider>().enabled = false;
            Sphere_UI[i].GetComponent <ButtonManagerApp>().setUpButtons(forwardAngle);
            Sphere_UI[i].SetActive(true);
        }
        this.forwardAngle = forwardAngle;
    }
Ejemplo n.º 16
0
    /// <summary>
    /// Builds the "head" of the flower (a sphere that sits on top of the stem).
    /// </summary>
    /// <param name="meshBuilder">The mesh builder currently being added to.</param>
    /// <param name="offset">The position offset to apply to the head (position at the top of the stem).</param>
    /// <param name="rotation">The rotation offset to apply to the head (rotation at the top of the stem).</param>
    /// <param name="partData">The parameters describing the sphere to be built.</param>
    private void BuildHead(MeshBuilder meshBuilder, Vector3 offset, Quaternion rotation, SphereData partData)
    {
        //bail if this part has been disabled:
        if (!partData.m_Build)
            return;

        //the angle increment per height segment:
        float angleInc = Mathf.PI / partData.m_HeightSegmentCount;

        //the vertical (scaled) radius of the sphere:
        float verticalRadius = partData.m_Radius * partData.m_VerticalScale;

        //build the rings:
        for (int i = 0; i <= partData.m_HeightSegmentCount; i++)
        {
            Vector3 centrePos = Vector3.zero;

            //calculate a height offset and radius based on a vertical circle calculation:
            centrePos.y = -Mathf.Cos(angleInc * i);
            float radius = Mathf.Sin(angleInc * i);

            //calculate the slope of the shpere at this ring based on the height and radius:
            Vector2 slope = new Vector3(-centrePos.y / partData.m_VerticalScale, radius);
            slope.Normalize();

            //multiply the unit height by the vertical radius, and then add the radius to the height to make this sphere originate from its base rather than its centre:
            centrePos.y = centrePos.y * verticalRadius + verticalRadius;

            //scale the radius by the one stored in the partData:
            radius *= partData.m_Radius;

            //calculate the final position of the ring centre:
            Vector3 finalRingCentre = rotation * centrePos + offset;

            //V coordinate:
            float v = (float)i / partData.m_HeightSegmentCount;

            //build the ring:
            BuildRing(meshBuilder, partData.m_RadialSegmentCount, finalRingCentre, radius, v, i > 0, rotation, slope);
        }
    }
Ejemplo n.º 17
0
 public Sphere(float _r, float _h, float _k, float _z)
 {
     Source = new SphereData(_r, _h, _k, _z);
     Attributes = new SphereAttributes();
 }
Ejemplo n.º 18
0
    /// <summary>
    /// Builds the "head" of the flower (a sphere that sits on top of the stem).
    /// </summary>
    /// <param name="meshBuilder">The mesh builder currently being added to.</param>
    /// <param name="offset">The position offset to apply to the head (position at the top of the stem).</param>
    /// <param name="rotation">The rotation offset to apply to the head (rotation at the top of the stem).</param>
    /// <param name="partData">The parameters describing the sphere to be built.</param>
    private void BuildHead(MeshBuilder meshBuilder, Vector3 offset, Quaternion rotation, SphereData partData)
    {
        //bail if this part has been disabled:
        if (!partData.m_Build)
        {
            return;
        }

        //the angle increment per height segment:
        float angleInc = Mathf.PI / partData.m_HeightSegmentCount;

        //the vertical (scaled) radius of the sphere:
        float verticalRadius = partData.m_Radius * partData.m_VerticalScale;

        //build the rings:
        for (int i = 0; i <= partData.m_HeightSegmentCount; i++)
        {
            Vector3 centrePos = Vector3.zero;

            //calculate a height offset and radius based on a vertical circle calculation:
            centrePos.y = -Mathf.Cos(angleInc * i);
            float radius = Mathf.Sin(angleInc * i);

            //calculate the slope of the shpere at this ring based on the height and radius:
            Vector2 slope = new Vector3(-centrePos.y / partData.m_VerticalScale, radius);
            slope.Normalize();

            //multiply the unit height by the vertical radius, and then add the radius to the height to make this sphere originate from its base rather than its centre:
            centrePos.y = centrePos.y * verticalRadius + verticalRadius;

            //scale the radius by the one stored in the partData:
            radius *= partData.m_Radius;

            //calculate the final position of the ring centre:
            Vector3 finalRingCentre = rotation * centrePos + offset;

            //V coordinate:
            float v = (float)i / partData.m_HeightSegmentCount;

            //build the ring:
            BuildRing(meshBuilder, partData.m_RadialSegmentCount, finalRingCentre, radius, v, i > 0, rotation, slope);
        }
    }
    // Start is called before the first frame update
    void Start()
    {
        //render出來的結果會被寫在m_RTTarget中
        //m_RTTarget = new RenderTexture(m_RTSize.x, m_RTSize.y, 0, UnityEngine.Experimental.Rendering.GraphicsFormat.R8G8B8A8_SRGB);

        //開出材質空間
        m_RTTarget = new RenderTexture(m_RTSize.x, m_RTSize.y, 0, UnityEngine.Experimental.Rendering.GraphicsFormat.R8G8B8A8_UNorm);
        m_RTTarget.enableRandomWrite = true;
        m_RTTarget.Create();

        m_QuadMaterial.SetTexture("_MainTex", m_RTTarget);

        //init a buffer in cpu menory
        m_SimpleAccelerationStructureDataBuffer = new ComputeBuffer(512, System.Runtime.InteropServices.Marshal.SizeOf(typeof(SphereData)));
        SphereData Data = new SphereData();


        //lambert sphere
        Data.Center                      = new Vector3(-2.0f, -1.0f, 0.0f);
        Data.Radius                      = 0.8f;
        Data.MaterialType                = (int)MaterialType.MAT_METAL;
        Data.MaterialAlbedo              = new Vector3(0.9f, 0.9f, 0.9f);
        Data.MaterialData                = new Vector4(0.0f, 0.0f, 0.0f, 0.0f);
        m_SphereArray[m_NumSpheres]      = Data;
        m_SphereTimeOffset[m_NumSpheres] = UnityEngine.Random.Range(0, 100.0f);
        m_NumSpheres++;

        //set data in cpu  memory
        m_SimpleAccelerationStructureDataBuffer.SetData(m_SphereArray);

        //load obj
        m_VertexDataBuffer = new ComputeBuffer(m_Mesh.GetIndices(0).Length / 3, System.Runtime.InteropServices.Marshal.SizeOf(typeof(FaceAttribute)));
        FaceAttribute[] m_VertexData = new FaceAttribute[m_Mesh.GetIndices(0).Length / 3];
        //Debug.Log(m_Mesh.GetIndices(0).Length);
        for (int i = 0; i < m_Mesh.GetIndices(0).Length / 3; i++)
        {
            m_VertexData[i].v0 = m_Mesh.vertices[m_Mesh.GetIndices(0)[3 * i]];
            m_VertexData[i].v1 = m_Mesh.vertices[m_Mesh.GetIndices(0)[3 * i + 1]];
            m_VertexData[i].v2 = m_Mesh.vertices[m_Mesh.GetIndices(0)[3 * i + 2]];

            //m_VertexData[i].v0.y += 1.0f;
            //m_VertexData[i].v1.y += 1.0f;
            //m_VertexData[i].v2.y += 1.0f;

            Vector3 v0v1 = m_VertexData[i].v1 - m_VertexData[i].v0;
            Vector3 v0v2 = m_VertexData[i].v2 - m_VertexData[i].v0;
            Vector3 N    = Vector3.Normalize(Vector3.Cross(v0v1, v0v2)); // N
            m_VertexData[i].normal = N;


            m_VertexData[i].MaterialType   = (int)MaterialType.MAT_METAL;
            m_VertexData[i].MaterialAlbedo = new Vector3(0.9f, 0.9f, 0.9f);
            m_VertexData[i].MaterialData   = new Vector4(0.0f, 0.0f, 0.0f, 0.0f);


            //Debug.Log((m_VertexData[i].v0.x, m_VertexData[i].v0.y, m_VertexData[i].v0.z));
            //Debug.Log((m_VertexData[i].v1.x, m_VertexData[i].v1.y, m_VertexData[i].v1.z));
            //Debug.Log((m_VertexData[i].v2.x, m_VertexData[i].v2.y, m_VertexData[i].v2.z));
            //Debug.Log((m_VertexData[i].normal.x, m_VertexData[i].normal.y, m_VertexData[i].normal.z));
            //Debug.Log("---------------------------------------------------------------------------------");
        }


        AABB[] mainOBJ_aabb = new AABB[1];
        mainOBJ_aabb[0] = FindAABB(ref m_VertexData);
        Debug.Log(((mainOBJ_aabb[0].X_axis), (mainOBJ_aabb[0].Y_axis), (mainOBJ_aabb[0].Z_axis)));
        m_AABBDataBuffer = new ComputeBuffer(1, System.Runtime.InteropServices.Marshal.SizeOf(typeof(AABB)));
        m_AABBDataBuffer.SetData(mainOBJ_aabb);

        m_VertexDataBuffer.SetData(m_VertexData);
        float m_TriangleNum = m_Mesh.GetIndices(0).Length / 3;
        int   KernelHandle  = m_ComputeShader.FindKernel("CSMain");

        m_ComputeShader.SetBuffer(KernelHandle, "FaceAttrib", m_VertexDataBuffer);
        m_ComputeShader.SetBuffer(KernelHandle, "objAABB", m_AABBDataBuffer);
        m_ComputeShader.SetTexture(KernelHandle, "_SkyboxTexture", m_Skybox);
        m_ComputeShader.SetFloat("TriangleNum", m_TriangleNum);

        //procedural texture
        noiseTex = new Texture2D(100, 100);
        pix      = new Color[noiseTex.width * noiseTex.height];
        CalcNoise();
        m_ComputeShader.SetTexture(KernelHandle, "_ProceduralTexture", noiseTex);
    }
Ejemplo n.º 20
0
    // Start is called before the first frame update
    void Start()
    {
        //m_RTTarget = new RenderTexture(m_RTSize.x, m_RTSize.y, 0, UnityEngine.Experimental.Rendering.GraphicsFormat.R8G8B8A8_SRGB);
        m_RTTarget = new RenderTexture(m_RTSize.x, m_RTSize.y, 0, UnityEngine.Experimental.Rendering.GraphicsFormat.R8G8B8A8_UNorm);
        m_RTTarget.enableRandomWrite = true;
        m_RTTarget.Create();
        m_QuadMaterial.SetTexture("_MainTex", m_RTTarget);

        m_WorldDataBuffer = new ComputeBuffer(512, System.Runtime.InteropServices.Marshal.SizeOf(typeof(SphereData)));

        SphereData Data = new SphereData();

        Data.Center                      = new Vector3(0, -1000.0f, 0.0f);
        Data.Radius                      = 1000.0f;
        Data.MaterialType                = (int)MaterialType.MAT_LAMBERTIAN;
        Data.MaterialAlbedo              = new Vector3(0.5f, 0.5f, 0.5f);
        m_SphereArray[m_NumSpheres]      = Data;
        m_SphereTimeOffset[m_NumSpheres] = UnityEngine.Random.Range(0, 100.0f);
        m_NumSpheres++;

        Data.Center                      = new Vector3(0, 1.0f, 0.0f);
        Data.Radius                      = 1.0f;
        Data.MaterialType                = (int)MaterialType.MAT_DIELECTRIC;
        Data.MaterialAlbedo              = new Vector3(0.1f, 0.2f, 0.5f);
        Data.MaterialData                = new Vector4(1.5f, 0.0f, 0.0f, 0.0f);
        m_SphereArray[m_NumSpheres]      = Data;
        m_SphereTimeOffset[m_NumSpheres] = UnityEngine.Random.Range(0, 100.0f);
        m_NumSpheres++;

        Data.Center                      = new Vector3(-4.0f, 1.0f, 0.0f);
        Data.Radius                      = 1.0f;
        Data.MaterialType                = (int)MaterialType.MAT_LAMBERTIAN;
        Data.MaterialAlbedo              = new Vector3(0.4f, 0.2f, 0.1f);
        Data.MaterialData                = new Vector4(1.0f, 0.0f, 0.0f, 0.0f);
        m_SphereArray[m_NumSpheres]      = Data;
        m_SphereTimeOffset[m_NumSpheres] = UnityEngine.Random.Range(0, 100.0f);
        m_NumSpheres++;

        Data.Center                      = new Vector3(4.0f, 1.0f, 0.0f);
        Data.Radius                      = 1.0f;
        Data.MaterialType                = (int)MaterialType.MAT_METAL;
        Data.MaterialAlbedo              = new Vector3(0.7f, 0.6f, 0.5f);
        Data.MaterialData                = new Vector4(0.0f, 0.0f, 0.0f, 0.0f);
        m_SphereArray[m_NumSpheres]      = Data;
        m_SphereTimeOffset[m_NumSpheres] = UnityEngine.Random.Range(0, 100.0f);
        m_NumSpheres++;

        for (int a = -4; a < 5; a++)
        {
            for (int b = -4; b < 4; b++)
            {
                float   Choose_Mat = UnityEngine.Random.Range(0, 1.0f);
                Vector3 Center     = new Vector3(a * 1.5f + 1.5f * UnityEngine.Random.Range(0, 1.0f), 0.2f, b * 1.0f + 1.0f * UnityEngine.Random.Range(0, 1.0f));
                Vector3 Dist       = Center - new Vector3(4, 0.2f, 0);
                if (Dist.magnitude > 0.9f)
                {
                    if (Choose_Mat < 0.5f)
                    {
                        // diffuse
                        Vector3 Albedo = new Vector3(UnityEngine.Random.Range(0, 1.0f), UnityEngine.Random.Range(0, 1.0f), UnityEngine.Random.Range(0, 1.0f));
                        Data.Center         = Center;
                        Data.Radius         = 0.2f;
                        Data.MaterialType   = (int)MaterialType.MAT_LAMBERTIAN;
                        Data.MaterialAlbedo = Albedo;
                        Data.MaterialData   = new Vector4(0.0f, 0.0f, 0.0f, 0.0f);
                    }
                    else if (Choose_Mat < 0.8f)
                    {
                        // metal
                        Vector3 Albedo = new Vector3(UnityEngine.Random.Range(0, 1.0f), UnityEngine.Random.Range(0, 1.0f), UnityEngine.Random.Range(0, 1.0f));
                        float   Fuzz   = UnityEngine.Mathf.Min(UnityEngine.Random.Range(0, 1.0f), 0.5f);
                        Data.Center         = Center;
                        Data.Radius         = 0.2f;
                        Data.MaterialType   = (int)MaterialType.MAT_METAL;
                        Data.MaterialAlbedo = Albedo;
                        Data.MaterialData   = new Vector4(Fuzz, 0.0f, 0.0f, 0.0f);
                    }
                    else
                    {
                        Data.Center       = Center;
                        Data.Radius       = 0.2f;
                        Data.MaterialType = (int)MaterialType.MAT_DIELECTRIC;
                        Data.MaterialData = new Vector4(1.5f, 0.0f, 0.0f, 0.0f);
                    }
                    m_SphereArray[m_NumSpheres]      = Data;
                    m_SphereTimeOffset[m_NumSpheres] = UnityEngine.Random.Range(0, 100.0f);
                    m_NumSpheres++;
                }
            }
        }
        m_WorldDataBuffer.SetData(m_SphereArray);
    }
Ejemplo n.º 21
0
        public override void Initialise(Device device, BufferManager bufferManager)
        {
            var vertShaderData = LoadShaderData(".\\Shaders\\BasicShader.vert.spv", out int vertCodeSize);

            this.vertexShader = device.CreateShaderModule(new ShaderModuleCreateInfo
            {
                Code     = vertShaderData,
                CodeSize = vertCodeSize
            });

            var fragShaderData = LoadShaderData(".\\Shaders\\BasicShader.frag.spv", out int fragCodeSize);

            this.fragmentShader = device.CreateShaderModule(new ShaderModuleCreateInfo
            {
                Code     = fragShaderData,
                CodeSize = fragCodeSize
            });

            SphereData.Get(6, out var vertices, out var indices);

            var vertexData = vertices.Select(x => new Vertex(x.Item1, x.Item2, x.Item3, x.Item4)).ToArray();

            indexCount = indices.Count();

            this.vertexBuffer = bufferManager.CreateBuffer(MemUtil.SizeOf <Vertex>() * (uint)vertexData.Length, BufferUsageFlags.TransferDestination | BufferUsageFlags.VertexBuffer, MemoryPropertyFlags.DeviceLocal);

            this.vertexBuffer.Update(vertexData);

            this.indexBuffer = bufferManager.CreateBuffer(MemUtil.SizeOf <uint>() * (uint)indices.Length, BufferUsageFlags.TransferDestination | BufferUsageFlags.IndexBuffer, MemoryPropertyFlags.DeviceLocal);

            this.indexBuffer.Update(indices);

            this.uniformBuffer = bufferManager.CreateBuffer(MemUtil.SizeOf <UniformBufferObject>(), BufferUsageFlags.TransferDestination | BufferUsageFlags.UniformBuffer, MemoryPropertyFlags.DeviceLocal);

            this.descriptorPool = device.CreateDescriptorPool(new DescriptorPoolCreateInfo
            {
                PoolSizes = new[]
                {
                    new DescriptorPoolSize
                    {
                        DescriptorCount = 1,
                        Type            = DescriptorType.UniformBuffer
                    }
                },
                MaxSets = 1
            });

            this.descriptorSetLayout = device.CreateDescriptorSetLayout(new DescriptorSetLayoutCreateInfo
            {
                Bindings = new[]
                {
                    new DescriptorSetLayoutBinding
                    {
                        Binding         = 0,
                        DescriptorType  = DescriptorType.UniformBuffer,
                        StageFlags      = ShaderStageFlags.AllGraphics,
                        DescriptorCount = 1
                    }
                }
            });

            this.descriptorSet = device.AllocateDescriptorSets(new DescriptorSetAllocateInfo
            {
                DescriptorPool = descriptorPool,
                SetLayouts     = new[]
                {
                    this.descriptorSetLayout
                }
            }).Single();

            device.UpdateDescriptorSets(
                new WriteDescriptorSet
            {
                BufferInfo = new[]
                {
                    new DescriptorBufferInfo
                    {
                        Buffer = this.uniformBuffer.Buffer,
                        Offset = 0,
                        Range  = MemUtil.SizeOf <UniformBufferObject>()
                    }
                },
                DestinationSet          = descriptorSet,
                DestinationBinding      = 0,
                DestinationArrayElement = 0,
                DescriptorType          = DescriptorType.UniformBuffer
            }, null);

            this.pipelineLayout = device.CreatePipelineLayout(new PipelineLayoutCreateInfo()
            {
                SetLayouts = new[]
                {
                    this.descriptorSetLayout
                }
            });
        }
Ejemplo n.º 22
0
    // Start is called before the first frame update
    void Start()
    {
        m_SimpleAccelerationStructureDataBuffer = new ComputeBuffer(512, System.Runtime.InteropServices.Marshal.SizeOf(typeof(SphereData)), ComputeBufferType.Default);

        SphereData Data = new SphereData();

        Color[] Colors;
        Mesh    SphereMesh;

        Data.Center                      = new Vector3(0, 1.0f, 0.0f);
        Data.Radius                      = 1.0f;
        Data.MaterialType                = (int)MaterialType.MAT_DIELECTRIC;
        Data.MaterialAlbedo              = new Vector3(0.1f, 0.2f, 0.5f);
        Data.MaterialData                = new Vector4(1.5f, 0.0f, 0.0f, 0.0f);
        m_SphereArray[m_NumSpheres]      = Data;
        m_SphereTimeOffset[m_NumSpheres] = UnityEngine.Random.Range(0, 100.0f);
        m_SphereGOArray[m_NumSpheres]    = GameObject.CreatePrimitive(PrimitiveType.Sphere);
        m_SphereGOArray[m_NumSpheres].transform.localPosition            = Data.Center;
        m_SphereGOArray[m_NumSpheres].transform.localScale               = new Vector3(Data.Radius * 2.0f, Data.Radius * 2.0f, Data.Radius * 2.0f);
        m_SphereGOArray[m_NumSpheres].GetComponent <Renderer>().material = m_Material;
        SphereMesh = m_SphereGOArray[m_NumSpheres].GetComponent <MeshFilter>().mesh;
        Colors     = new Color[SphereMesh.vertices.Length];
        for (int i = 0; i < SphereMesh.vertices.Length; i++)
        {
            Colors[i] = new Color(Data.MaterialAlbedo.x, Data.MaterialAlbedo.y, Data.MaterialAlbedo.z, 1.0f);
        }
        SphereMesh.colors = Colors;
        m_NumSpheres++;

        Data.Center                      = new Vector3(-4.0f, 1.0f, 0.0f);
        Data.Radius                      = 1.0f;
        Data.MaterialType                = (int)MaterialType.MAT_LAMBERTIAN;
        Data.MaterialAlbedo              = new Vector3(0.4f, 0.2f, 0.1f);
        Data.MaterialData                = new Vector4(1.0f, 0.0f, 0.0f, 0.0f);
        m_SphereArray[m_NumSpheres]      = Data;
        m_SphereTimeOffset[m_NumSpheres] = UnityEngine.Random.Range(0, 100.0f);
        m_SphereGOArray[m_NumSpheres]    = GameObject.CreatePrimitive(PrimitiveType.Sphere);
        m_SphereGOArray[m_NumSpheres].transform.localPosition            = Data.Center;
        m_SphereGOArray[m_NumSpheres].transform.localScale               = new Vector3(Data.Radius * 2.0f, Data.Radius * 2.0f, Data.Radius * 2.0f);
        m_SphereGOArray[m_NumSpheres].GetComponent <Renderer>().material = m_Material;
        SphereMesh = m_SphereGOArray[m_NumSpheres].GetComponent <MeshFilter>().mesh;
        Colors     = new Color[SphereMesh.vertices.Length];
        for (int i = 0; i < SphereMesh.vertices.Length; i++)
        {
            Colors[i] = new Color(Data.MaterialAlbedo.x, Data.MaterialAlbedo.y, Data.MaterialAlbedo.z, 1.0f);
        }
        SphereMesh.colors = Colors;
        m_NumSpheres++;

        Data.Center                      = new Vector3(4.0f, 1.0f, 0.0f);
        Data.Radius                      = 1.0f;
        Data.MaterialType                = (int)MaterialType.MAT_METAL;
        Data.MaterialAlbedo              = new Vector3(0.7f, 0.6f, 0.5f);
        Data.MaterialData                = new Vector4(0.0f, 0.0f, 0.0f, 0.0f);
        m_SphereArray[m_NumSpheres]      = Data;
        m_SphereTimeOffset[m_NumSpheres] = UnityEngine.Random.Range(0, 100.0f);
        m_SphereGOArray[m_NumSpheres]    = GameObject.CreatePrimitive(PrimitiveType.Sphere);
        m_SphereGOArray[m_NumSpheres].transform.localPosition            = Data.Center;
        m_SphereGOArray[m_NumSpheres].transform.localScale               = new Vector3(Data.Radius * 2.0f, Data.Radius * 2.0f, Data.Radius * 2.0f);
        m_SphereGOArray[m_NumSpheres].GetComponent <Renderer>().material = m_Material;
        SphereMesh = m_SphereGOArray[m_NumSpheres].GetComponent <MeshFilter>().mesh;
        Colors     = new Color[SphereMesh.vertices.Length];
        for (int i = 0; i < SphereMesh.vertices.Length; i++)
        {
            Colors[i] = new Color(Data.MaterialAlbedo.x, Data.MaterialAlbedo.y, Data.MaterialAlbedo.z, 1.0f);
        }
        SphereMesh.colors = Colors;
        m_NumSpheres++;

        for (int a = -4; a < 5; a++)
        {
            for (int b = -4; b < 4; b++)
            {
                float   Choose_Mat = UnityEngine.Random.Range(0, 1.0f);
                Vector3 Center     = new Vector3(a * 1.5f + 1.5f * UnityEngine.Random.Range(0, 1.0f), 0.2f, b * 1.0f + 1.0f * UnityEngine.Random.Range(0, 1.0f));
                Vector3 Dist       = Center - new Vector3(4, 0.2f, 0);
                if (Dist.magnitude > 0.9f)
                {
                    if (Choose_Mat < 0.5f)
                    {
                        // diffuse
                        Vector3 Albedo = new Vector3(UnityEngine.Random.Range(0, 1.0f), UnityEngine.Random.Range(0, 1.0f), UnityEngine.Random.Range(0, 1.0f));
                        Data.Center         = Center;
                        Data.Radius         = 0.2f;
                        Data.MaterialType   = (int)MaterialType.MAT_LAMBERTIAN;
                        Data.MaterialAlbedo = Albedo;
                        Data.MaterialData   = new Vector4(0.0f, 0.0f, 0.0f, 0.0f);
                    }
                    else if (Choose_Mat < 0.8f)
                    {
                        // metal
                        Vector3 Albedo = new Vector3(UnityEngine.Random.Range(0, 1.0f), UnityEngine.Random.Range(0, 1.0f), UnityEngine.Random.Range(0, 1.0f));
                        float   Fuzz   = UnityEngine.Mathf.Min(UnityEngine.Random.Range(0, 1.0f), 0.5f);
                        Data.Center         = Center;
                        Data.Radius         = 0.2f;
                        Data.MaterialType   = (int)MaterialType.MAT_METAL;
                        Data.MaterialAlbedo = Albedo;
                        Data.MaterialData   = new Vector4(Fuzz, 0.0f, 0.0f, 0.0f);
                    }
                    else
                    {
                        Data.Center       = Center;
                        Data.Radius       = 0.2f;
                        Data.MaterialType = (int)MaterialType.MAT_DIELECTRIC;
                        Data.MaterialData = new Vector4(1.5f, 0.0f, 0.0f, 0.0f);
                    }
                    m_SphereArray[m_NumSpheres]      = Data;
                    m_SphereTimeOffset[m_NumSpheres] = UnityEngine.Random.Range(0, 100.0f);
                    m_SphereGOArray[m_NumSpheres]    = GameObject.CreatePrimitive(PrimitiveType.Sphere);
                    m_SphereGOArray[m_NumSpheres].transform.localPosition            = Data.Center;
                    m_SphereGOArray[m_NumSpheres].transform.localScale               = new Vector3(Data.Radius * 2.0f, Data.Radius * 2.0f, Data.Radius * 2.0f);
                    m_SphereGOArray[m_NumSpheres].GetComponent <Renderer>().material = m_Material;
                    SphereMesh = m_SphereGOArray[m_NumSpheres].GetComponent <MeshFilter>().mesh;
                    Colors     = new Color[SphereMesh.vertices.Length];
                    for (int i = 0; i < SphereMesh.vertices.Length; i++)
                    {
                        Colors[i] = new Color(Data.MaterialAlbedo.x, Data.MaterialAlbedo.y, Data.MaterialAlbedo.z, 1.0f);
                    }
                    SphereMesh.colors = Colors;
                    m_NumSpheres++;
                }
            }
        }
        m_SimpleAccelerationStructureDataBuffer.SetData(m_SphereArray);

        Camera.main.transform.localPosition = new Vector3(13, 2, -3);
        Camera.main.transform.LookAt(new Vector3(0, 0, 0));
    }
Ejemplo n.º 23
0
        private Color GetColor(float3 pixelPos)
        {
            // Create ray from camera position to pixel position
            // e + t * d (where e is origin)
            float3 d = normalize(pixelPos - CameraPosition);
            float3 e = CameraPosition;

            // Find closest intersection point
            float              closestt = 1000000;
            float3             closestIntersectionPoint  = new float3(0, 0, 0);
            float3             closestIntersectionNormal = new float3(0, 0, 0);
            ObjectLightingData lightingData = new ObjectLightingData();

            // Loop Spheres
            for (int i = 0; i < Spheres.Length; i++)  // No foreachs in jobs
            {
                SphereData sphere = Spheres[i];

                // Using ray-sphere intersection equation
                float3 c = sphere.Position;
                float  R = sphere.Radius;

                float3 eminusc      = e - c;
                float  ddoteminusc  = dot(d, eminusc);
                float  descriminant = ddoteminusc * ddoteminusc - dot(d, d) * (dot(eminusc, eminusc) - R * R);
                if (descriminant < 0)
                {
                    // No hit
                    continue;
                }

                float sqrtdesc = sqrt(descriminant);
                float plust    = (-ddoteminusc + sqrtdesc) / dot(d, d);
                float minust   = (-ddoteminusc - sqrtdesc) / dot(d, d);

                if (plust > 0 && minust > 0)
                {
                    // In front of camera
                    float t = min(plust, minust);
                    if (t < closestt)
                    {
                        closestIntersectionPoint  = e + t * d;
                        closestIntersectionNormal = (closestIntersectionPoint - c) / R;
                        closestt     = t;
                        lightingData = sphere.LightingData;
                    }
                }
                else if (plust > 0 && minust < 0 || plust < 0 && minust > 0)
                {
                    // Inside circle
                }
                else if (plust < 0 && minust < 0)
                {
                    // Circle is behind camera.
                }
            }

            // Loop Triangles
            for (int i = 0; i < Triangles.Length; i++)
            {
                // No foreachs in jobs
                SingleTriangleData triangle = Triangles[i];

                float3 a = triangle.a;
                float3 b = triangle.b;
                float3 c = triangle.c;

                float detA = determinant(
                    float3x3(a.x - b.x, a.x - c.x, d.x,
                             a.y - b.y, a.y - c.y, d.y,
                             a.z - b.z, a.z - c.z, d.z));

                // Compute t
                float t = determinant(
                    float3x3(a.x - b.x, a.x - c.x, a.x - e.x,
                             a.y - b.y, a.y - c.y, a.y - e.y,
                             a.z - b.z, a.z - c.z, a.z - e.z)) /
                          detA;

                if (t < 0 || t > closestt)
                {
                    continue;
                }

                // Compute gamma
                float gamma = determinant(
                    float3x3(a.x - b.x, a.x - e.x, d.x,
                             a.y - b.y, a.y - e.y, d.y,
                             a.z - b.z, a.z - e.z, d.z)) /
                              detA;

                if (gamma < 0 || gamma > 1)
                {
                    continue;
                }

                // Compute beta
                float beta = determinant(
                    float3x3(a.x - e.x, a.x - c.x, d.x,
                             a.y - e.y, a.y - c.y, d.y,
                             a.z - e.z, a.z - c.z, d.z)) /
                             detA;

                if (beta < 0 || beta > 1 - gamma)
                {
                    continue;
                }

                closestt = t;
                closestIntersectionPoint  = e + t * d;
                closestIntersectionNormal = normalize(cross(c - a, b - a));
                lightingData = triangle.LightingData;
            }

            // Sphong Blinn Shading with no ambient lighting
            if (closestt < 1000000)
            {
                float3 p = closestIntersectionPoint;
                float3 n = closestIntersectionNormal;

                // v = direction from point to viewers eye
                float3 v = normalize(e - closestIntersectionPoint);

                Color color = new Color(0, 0, 0, 1);

                // It's been hit! Calculate the color based on lighting
                for (int j = 0; j < Lights.Length; j++)
                {
                    LightingData light = Lights[j];

                    // l = vector from light to intersect point
                    float3 l = normalize(light.Position - p);

                    // h = half vector to light source
                    float3 h = normalize(v + l);
                    color += lightingData.diffuseCoefficient * light.Color * max(0, dot(n, l)) +
                             lightingData.specularCoefficient * light.Color *
                             pow(max(0, dot(n, h)), lightingData.phongExponent);
                }

                return(color);
            }
            return(BackgroundColor);
        }
Ejemplo n.º 24
0
    void Update()
    {
        //[Modify]

        // For Sampling
        if (onSampling)
        {
            PointsSampling();
        }

        #region ComputerInputs

        //[Keyboard]
        //Start Sampling "Enter"
        if (Input.GetKeyDown(KeyCode.Return))
        {
            print("Start sampling!");
            //targetPosition.setUseHand();
            spherepointvisualizer.clear();
            onSampling = true;
        }

        //End Sampling "Enter"
        if (Input.GetKeyUp(KeyCode.Return))
        {
            print("End of sampling");
            onSampling = false;
            // apply offset to SphereUI

            if (points.Count > 0)
            {
                hSphere = ransac_sphere(points, 0.001f);
                ActionEventManager.instance.setUpSphereUIs(hSphere, forwardAngle);
                Destroy(SphereUI);
                //clear the points visualizer
                spherepointvisualizer.clear();
            }
        }

        //Set the user's facing angle and setup the inital sphere(SphereUI0) (HMD Case)
        if (Input.GetKeyDown(KeyCode.F))
        {
            //[Modify]
            forwardAngle = eyeCenter.transform.localEulerAngles.y;
            CalibrationButtons.instance.setForwardAngle(forwardAngle);
            resetSphereUI();
            hSphere.radius = defaultRadius;
            hSphere.center = Vector3.zero;

            initSphereUI();
        }

        //Load from Data "L"
        if (Input.GetKeyDown(KeyCode.L))
        {
            SphereData sphereload = SphereDataLoader.loadSphere();
            //There is a loading file
            if (sphereload.radius != -1)
            {
                hSphere = sphereload;
                ActionEventManager.instance.setUpSphereUIs(hSphere, forwardAngle);
                Destroy(SphereUI);
            }
        }
        //Save the current SphereUI data "S"
        if (Input.GetKeyDown(KeyCode.S))
        {
            SphereDataWriter.writeSphereData(hSphere.center, hSphere.radius);
        }

        #endregion
    }
Ejemplo n.º 25
0
        public async Task Exrep([Remainder] string msg)
        {
            var json = new GetInfo().GetExpansionInfo(msg).Result;

            JArray sphereObj;

            try
            {
                sphereObj = JArray.Parse(json);
            }
            catch (Exception e)
            {
                Console.WriteLine("System " + msg + " was not found!");
                return;
            }

            List <SphereData> systems = new List <SphereData>();

            foreach (var result in sphereObj)
            {
                SphereData sphereData = result.ToObject <SphereData>();
                systems.Add(sphereData);
            }

            // Check to ensure a faction has already been set
            if (string.IsNullOrEmpty(Config.Bot.Faction))
            {
                await Context.Channel.SendMessageAsync(
                    "`No faction is set! Contact the bot maintainer to configure this bot for a faction.`");
            }

            await Context.Channel.SendMessageAsync(
                "`This can take some time; please be patient!`");

            // Sort by distance
            var sorted =
                from system in systems
                orderby system.distance
                select system;

            int originCheck = 0;

            foreach (var s in sorted)
            {
                // Grab system data
                var        systemJson = new GetInfo().GetSystemInfo(s.name).Result;
                SystemData system;

                // Check for bad results
                try
                {
                    system = JsonConvert.DeserializeObject <SystemData>(systemJson);
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                    throw;
                }

                // Check if the faction in the config file is at the system checked, and warn.
                if (system.name == Config.Bot.Faction & originCheck == 0)
                {
                    originCheck++;
                    await Context.Channel.SendMessageAsync("`Warning: " + Config.Bot.Faction + " is not in " +
                                                           system.factions[0].name + "!`");
                }

                //Check the the number of factions and if the configured faction occupies the system
                int total           = 0;
                int occupiedAlready = 0;
//                Console.WriteLine("System Name: " + s.name);
//                Console.WriteLine("Distance: " + s.distance);
//                Console.WriteLine("Factions:");
                foreach (var f in system.factions)
                {
//                    Console.WriteLine(f.name);
                    if (f.influence > 0.00)
                    {
                        total++;
                    }

                    if (f.name == Config.Bot.Faction)
                    {
//                        Console.WriteLine("Occupied by " + Config.Bot.Faction);
                        occupiedAlready = 1;
                    }
                }

//                Console.WriteLine("Total Factions: " + total);
//                Console.WriteLine("-------");
                if (total < 7 && total > 0 && occupiedAlready != 1
                    & s.name != "Sol" & s.name != "Sirius") // Some special systems don't follow the rules.
                {
                    await Context.Channel.SendMessageAsync("`" + s.name.ToUpper() + " is the most likely expansion candidate for "
                                                           + Config.Bot.Faction.ToUpper() + " in " + msg.ToUpper() + ".`");

                    await Context.Channel.SendMessageAsync("`Distance: " + s.distance + "ly`");
                    await Sitrep(s.name);

                    return; // Since we're sorted by distance, stop at the first hit.
                }
            }
            // This will only trigger if no systems are found that are available for expansion.
            await Context.Channel.SendMessageAsync("`No expansion candidate found for " + msg.ToUpper() + ".`");
        }