Ejemplo n.º 1
0
    public GameObject CreateLight(DetectionBox box, Vector3 hitPoint, bool debug = false)
    {
        if (PointLightPrefab == null)
        {
            Debug.Log("please assign to light prefab.");
            return(null);
        }

        GameObject lightObject = Instantiate(PointLightPrefab);

        lightObject.transform.position    = hitPoint;
        lightObject.transform.eulerAngles = Quaternion.identity.eulerAngles;
        lightObject.transform.SetParent(this.gameObject.transform);

        LightInfo lightInfo = new LightInfo()
        {
            position = lightObject.transform.position,
            rotation = lightObject.transform.eulerAngles,
            light    = ApplyLightProperties(lightObject, box),
            collider = lightObject.GetComponent <BoxCollider>()
        };

        AddLight(lightInfo);

        if (debug)
        {
            CreateDebugBox(lightInfo, box);
        }

        return(lightObject);
    }
Ejemplo n.º 2
0
    private Light ApplyLightProperties(GameObject lightObject, DetectionBox box)
    {
        Light light = lightObject.GetComponent <Light>();

        light.type      = GetLightType(box.id);
        light.intensity = GetLightIntensity(box.intensity);
        light.color     = GetColorTemperature(box.color);

        return(light);
    }
Ejemplo n.º 3
0
    public DetectionBox[] ParseToBoxes()
    {
        if (xmlPath == null)
        {
            return(null);
        }


        XmlDocument xmlDocument = new XmlDocument();

        xmlDocument.Load(xmlPath);

        XmlNodeList xmlList = xmlDocument.SelectNodes(SELECT_NODE_NAME);

        string[] parseData = new string[xmlList.Count];

        DetectionBox[] boxes = new DetectionBox[xmlList.Count];
        XmlNode        node  = null;

        for (int i = 0; i < xmlList.Count; i++)
        {
            node = xmlList[i];

            boxes[i] = new DetectionBox()
            {
                id = int.Parse(node[ID].InnerText),

                score = float.Parse(node[SCORE].InnerText),

                min = new Vector2()
                {
                    x = float.Parse(node[BOX][X_MIN].InnerText),
                    y = float.Parse(node[BOX][Y_MIN].InnerText)
                },

                max = new Vector2()
                {
                    x = float.Parse(node[BOX][X_MAX].InnerText),
                    y = float.Parse(node[BOX][Y_MAX].InnerText)
                },

                color = new Color()
                {
                    r = float.Parse(node[COLOR][R].InnerText),
                    g = float.Parse(node[COLOR][G].InnerText),
                    b = float.Parse(node[COLOR][B].InnerText),
                },

                intensity = float.Parse(node[INTENSITY].InnerText)
            };
        }

        return(boxes);
    }
Ejemplo n.º 4
0
    public GameObject CreateDebugBox(LightInfo lightInfo, DetectionBox originInfo)
    {
        GameObject debugBox = Instantiate(DebugBoxPrefab);

        debugBox.transform.SetParent(DebugCanvasTransform);
        debugBox.transform.position = lightInfo.position;

        string          lightType       = (originInfo.id == 1 ? "Area" : (originInfo.id == 2 ? "Point" : "Spot"));
        DebugBoxManager debugBoxManager = debugBox.GetComponent <DebugBoxManager>() as DebugBoxManager;

        debugBoxManager.SetParams(lightType, lightInfo.light.intensity, lightInfo.light.color);

        return(debugBox);
    }
Ejemplo n.º 5
0
    InferenceResult ParseData(string data)
    {
        string[] parts;
        string[] hmdPositionRaw;
        string[] hmdRotationRaw;
        string[] boxes;

        Vector3 hmdPosition, hmdRotation;

        DetectionBox[]  detectionBoxes;
        InferenceResult result = null;

        try
        {
            parts = data.Split(':');

            hmdPositionRaw = parts[0].Split('|');
            hmdPosition    = RawToVector3(hmdPositionRaw);

            hmdRotationRaw = parts[1].Split('|');
            hmdRotation    = RawToVector3(hmdRotationRaw);

            boxes = parts[2].Split('\\');

            detectionBoxes = new DetectionBox[boxes.Length];
            for (int i = 0; i < boxes.Length; i++)
            {
                string[] boxData = boxes[i].Split('|');
                detectionBoxes[i] = new DetectionBox(boxData);
            }

            result = new InferenceResult(hmdPosition, hmdRotation, detectionBoxes);
        }
        catch
        {
            result = null;
        }

        return(result);
    }