Пример #1
0
    public ModelResource getRenderModelResource(string renderModel, ModelSpecify ms, bool merge)
    {
        foreach (ModelResource t in renderModelList)
        {
            if ((t.renderModelName == renderModel) && (t.mergeToOne == merge) && (t.modelSpecify == ms))
            {
                return(t);
            }
        }

        return(null);
    }
Пример #2
0
    public bool isRenderModelExist(string renderModel, ModelSpecify ms, bool merge)
    {
        foreach (ModelResource t in renderModelList)
        {
            if ((t.renderModelName == renderModel) && (t.mergeToOne == merge) && (t.modelSpecify == ms))
            {
                return(true);
            }
        }

        return(false);
    }
Пример #3
0
    void OnEnable()
    {
        PrintDebugLog("OnEnable");
        if (mLoadingState == LoadingState.LoadingState_LOADING)
        {
            deleteChild("RenderModel doesn't expect model is in loading, delete all children");
        }

        if (WhichHand == ControllerHand.Controller_Dominant)
        {
            deviceType   = WaveVR_Controller.EDeviceType.Dominant;
            modelSpecify = ModelSpecify.MS_Dominant;
        }
        else
        {
            deviceType   = WaveVR_Controller.EDeviceType.NonDominant;
            modelSpecify = ModelSpecify.MS_NonDominant;
        }

        connected = checkConnection();

        if (connected)
        {
            WaveVR.Device _device = WaveVR.Instance.getDeviceByType(this.deviceType);

            if (mLoadingState == LoadingState.LoadingState_LOADED)
            {
                if (isRenderModelNameSameAsPrevious())
                {
                    PrintDebugLog("OnEnable - Controller connected, model was loaded!");
                }
                else
                {
                    deleteChild("Controller load when OnEnable, render model is different!");
                    onLoadController(_device.type);
                }
            }
            else
            {
                PrintDebugLog("Controller load when OnEnable!");
                onLoadController(_device.type);
            }
        }

        WaveVR_Utils.Event.Listen(WaveVR_Utils.Event.DEVICE_CONNECTED, onDeviceConnected);
        WaveVR_Utils.Event.Listen(WaveVR_Utils.Event.OEM_CONFIG_CHANGED, onOEMConfigChanged);
    }
Пример #4
0
    bool getBatteryIndicatorParam(ModelResource curr, string modelFolderPath, ModelSpecify ms)
    {
        if (curr == null)
        {
            PrintWarningLog("Model resource is null!");
            return(false);
        }

        string batteryJsonFile = modelFolderPath + "/";

        if (ms == ModelSpecify.MS_Dominant)
        {
            batteryJsonFile += "BatteryIndicator.json";
        }
        else
        {
            batteryJsonFile += "BatteryIndicator01.json";
        }

        if (!File.Exists(batteryJsonFile))
        {
            PrintWarningLog(batteryJsonFile + " is not found!");
            return(false);
        }

        StreamReader json_sr = new StreamReader(batteryJsonFile);

        string JsonString = json_sr.ReadToEnd();

        PrintInfoLog("BatteryIndicator json: " + JsonString);
        json_sr.Close();

        if (JsonString.Equals(""))
        {
            PrintWarningLog("JsonString is empty!");
            return(false);
        }

        SimpleJSON.JSONNode jsNodes = SimpleJSON.JSONNode.Parse(JsonString);

        string tmpStr = "";

        tmpStr = jsNodes["LevelCount"].Value;

        if (tmpStr.Equals(""))
        {
            PrintWarningLog("Battery level is not found!");
            return(false);
        }

        int batteryLevel = int.Parse(tmpStr);

        PrintInfoLog("Battery level is " + batteryLevel);

        if (batteryLevel <= 0)
        {
            PrintWarningLog("Battery level is less or equal to 0!");
            return(false);
        }
        List <BatteryIndicator> batteryTextureList = new List <BatteryIndicator>();

        for (int i = 0; i < batteryLevel; i++)
        {
            string minStr  = jsNodes["BatteryLevel"][i]["min"].Value;
            string maxStr  = jsNodes["BatteryLevel"][i]["max"].Value;
            string pathStr = jsNodes["BatteryLevel"][i]["path"].Value;

            if (minStr.Equals("") || maxStr.Equals("") || pathStr.Equals(""))
            {
                PrintWarningLog("Min, Max or Path is not found!");
                batteryLevel = 0;
                batteryTextureList.Clear();
                return(false);
            }

            string batteryLevelFile = modelFolderPath + "/" + pathStr;

            if (!File.Exists(batteryLevelFile))
            {
                PrintWarningLog(batteryLevelFile + " is not found!");
                batteryLevel = 0;
                batteryTextureList.Clear();
                return(false);
            }

            BatteryIndicator tmpBI = new BatteryIndicator();
            tmpBI.level       = i;
            tmpBI.min         = float.Parse(minStr);
            tmpBI.max         = float.Parse(maxStr);
            tmpBI.texturePath = batteryLevelFile;

            byte[] imgByteArray = File.ReadAllBytes(batteryLevelFile);
            PrintDebugLog("Image size: " + imgByteArray.Length);

            tmpBI.batteryTexture = new Texture2D(2, 2, TextureFormat.BGRA32, false);
            tmpBI.textureLoaded  = tmpBI.batteryTexture.LoadImage(imgByteArray);

            PrintInfoLog("Battery Level: " + tmpBI.level + " min: " + tmpBI.min + " max: " + tmpBI.max + " path: " + tmpBI.texturePath + " loaded: " + tmpBI.textureLoaded);

            batteryTextureList.Add(tmpBI);
        }

        curr.batteryTextureList = batteryTextureList;
        PrintInfoLog("BatteryIndicator is ready!");
        return(true);
    }
Пример #5
0
    private bool GetTouchPadParam(ModelResource curr, string modelFolderPath, ModelSpecify ms)
    {
        if (curr == null)
        {
            PrintWarningLog("Model resource is null!");
            return(false);
        }

        string TouchPadJsonPath = modelFolderPath + "/";

        if (ms == ModelSpecify.MS_Dominant)
        {
            TouchPadJsonPath += "Touchpad.json";
        }
        else
        {
            TouchPadJsonPath += "Touchpad01.json";
        }

        if (!File.Exists(TouchPadJsonPath))
        {
            PrintWarningLog(TouchPadJsonPath + " is not found!");
            return(false);
        }

        StreamReader json_sr = new StreamReader(TouchPadJsonPath);

        string JsonString = json_sr.ReadToEnd();

        PrintInfoLog("Touchpad json: " + JsonString);
        json_sr.Close();

        if (JsonString.Equals(""))
        {
            PrintWarningLog("JsonString is empty!");
            return(false);
        }

        curr.TouchSetting = new TouchSetting();
        try
        {
            SimpleJSON.JSONNode jsNodes = SimpleJSON.JSONNode.Parse(JsonString);
            string xvalue      = "";
            string yvalue      = "";
            string zvalue      = "";
            string floatingStr = "";

            xvalue = jsNodes["center"]["x"].Value;
            yvalue = jsNodes["center"]["y"].Value;
            zvalue = jsNodes["center"]["z"].Value;
            if (xvalue.Equals("") || yvalue.Equals("") || zvalue.Equals(""))
            {
                PrintWarningLog("Touch Center pointer is not found!");
                return(false);
            }
            curr.TouchSetting.touchCenter = new Vector3(float.Parse(xvalue), float.Parse(yvalue), float.Parse(zvalue));
            PrintDebugLog("Touch Center pointer is found! x: " + curr.TouchSetting.touchCenter.x + " ,y: " + curr.TouchSetting.touchCenter.y + " ,z: " + curr.TouchSetting.touchCenter.z);

            xvalue = jsNodes["up"]["x"].Value;
            yvalue = jsNodes["up"]["y"].Value;
            zvalue = jsNodes["up"]["z"].Value;
            if (xvalue.Equals("") || yvalue.Equals("") || zvalue.Equals(""))
            {
                PrintWarningLog("Touch Up pointer is not found!");
                return(false);
            }
            curr.TouchSetting.touchForward = new Vector3(float.Parse(xvalue), float.Parse(yvalue), float.Parse(zvalue));
            PrintDebugLog("Touch Up pointer is found! x: " + curr.TouchSetting.touchForward.x + " ,y: " + curr.TouchSetting.touchForward.y + " ,z: " + curr.TouchSetting.touchForward.z);

            xvalue = jsNodes["right"]["x"].Value;
            yvalue = jsNodes["right"]["y"].Value;
            zvalue = jsNodes["right"]["z"].Value;
            if (xvalue.Equals("") || yvalue.Equals("") || zvalue.Equals(""))
            {
                PrintWarningLog("Touch right pointer is not found!");
                return(false);
            }
            curr.TouchSetting.touchRight = new Vector3(float.Parse(xvalue), float.Parse(yvalue), float.Parse(zvalue));
            PrintDebugLog("Touch right pointer is found! x: " + curr.TouchSetting.touchRight.x + " ,y: " + curr.TouchSetting.touchRight.y + " ,z: " + curr.TouchSetting.touchRight.z);
            floatingStr = jsNodes["FloatingDistance"].Value;

            if (floatingStr.Equals(""))
            {
                PrintWarningLog("floatingStr is not found!");
                return(false);
            }

            curr.TouchSetting.touchptHeight = float.Parse(floatingStr);
            PrintInfoLog("Floating distance : " + curr.TouchSetting.touchptHeight);

            curr.TouchSetting.touchPtW = (curr.TouchSetting.touchForward - curr.TouchSetting.touchCenter).normalized;           //analog +y direction.
            curr.TouchSetting.touchPtU = (curr.TouchSetting.touchRight - curr.TouchSetting.touchCenter).normalized;             //analog +x direction.
            curr.TouchSetting.touchPtV = Vector3.Cross(curr.TouchSetting.touchPtU, curr.TouchSetting.touchPtW).normalized;
            curr.TouchSetting.raidus   = (curr.TouchSetting.touchForward - curr.TouchSetting.touchCenter).magnitude;

            PrintInfoLog("touchPtW! x: " + curr.TouchSetting.touchPtW.x + " ,y: " + curr.TouchSetting.touchPtW.y + " ,z: " + curr.TouchSetting.touchPtW.z);
            PrintInfoLog("touchPtU! x: " + curr.TouchSetting.touchPtU.x + " ,y: " + curr.TouchSetting.touchPtU.y + " ,z: " + curr.TouchSetting.touchPtU.z);
            PrintInfoLog("touchPtV! x: " + curr.TouchSetting.touchPtV.x + " ,y: " + curr.TouchSetting.touchPtV.y + " ,z: " + curr.TouchSetting.touchPtV.z);
            PrintInfoLog("raidus: " + curr.TouchSetting.raidus);
        }
        catch (Exception e)
        {
            Log.e(LOG_TAG, "JsonParse failed: " + e.ToString());
            return(false);
        }
        return(true);
    }
Пример #6
0
    void readNativeData(ModelResource curr, bool mergeTo, string modelFolderPath, ModelSpecify ms)
    {
        PrintDebugLog("---  thread start  ---");
        PrintInfoLog("Render model name: " + curr.renderModelName + ", merge = " + curr.mergeToOne);

        IntPtr ptrError = Marshal.AllocHGlobal(64);
        string FBXFile  = modelFolderPath + "/";

        if (ms == ModelSpecify.MS_Dominant)
        {
            FBXFile += "controller00.fbx";
        }
        else
        {
            FBXFile += "controller01.fbx";
        }

        bool   ret          = false;
        uint   sessionid    = 0;
        uint   sectionCount = 0;
        string errorCode    = "";

        if (File.Exists(FBXFile))
        {
            ret       = Interop.WVR_OpenMesh(FBXFile, ref sessionid, ptrError, mergeTo);
            errorCode = Marshal.PtrToStringAnsi(ptrError);

            if (!ret)
            {
                PrintWarningLog("FBX parse failed: " + errorCode);
                return;
            }
        }
        else
        {
            PrintWarningLog("FBX is not found");
            return;
        }

        PrintInfoLog("FBX parse succeed, sessionid = " + sessionid);
        bool finishLoading = Interop.WVR_GetSectionCount(sessionid, ref sectionCount);

        if (!finishLoading || sectionCount == 0)
        {
            PrintWarningLog("failed to load mesh");
            return;
        }

        curr.sectionCount = sectionCount;
        curr.FBXInfo      = new FBXInfo_t[curr.sectionCount];
        curr.SectionInfo  = new MeshInfo_t[curr.sectionCount];

        for (int i = 0; i < curr.sectionCount; i++)
        {
            curr.FBXInfo[i]     = new FBXInfo_t();
            curr.SectionInfo[i] = new MeshInfo_t();

            curr.FBXInfo[i].meshName = Marshal.AllocHGlobal(256);
        }


        ret = Interop.WVR_GetMeshData(sessionid, curr.FBXInfo);
        if (!ret)
        {
            for (int i = 0; i < sectionCount; i++)
            {
                Marshal.FreeHGlobal(curr.FBXInfo[i].meshName);
            }

            curr.SectionInfo = null;
            curr.FBXInfo     = null;
            Interop.WVR_ReleaseMesh(sessionid);
            return;
        }

        for (uint i = 0; i < curr.sectionCount; i++)
        {
            curr.SectionInfo[i]._vectice = new Vector3[curr.FBXInfo[i].verticeCount];
            for (int j = 0; j < curr.FBXInfo[i].verticeCount; j++)
            {
                curr.SectionInfo[i]._vectice[j] = new Vector3();
            }
            curr.SectionInfo[i]._normal = new Vector3[curr.FBXInfo[i].normalCount];
            for (int j = 0; j < curr.FBXInfo[i].verticeCount; j++)
            {
                curr.SectionInfo[i]._normal[j] = new Vector3();
            }
            curr.SectionInfo[i]._uv = new Vector2[curr.FBXInfo[i].uvCount];
            for (int j = 0; j < curr.FBXInfo[i].verticeCount; j++)
            {
                curr.SectionInfo[i]._uv[j] = new Vector2();
            }
            curr.SectionInfo[i]._indice = new int[curr.FBXInfo[i].indiceCount];
            for (int j = 0; j < curr.FBXInfo[i].verticeCount; j++)
            {
                curr.SectionInfo[i]._indice[j] = new int();
            }

            bool active = false;

            bool tret = Interop.WVR_GetSectionData(sessionid, i, curr.SectionInfo[i]._vectice, curr.SectionInfo[i]._normal, curr.SectionInfo[i]._uv, curr.SectionInfo[i]._indice, ref active);
            if (!tret)
            {
                continue;
            }

            curr.SectionInfo[i]._active = active;

            PrintInfoLog("i = " + i + ", name = " + Marshal.PtrToStringAnsi(curr.FBXInfo[i].meshName) + ", active = " + curr.SectionInfo[i]._active);
            PrintInfoLog("i = " + i + ", relative transform = [" + curr.FBXInfo[i].matrix.m0 + " , " + curr.FBXInfo[i].matrix.m1 + " , " + curr.FBXInfo[i].matrix.m2 + " , " + curr.FBXInfo[i].matrix.m3 + "] ");
            PrintInfoLog("i = " + i + ", relative transform = [" + curr.FBXInfo[i].matrix.m4 + " , " + curr.FBXInfo[i].matrix.m5 + " , " + curr.FBXInfo[i].matrix.m6 + " , " + curr.FBXInfo[i].matrix.m7 + "] ");
            PrintInfoLog("i = " + i + ", relative transform = [" + curr.FBXInfo[i].matrix.m8 + " , " + curr.FBXInfo[i].matrix.m9 + " , " + curr.FBXInfo[i].matrix.m10 + " , " + curr.FBXInfo[i].matrix.m11 + "] ");
            PrintInfoLog("i = " + i + ", relative transform = [" + curr.FBXInfo[i].matrix.m12 + " , " + curr.FBXInfo[i].matrix.m13 + " , " + curr.FBXInfo[i].matrix.m14 + " , " + curr.FBXInfo[i].matrix.m15 + "] ");
            PrintInfoLog("i = " + i + ", vertice count = " + curr.FBXInfo[i].verticeCount + ", normal count = " + curr.FBXInfo[i].normalCount + ", uv count = " + curr.FBXInfo[i].uvCount + ", indice count = " + curr.FBXInfo[i].indiceCount);
        }
        Interop.WVR_ReleaseMesh(sessionid);
        curr.isTouchSetting = GetTouchPadParam(curr, modelFolderPath, ms);
        curr.parserReady    = true;
        PrintDebugLog("---  thread end  ---");
    }
Пример #7
0
    public bool addRenderModel(string renderModel, string ModelFolder, ModelSpecify ms, bool merge)
    {
        if (isRenderModelExist(renderModel, ms, merge))
        {
            return(false);
        }

        string FBXFile   = ModelFolder + "/";
        string imageFile = ModelFolder + "/";

        if (ms == ModelSpecify.MS_Dominant)
        {
            FBXFile   += "controller00.fbx";
            imageFile += "controller00.png";
        }
        else
        {
            FBXFile   += "controller01.fbx";
            imageFile += "controller01.png";
        }

        if (!File.Exists(FBXFile))
        {
            return(false);
        }

        if (!File.Exists(imageFile))
        {
            return(false);
        }
        PrintDebugLog("---  start  ---");
        ModelResource newMR = new ModelResource();

        newMR.renderModelName = renderModel;
        newMR.mergeToOne      = merge;
        newMR.parserReady     = false;
        newMR.modelSpecify    = ms;
        renderModelList.Add(newMR);

        mthread = new Thread(() => readNativeData(newMR, merge, ModelFolder, ms));
        mthread.Start();

        PrintDebugLog("---  Read image file start  ---");
        byte[] imgByteArray = File.ReadAllBytes(imageFile);
        PrintDebugLog("---  Read image file end  ---");
        PrintDebugLog("---  Load image start  ---");
        Texture2D modelpng = new Texture2D(2, 2, TextureFormat.BGRA32, false);
        bool      retLoad  = modelpng.LoadImage(imgByteArray);

        if (retLoad)
        {
            PrintDebugLog("---  Load image end  ---, size: " + imgByteArray.Length);
        }
        else
        {
            PrintWarningLog("failed to load texture");
        }
        newMR.modelTexture = modelpng;
        PrintDebugLog("---  Parse battery image start  ---");
        newMR.isBatterySetting = getBatteryIndicatorParam(newMR, ModelFolder, ms);
        PrintDebugLog("---  Parse battery image end  ---");
        PrintDebugLog("---  end  ---");

        return(true);
    }