Exemple #1
0
    IEnumerator checkParams()
    {
        while (true)
        {
            if (!bLoadMesh)
            {
                yield return(wfef);
            }
            else
            {
                break;
            }
        }
        string meshName = "";

        for (uint i = 0; i < sectionCount; i++)
        {
            meshName   = Marshal.PtrToStringAnsi(FBXInfo[i].meshName);
            meshCom    = null;
            meshGO     = null;
            updateMesh = new Mesh();

            meshCom = Resources.Load("MeshComponent") as GameObject;
            meshGO  = Instantiate(meshCom);
            meshGO.transform.parent = this.transform;
            meshGO.name             = meshName;
            Matrix4x4 t = WaveVR_Utils.RigidTransform.toMatrix44(FBXInfo[i].matrix);

            Vector3 x = WaveVR_Utils.GetPosition(t);
            meshGO.transform.localPosition = new Vector3(-x.x, x.y, x.z);

            Log.d(LOG_TAG, " MeshGO = " + meshName + ", localPosition: " + meshGO.transform.localPosition.x + ", " + meshGO.transform.localPosition.y + ", " + meshGO.transform.localPosition.z);
            meshGO.transform.localRotation = WaveVR_Utils.GetRotation(t);

            float   a = 0f;
            Vector3 b = Vector3.zero;
            meshGO.transform.localRotation.ToAngleAxis(out a, out b);
            Log.d(LOG_TAG, " MeshGO = " + meshName + ", localRotation: " + b);
            //Log.d(LOG_TAG, " MeshGO = " + meshName + ", localRotation: " + meshGO.transform.localRotation);
            meshGO.transform.localScale = WaveVR_Utils.GetScale(t);
            Log.d(LOG_TAG, " MeshGO = " + meshName + ", localScale: " + meshGO.transform.localScale);

            meshGO.transform.Rotate(new Vector3(0, 180, 0));

            var meshfilter = meshGO.GetComponent <MeshFilter>();

            updateMesh.Clear();

            updateMesh.vertices = SectionInfo[i]._vectice;
            updateMesh.uv       = SectionInfo[i]._uv;
            updateMesh.uv2      = SectionInfo[i]._uv;
            updateMesh.colors32 = colors.ToArray();
            updateMesh.normals  = SectionInfo[i]._normal;
            updateMesh.SetIndices(SectionInfo[i]._indice, MeshTopology.Triangles, 0);
            updateMesh.name = meshName;

            meshfilter.mesh = updateMesh;

            var meshRenderer = meshGO.GetComponent <MeshRenderer>();
            meshRenderer.material.mainTexture = MatImage;
            meshRenderer.enabled = true;
        }

        WaveVR_Utils.Event.Send(WaveVR_Utils.Event.ADAPTIVE_CONTROLLER_READY, this.device);
        cleanNativeData();
        Resources.UnloadUnusedAssets();
    }
Exemple #2
0
    IEnumerator SpawnRenderModel()
    {
        while (true)
        {
            if (modelResource != null)
            {
                if (modelResource.parserReady)
                {
                    break;
                }
            }
            PrintDebugLog("SpawnRenderModel is waiting");
            yield return(wfef);
        }

        PrintDebugLog("Start to spawn all meshes!");

        if (modelResource == null)
        {
            PrintDebugLog("modelResource is null, skipping spawn objects");
            mLoadingState = LoadingState.LoadingState_NOT_LOADED;
            yield return(null);
        }

        string meshName = "";

        for (uint i = 0; i < modelResource.sectionCount; i++)
        {
            meshName = Marshal.PtrToStringAnsi(modelResource.FBXInfo[i].meshName);
            meshCom  = null;
            meshGO   = null;

            bool meshAlready = false;

            for (uint j = 0; j < i; j++)
            {
                string tmp = Marshal.PtrToStringAnsi(modelResource.FBXInfo[j].meshName);

                if (tmp.Equals(meshName))
                {
                    meshAlready = true;
                }
            }

            if (meshAlready)
            {
                PrintDebugLog(meshName + " is created! skip.");
                continue;
            }

            if (mergeToOneBone && modelResource.SectionInfo[i]._active)
            {
                meshName = "Merge_" + meshName;
            }
            updateMesh = new Mesh();
            meshCom    = new GameObject();
            meshCom.AddComponent <MeshRenderer>();
            meshCom.AddComponent <MeshFilter>();
            meshGO = Instantiate(meshCom);
            meshGO.transform.parent = this.transform;
            meshGO.name             = meshName;

            Matrix4x4 t = WaveVR_Utils.RigidTransform.toMatrix44(modelResource.FBXInfo[i].matrix);

            Vector3 x = WaveVR_Utils.GetPosition(t);
            meshGO.transform.localPosition = new Vector3(x.x, x.y, -x.z);

            meshGO.transform.localRotation = WaveVR_Utils.GetRotation(t);
            Vector3 r = meshGO.transform.localEulerAngles;
            meshGO.transform.localEulerAngles = new Vector3(-r.x, r.y, r.z);
            meshGO.transform.localScale       = WaveVR_Utils.GetScale(t);

            PrintDebugLog("i = " + i + " MeshGO = " + meshName + ", localPosition: " + meshGO.transform.localPosition.x + ", " + meshGO.transform.localPosition.y + ", " + meshGO.transform.localPosition.z);
            PrintDebugLog("i = " + i + " MeshGO = " + meshName + ", localRotation: " + meshGO.transform.localEulerAngles);
            PrintDebugLog("i = " + i + " MeshGO = " + meshName + ", localScale: " + meshGO.transform.localScale);

            var meshfilter = meshGO.GetComponent <MeshFilter>();
            updateMesh.Clear();
            updateMesh.vertices = modelResource.SectionInfo[i]._vectice;
            updateMesh.uv       = modelResource.SectionInfo[i]._uv;
            updateMesh.uv2      = modelResource.SectionInfo[i]._uv;
            updateMesh.colors32 = colors.ToArray();
            updateMesh.normals  = modelResource.SectionInfo[i]._normal;
            updateMesh.SetIndices(modelResource.SectionInfo[i]._indice, MeshTopology.Triangles, 0);
            updateMesh.name = meshName;
            if (meshfilter != null)
            {
                meshfilter.mesh = updateMesh;
            }
            var meshRenderer = meshGO.GetComponent <MeshRenderer>();
            if (meshRenderer != null)
            {
                if (ImgMaterial == null)
                {
                    PrintDebugLog("ImgMaterial is null");
                }
                meshRenderer.material             = ImgMaterial;
                meshRenderer.material.mainTexture = modelResource.modelTexture;
                meshRenderer.enabled = true;
            }

            if (meshName.Equals(emitterMeshName))
            {
                PrintDebugLog(meshName + " is found, set " + meshName + " active: true");
                meshGO.SetActive(true);
            }
            else if (meshName.Equals("__CM__Battery"))
            {
                isBatteryIndicatorReady = false;
                if (modelResource.isBatterySetting)
                {
                    if (modelResource.batteryTextureList != null)
                    {
                        batteryMR = meshGO.GetComponent <MeshRenderer>();
                        var mat = Resources.Load("TransparentMat") as Material;
                        if (mat != null)
                        {
                            batteryMR.material = mat;
                        }

                        batteryMR.material.mainTexture = modelResource.batteryTextureList[0].batteryTexture;
                        batteryMR.enabled       = true;
                        isBatteryIndicatorReady = true;
                    }
                }
                meshGO.SetActive(false);
                PrintDebugLog(meshName + " is found, set " + meshName + " active: false (waiting for update");
                batteryGO = meshGO;
            }
            else if (meshName == "__CM__TouchPad_Touch")
            {
                PrintDebugLog(meshName + " is found, set " + meshName + " active: false");
                meshGO.SetActive(false);
            }
            else
            {
                PrintDebugLog("set " + meshName + " active: " + modelResource.SectionInfo[i]._active);
                meshGO.SetActive(modelResource.SectionInfo[i]._active);
            }

            yield return(wfef);
        }
        PrintDebugLog("send " + deviceType + " ADAPTIVE_CONTROLLER_READY ");
        WaveVR_Utils.Event.Send(WaveVR_Utils.Event.ADAPTIVE_CONTROLLER_READY, deviceType);

        Resources.UnloadUnusedAssets();
        mLoadingState = LoadingState.LoadingState_LOADED;
    }
    void spawnMesh()
    {
        if (!bLoadMesh)
        {
            PrintDebugLog("bLoadMesh is false, skipping spawn objects");
            return;
        }
        string meshName = "";

        for (uint i = 0; i < sectionCount; i++)
        {
            meshName = Marshal.PtrToStringAnsi(FBXInfo[i].meshName);
            meshCom  = null;
            meshGO   = null;

            updateMesh = new Mesh();
            meshCom    = new GameObject();
            meshCom.AddComponent <MeshRenderer>();
            meshCom.AddComponent <MeshFilter>();
            //      meshCom = Resources.Load("MeshComponent") as GameObject;
            meshGO = Instantiate(meshCom);
            meshGO.transform.parent = this.transform;
            meshGO.name             = meshName;
            Matrix4x4 t = WaveVR_Utils.RigidTransform.toMatrix44(FBXInfo[i].matrix);

            Vector3 x = WaveVR_Utils.GetPosition(t);
            meshGO.transform.localPosition = new Vector3(-x.x, x.y, x.z);

            PrintDebugLog("i = " + i + " MeshGO = " + meshName + ", localPosition: " + meshGO.transform.localPosition.x + ", " + meshGO.transform.localPosition.y + ", " + meshGO.transform.localPosition.z);
            meshGO.transform.localRotation = WaveVR_Utils.GetRotation(t);

            float   a = 0f;
            Vector3 b = Vector3.zero;
            meshGO.transform.localRotation.ToAngleAxis(out a, out b);
            PrintDebugLog("i = " + i + " MeshGO = " + meshName + ", localRotation: " + b);
            //PrintDebugLog(" MeshGO = " + meshName + ", localRotation: " + meshGO.transform.localRotation);
            meshGO.transform.localScale = WaveVR_Utils.GetScale(t);
            PrintDebugLog("i = " + i + " MeshGO = " + meshName + ", localScale: " + meshGO.transform.localScale);
            meshGO.transform.Rotate(new Vector3(0, 180, 0));

            var meshfilter = meshGO.GetComponent <MeshFilter>();

            updateMesh.Clear();
            updateMesh.vertices = SectionInfo[i]._vectice;
            updateMesh.uv       = SectionInfo[i]._uv;
            updateMesh.uv2      = SectionInfo[i]._uv;
            updateMesh.colors32 = colors.ToArray();
            updateMesh.normals  = SectionInfo[i]._normal;
            updateMesh.SetIndices(SectionInfo[i]._indice, MeshTopology.Triangles, 0);
            updateMesh.name = meshName;
            if (meshfilter != null)
            {
                meshfilter.mesh = updateMesh;
            }

            var meshRenderer = meshGO.GetComponent <MeshRenderer>();
            if (meshRenderer != null)
            {
                meshRenderer.material             = ImgMaterial;
                meshRenderer.material.mainTexture = MatImage;
                meshRenderer.enabled = true;
            }

            if (meshName == "__CM__TouchPad_Touch")
            {
                meshGO.SetActive(false);
            }
        }
        WaveVR_Utils.Event.Send(WaveVR_Utils.Event.ADAPTIVE_CONTROLLER_READY, deviceType);

        cleanNativeData();
        Resources.UnloadUnusedAssets();
    }