Esempio n. 1
0
    private void createLodSys(MeshInstance _mesh)
    {
        if (_mesh != null)
        {
            GD.Print("Create mesh");

            if (_mesh.GetChildCount() > 0)
            {
                GD.Print("Mesh needs to be clear. Remove childs at first");
                return;
            }

            var q2 = (float)(editDock.GetNode("lod2_quality") as Slider).Value;
            var q3 = (float)(editDock.GetNode("lod3_quality") as Slider).Value;

            var lod2Mesh = MeshDecimator.MeshDecimatorTool.generateMesh(q2, _mesh);
            var lod3Mesh = MeshDecimator.MeshDecimatorTool.generateMesh(q3, _mesh);

            //set scale to all other meshinstances
            var tf = (MeshLod)GD.Load <PackedScene>("res://addons/mesh_lod/MeshLod.tscn").Instance();
            _mesh.GetParent().AddChild(tf);
            tf.Translation = _mesh.Translation;
            tf.Rotation    = _mesh.Rotation;
            tf.Scale       = _mesh.Scale;
            tf.lod2Quality = q2;
            tf.lod3Quality = q3;
            tf.Owner       = GetEditorInterface().GetEditedSceneRoot();
            _mesh.GetParent().RemoveChild(_mesh);
            tf.AddChild(_mesh);

            _mesh.Owner = GetEditorInterface().GetEditedSceneRoot();
            tf.Name     = _mesh.Name;
            _mesh.Name  = "lod1";

            _mesh.Translation = Vector3.Zero;
            _mesh.Rotation    = Vector3.Zero;
            _mesh.Scale       = new Vector3(1, 1, 1);

            var lod2 = createLodMesh(_mesh, lod2Mesh);
            lod2.Name = "lod2";

            var lod3 = createLodMesh(_mesh, lod3Mesh);
            lod3.Name = "lod3";

            tf.AddChild(lod2);
            tf.AddChild(lod3);

            lod2.Owner = GetEditorInterface().GetEditedSceneRoot();
            lod3.Owner = GetEditorInterface().GetEditedSceneRoot();

            tf.doLoding();
        }
    }