Example #1
0
    //----------------------------------------------------------------------------------
    // Material Property loading

    #region MaterialProps

    /// <summary> Load the hard-coded properties of the material </summary>
    /// <param name="ofMaterial"></param>
    public void LoadMaterialProps(VirtualMaterial ofMaterial)
    {
        //SenseGlove_Debugger.Log("Loading material props of " + ofMaterial.ToString());
        if (ofMaterial != VirtualMaterial.Custom)
        {
            MaterialProps thisProps = new MaterialProps();
            switch (ofMaterial)
            {
            case VirtualMaterial.Rubber:
                thisProps.maxForce     = 65;
                thisProps.maxForceDist = 0.02f;
                thisProps.yieldDist    = float.MaxValue;
                thisProps.hapticForce  = 60;
                thisProps.hapticDur    = 200;
                break;

            case VirtualMaterial.Steel:
                thisProps.maxForce     = 100;
                thisProps.maxForceDist = 0.00f;
                thisProps.yieldDist    = float.MaxValue;
                thisProps.hapticForce  = 0;
                thisProps.hapticDur    = 0;
                break;

            case VirtualMaterial.Egg:
                thisProps.maxForce     = 90;
                thisProps.maxForceDist = 0.01f;
                thisProps.yieldDist    = 0.02f;
                thisProps.hapticForce  = 0;
                thisProps.hapticDur    = 0;
                break;
            }
            this.LoadMaterialProps(thisProps);
        }
    }
    private void AddSceneStreaming(VirtualMaterial vm, int clusterCount)
    {
        foreach (var s in res.clusterProperties)
        {
            if (s.name == sceneName)
            {
                res.clusterProperties.Remove(s);
                break;
            }
        }

        SceneStreaming ss = new SceneStreaming();

        ss.name         = sceneName;
        ss.vm           = vm;
        ss.clusterCount = clusterCount;

        res.clusterProperties.Add(ss);
    }
Example #3
0
    public void LoadScene(string name)
    {
        ClusterResources res = _asset.res;
        SceneStreaming   ss  = res.GetSceneStreaming(name);

        if (ss == null)
        {
            Debug.LogError("没有取到场景资源,请检查ClusterMatResource");
        }
        VirtualMaterial vm = ss.vm;

        _properties       = vm.allProperties.ToArray();
        _perprotiesBuffer = new ComputeBuffer(_properties.Length, sizeof(MaterialProperties));
        _perprotiesBuffer.SetData(_properties);

        for (int i = 0; i < vm.albedoIDs.Count; i++)
        {
            string  texPath = "Scenes/" + name + ClusterComponents.PATH_TEX + vm.albedoNames[i];
            Texture texture = ResourceManager.instance.Load <Texture>(texPath);
            Shader.SetGlobalTexture(vm.albedoIDs[i].ToString(), texture);
        }
    }
    /// <summary> Called when the inspector is (re)drawn. </summary>
    public override void OnInspectorGUI()
    {
        // Update the serializedProperty - always do this in the beginning of OnInspectorGUI.
        serializedObject.Update();

        var materialClass = target as SenseGlove_Material;
        var origFontStyle = EditorStyles.label.fontStyle;

        ///// Always show the dropdown menu
        ////show as an enum dropdown with the selected option matching the one we've chosen.

        EditorGUI.BeginChangeCheck();
        SetRenderMode(_materialType.hasMultipleDifferentValues, headerStyle);
        materialClass.material = (VirtualMaterial)EditorGUILayout.EnumPopup(l_material, materialClass.material);
        SetRenderMode(false, origFontStyle);
        if (EditorGUI.EndChangeCheck()) //update serialzed properties before showing them.
        {
            _materialType.enumValueIndex = (int)materialClass.material;
            if (materialClass.material != this.previousMaterial)
            {
                //SenseGlove_Debugger.Log("Material Changed (from Editor)");
                if (materialClass.material != VirtualMaterial.Custom && materialClass.material != VirtualMaterial.FromDataBase)
                {
                    //SenseGlove_Debugger.Log("We've updated! materialClass.material = " + materialClass.material.ToString());

                    materialClass.LoadMaterialProps(materialClass.material);
                    //apply all relevant material settings.
                    _maxForce.intValue       = materialClass.maxForce;
                    _maxForceDist.floatValue = materialClass.maxForceDist;
                    _yieldDist.floatValue    = materialClass.yieldDistance;

                    _hapticFeedback.boolValue = materialClass.hapticFeedback;
                    _hapticDuration.intValue  = materialClass.hapticDuration;
                    _hapticMagnitude.intValue = materialClass.hapticMagnitude;

                    _breakAble.boolValue = materialClass.breakable;
                }
            }
            this.previousMaterial = materialClass.material;
        }

        //end of materialType; show everything else.

        if (!_materialType.hasMultipleDifferentValues)
        {
            ///only show material properties if custom is selected.
            if (materialClass.material == VirtualMaterial.Custom)
            {
                CreateIntSlider(ref materialClass.maxForce, ref this._maxForce, 0, 100, l_maxForce);
                CreateFloatField(ref materialClass.maxForceDist, ref this._maxForceDist, l_maxForceDist);
                CreateFloatField(ref materialClass.yieldDistance, ref this._yieldDist, l_yieldDist);
            }
            ///Show only the Database propery
            else if (materialClass.material == VirtualMaterial.FromDataBase)
            {
                EditorGUILayout.PropertyField(_materialDataBase, l_materialDB);
                CreateTextField(ref materialClass.materialName, ref _materialName, l_materialName);
            }
        }

        //Haptic Feeback Options
        CreateToggle(ref materialClass.hapticFeedback, ref _hapticFeedback, l_hapticFeedback, headerStyle, origFontStyle);
        if (materialClass.hapticFeedback && !_hapticFeedback.hasMultipleDifferentValues)
        {
            CreateIntSlider(ref materialClass.hapticMagnitude, ref _hapticMagnitude, 0, 100, l_hapticMagn);
            CreateIntSlider(ref materialClass.hapticDuration, ref _hapticDuration, 0, 1500, l_hapticDur);
        }

        //Breakable Options
        CreateToggle(ref materialClass.breakable, ref _breakAble, l_breakable, headerStyle, origFontStyle);
        if (materialClass.breakable && !_breakAble.hasMultipleDifferentValues)
        {
            CreateToggle(ref materialClass.mustBeGrabbed, ref _mustGrab, l_mustGrab);
            CreateToggle(ref materialClass.requiresThumb, ref _mustThumb, l_reqThumb);
            CreateIntSlider(ref materialClass.minimumFingers, ref _nuFingers, 1, 4, l_minFingers);
        }

        EditorStyles.label.fontStyle = origFontStyle; //return it to the desired value.

        // Apply changes to the serializedProperty - always do this in the end of OnInspectorGUI.
        serializedObject.ApplyModifiedProperties();
    }
    public CombinedModel ProcessCluster(MeshRenderer[] allRenderers, Dictionary <MeshRenderer, bool> lowLODLevels)
    {
        List <MeshFilter> allFilters = new List <MeshFilter>(allRenderers.Length);
        int sumVertexLength          = 0;
        int sumTriangleLength        = 0;

        for (int i = 0; i < allRenderers.Length; ++i)
        {
            if (!lowLODLevels.ContainsKey(allRenderers[i]))
            {
                MeshFilter filter = allRenderers[i].GetComponent <MeshFilter>();
                if (filter.sharedMesh == null)
                {
                    Debug.LogError("存在没有Mesh的物件:" + allRenderers[i].transform.name);
                }
                allFilters.Add(filter);
                sumVertexLength += (int)(filter.sharedMesh.vertexCount * 1.2f);
            }
        }
        sumTriangleLength = (int)(sumVertexLength * 1.5);
        NativeList <Point> points            = new NativeList <Point>(sumVertexLength, Allocator.Temp);
        NativeList <int>   triangleMaterials = new NativeList <int>(sumVertexLength / 3, Allocator.Temp);

        VirtualMaterial            vm        = new VirtualMaterial();
        Dictionary <Material, int> Mat2Index = vm.GetMaterialsData(allRenderers, resPath);

        for (int i = 0; i < allFilters.Count; ++i)
        {
            Mesh mesh = allFilters[i].sharedMesh;
            GetPoints(points, mesh, allFilters[i].transform, allRenderers[i].sharedMaterials, Mat2Index);
        }
        float3 less = points[0].vertex;
        float3 more = points[0].vertex;

        for (int i = 1; i < points.Length; ++i)
        {
            float3 current = points[i].vertex;
            if (less.x > current.x)
            {
                less.x = current.x;
            }
            if (more.x < current.x)
            {
                more.x = current.x;
            }
            if (less.y > current.y)
            {
                less.y = current.y;
            }
            if (more.y < current.y)
            {
                more.y = current.y;
            }
            if (less.z > current.z)
            {
                less.z = current.z;
            }
            if (more.z < current.z)
            {
                more.z = current.z;
            }
        }

        float3 center = (less + more) / 2;
        float3 extent = more - center;
        Bounds b      = new Bounds(center, extent * 2);

        CombinedModel md;

        md.bound       = b;
        md.allPoints   = points;
        md.allMatIndex = triangleMaterials;
        md.vm          = vm;

        return(md);
    }