예제 #1
0
    private void determineCheapCombineOp(ref StringBuilder cheapMap, RMObj obj, uint index)
    {
        CombineOpsTypes combineOpType = obj.CombineOpType;
        string          combineOps    = "_combineOps" + "[" + index + "].y);";

        if (!obj.IsPrim)
        {
            combineOps = "_combineOpsCSGs" + "[" + index + "].w);";
        }

        switch (combineOpType)
        {
        case CombineOpsTypes.Union:
            cheapMap.AppendLine("\tscene = opU(scene, obj);");
            break;

        case CombineOpsTypes.SmoothUnion:
            cheapMap.AppendLine("\tscene = opSmoothUnion(scene, obj, " + combineOps);
            break;

        case CombineOpsTypes.SmoothSubtraction:
            cheapMap.AppendLine("\tscene = opSmoothUnion(scene, obj, " + combineOps);
            break;

        case CombineOpsTypes.SmoothIntersection:
            cheapMap.AppendLine("\tscene = opSmoothUnion(scene, obj, " + combineOps);
            break;

        default:
            cheapMap.AppendLine("\tscene = opU(scene, obj);");
            break;
        }
    }
예제 #2
0
    //// Start is called before the first frame update
    //void Start()
    //{

    //}

    //// Update is called once per frame
    //void Update()
    //{

    //}

    public void resetCSG()
    {
        _firstNode             = null;
        _secondNode            = null;
        _nodeCombineOpType     = NodeCombineOpsTypes.Union;
        _nodeCombineSmoothness = 0.0f;
        _combineOpType         = CombineOpsTypes.Union;
        _combineSmoothness     = 0.0f;
        _isRoot = true;
    }
예제 #3
0
파일: RMObj.cs 프로젝트: MBE2FL/GDW
    public void displayCombineOp(GUIContent label, RMObj obj)
    {
        EditorGUILayout.PropertyField(_combineOpType, label);

        label.text = "Combine Smoothness";

        if (_combineOpType.intValue == (int)CombineOpsTypes.SmoothUnion ||
            _combineOpType.intValue == (int)CombineOpsTypes.SmoothSubtraction ||
            _combineOpType.intValue == (int)CombineOpsTypes.SmoothIntersection)
        {
            EditorGUILayout.PropertyField(_combineSmoothness);
            obj.CombineSmoothness = Mathf.Clamp(_combineSmoothness.floatValue, 0.0f, Mathf.Infinity);
        }
    }
예제 #4
0
    //private void buildPrimitives(ref StringBuilder map, ref uint primIndex)
    //{

    //    foreach (RMPrimitive prim in _rmMemoryManager.RM_Prims)
    //    {
    //        // Skip any primitives belonging to a csg, as they will be rendered recursively by thier respective csgs.
    //        if (prim.CSGNode)
    //            continue;

    //        parsePrimitive(ref map, prim, ref primIndex);
    //    }
    //}

    //private void buildCSGs(ref StringBuilder map, ref uint primIndex)
    //{
    //    uint csgIndex = 0;

    //    map.AppendLine("\t// ######### Render CSGs #########");
    //    map.AppendLine("\trmPixel obj2;");
    //    map.AppendLine("\trmPixel csg;");
    //    map.AppendLine("\trmPixel storedCSGs[MAX_CSG_CHILDREN];");
    //    map.AppendLine();

    //    foreach (CSG csg in _rmMemoryManager.CSGs)
    //    {
    //        // Skip any non-root CSGs, as they will be rendered recursively by thier parents.
    //        // Skip any CSGs which don't have two nodes.
    //        if (!csg.IsRoot || !csg.IsValid)
    //            continue;

    //        map.AppendLine("\t// ######### " + csg.gameObject.name + " #########");

    //        parseCSG(ref map, csg, ref primIndex, ref csgIndex);

    //        determineCombineOp(ref map, null, csg, csgIndex - 1);
    //        map.AppendLine("\t// ######### " + csg.gameObject.name + " #########");
    //        map.AppendLine();
    //    }
    //}
    #endregion Old



    private void parseCheapObj(ref StringBuilder cheapMap, RMObj obj, ref uint primIndex, ref uint csgIndex)
    {
        if (!obj.Static)
        {
            // Determine position and geometric information
            cheapMap.AppendLine("\tpos = mul(_invModelMats[" + primIndex + "], float4(p, 1.0));");
            cheapMap.AppendLine("\tgeoInfo = _boundGeoInfo[" + primIndex + "];");


            cheapMap.Append("\tobj = ");

            // Determine primitive type
            switch (obj.BoundShape)
            {
            case BoundingShapes.Sphere:
                cheapMap.AppendLine("sdSphere(pos.xyz, geoInfo.x);");
                break;

            case BoundingShapes.Box:
                cheapMap.AppendLine("sdBox(pos.xyz, geoInfo.xyz);");
                break;

            default:
                Debug.LogError("Obj's bound shape, in cheap map, could not be parsed.");
                break;
            }

            cheapMap.AppendLine();

            // Determine combining operation
            determineCheapCombineOp(ref cheapMap, obj, primIndex);


            if (obj.IsPrim)
            {
                ++primIndex;
            }
            else
            {
                parseCheapCSG(ref cheapMap, obj as CSG, ref primIndex, ref csgIndex);
            }
        }
        else
        {
            Matrix4x4 mat;
            Vector4   info;

            // Determine position and geometric information
            mat = obj.transform.localToWorldMatrix.inverse;
            cheapMap.AppendLine("\tpos = mul(float4x4(" + mat.m00 + ", " + mat.m01 + ", " + mat.m02 + ", " + mat.m03 + ", "
                                + mat.m10 + ", " + mat.m11 + ", " + mat.m12 + ", " + mat.m13 + ", "
                                + mat.m20 + ", " + mat.m21 + ", " + mat.m22 + ", " + mat.m23 + ", "
                                + mat.m30 + ", " + mat.m31 + ", " + mat.m32 + ", " + mat.m33 + "), float4(p, 1.0));");

            info = obj.BoundGeoInfo;
            cheapMap.AppendLine("\tgeoInfo = float4(" + info.x + ", " + info.y + ", " + info.z + ", " + info.w + ");");

            // Determine primitive type
            switch (obj.BoundShape)
            {
            case BoundingShapes.Sphere:
                cheapMap.AppendLine("sdSphere(pos.xyz, geoInfo.x);");
                break;

            case BoundingShapes.Box:
                cheapMap.AppendLine("sdBox(pos.xyz, geoInfo.xyz);");
                break;

            default:
                Debug.LogError("Obj's bound shape, in cheap map, could not be parsed.");
                break;
            }


            cheapMap.AppendLine();

            // Determine combining operation
            determineCheapCombineOp(ref cheapMap, obj, primIndex);

            //map.AppendLine();
            ++primIndex;
        }
    }
예제 #5
0
파일: RMObj.cs 프로젝트: MBE2FL/GDW
    public void displayAlterations(GUIContent label, RMObj obj)
    {
        EditorGUILayout.Space();
        // Alterations
        label.text    = "Alterations";
        label.tooltip = "";
        EditorGUILayout.LabelField(label, EditorStyles.boldLabel);

        // Clear all alterations.
        if (GUILayout.Button("Clear Alts"))
        {
            obj.clearAlts();
        }


        for (int i = 0; i < _alts.Count; ++i)
        {
            _currentAlt = _alts[i];

            activeProperty = _currentAlt.FindPropertyRelative("active");
            // No alterations are active.
            if (!activeProperty.boolValue)
            {
                break;
            }


            EditorGUILayout.Space();
            EditorGUILayout.Space();
            label.text = "Alteration " + (i + 1);
            EditorGUILayout.LabelField(label, EditorStyles.boldLabel);
            // Display the current alteration's information.
            DisplayAltInfo(_currentAlt);


            // Remove current alteration.
            GUILayout.BeginHorizontal();
            if (GUILayout.Button("Remove Alteration"))
            {
                removeAlt(_currentAlt);
                obj.AltsDirty = true;
            }

            // Move current alteration up.
            EditorGUI.BeginDisabledGroup(i == 0);
            if (GUILayout.Button("Move Up"))
            {
                moveUp(_currentAlt, i);
                obj.AltsDirty = true;
            }
            EditorGUI.EndDisabledGroup();


            bool disabled = (i == (_alts.Count - 1));
            if (i < (_alts.Count - 1))
            {
                disabled = !_alts[i + 1].FindPropertyRelative("active").boolValue;
            }

            // Move current alteration down.
            EditorGUI.BeginDisabledGroup(disabled);
            if (GUILayout.Button("Move Down"))
            {
                moveDown(_currentAlt, i);
                obj.AltsDirty = true;
            }
            EditorGUI.EndDisabledGroup();
            GUILayout.EndHorizontal();
        }

        EditorGUILayout.Space();
        EditorGUILayout.Space();
        // Add an alteration.
        if (GUILayout.Button("Add Alteration"))
        {
            addAlt();
            obj.AltsDirty = true;
        }
    }
예제 #6
0
파일: RMObj.cs 프로젝트: MBE2FL/GDW
    public override void OnInspectorGUI()
    {
        //base.OnInspectorGUI();

        RMObj rmObj = target as RMObj;

        serializedObject.Update();

        GUIContent label = new GUIContent("Shader Options", "All ray marching shaders you can add this object to.");

        // Retrieve all the ray march shaders, and display them as options to be added to.
        List <RayMarchShader> shaders = _rayMarcher.Shaders;

        if (shaders.Count > 0)
        {
            // Retrieve all the shaders' names.
            _shaderNames = new string[shaders.Count];
            for (int i = 0; i < shaders.Count; ++i)
            {
                _shaderNames[i] = shaders[i].ShaderName;
            }

            // Display them.
            _selectedShaderIndex = EditorGUILayout.Popup(label, _selectedShaderIndex, _shaderNames);

            if (GUILayout.Button("Add To Shader"))
            {
                shaders[_selectedShaderIndex].RenderList.Add(rmObj);
            }
        }
        else
        {
            _selectedShaderIndex = EditorGUILayout.Popup(label, _selectedShaderIndex, _shaderNames);
        }


        label.text    = "Draw Order";
        label.tooltip = "The order in which this object will be placed in the shader.";
        EditorGUILayout.PropertyField(_drawOrder, label);

        label.text    = "Static";
        label.tooltip = "Will hard code all info into the shader.";
        EditorGUILayout.PropertyField(_static, label);

        label.text    = "Bound Shape";
        label.tooltip = "";
        EditorGUILayout.PropertyField(_boundShape, label);

        label.text    = "Bound Geo Info";
        label.tooltip = "The dimensions of the bounding shape for this object.";
        Vector4 boundGeoInfo = new Vector4(1.0f, 1.0f, 1.0f, 0.0f);

        switch (_boundShape.enumValueIndex)
        {
        case (int)BoundingShapes.Sphere:
            boundGeoInfo.x             = EditorGUILayout.FloatField("Radius", _boundGeoInfo.vector4Value.x);
            _boundGeoInfo.vector4Value = boundGeoInfo;
            break;

        case (int)BoundingShapes.Box:
            boundGeoInfo.x             = EditorGUILayout.FloatField("Length", _boundGeoInfo.vector4Value.x);
            boundGeoInfo.z             = EditorGUILayout.FloatField("Breadth", _boundGeoInfo.vector4Value.z);
            boundGeoInfo.y             = EditorGUILayout.FloatField("Height", _boundGeoInfo.vector4Value.y);
            _boundGeoInfo.vector4Value = boundGeoInfo;
            break;

        default:
            break;
        }


        serializedObject.ApplyModifiedProperties();
    }
예제 #7
0
    public override void OnInspectorGUI()
    {
        base.OnInspectorGUI();

        var csg = target as CSG;
        //bool firstPrimChanged = false;
        //bool secondPrimChanged = false;
        //RMPrimitive firstPrimRef = null;
        //RMPrimitive secondPrimRef = null;
        bool       firstNodeChanged  = false;
        bool       secondNodeChanged = false;
        RMObj      firstNodeRef      = null;
        RMObj      secondNodeRef     = null;
        GUIContent label             = new GUIContent("Node Combine Op", "How the two nodes will interact.");

        bool nodeCombineOpChanged = false;

        serializedObject.Update();

        _isRoot.boolValue = EditorGUILayout.Toggle("Is Root CSG", _isRoot.boolValue);
        EditorGUILayout.Toggle("Is Valid CSG", csg.IsValid);


        EditorGUI.BeginChangeCheck();
        EditorGUILayout.PropertyField(_firstNode);
        firstNodeChanged = EditorGUI.EndChangeCheck();
        firstNodeRef     = csg.FirstNode;


        // Determine how the two objects will interact.
        EditorGUI.BeginChangeCheck();
        EditorGUILayout.PropertyField(_nodeCombineOpType, label);
        nodeCombineOpChanged = EditorGUI.EndChangeCheck();


        // Display the smoothness property for certain operations.
        if (_nodeCombineOpType.intValue == (int)NodeCombineOpsTypes.SmoothUnion ||
            _nodeCombineOpType.intValue == (int)NodeCombineOpsTypes.SmoothSubtraction ||
            _nodeCombineOpType.intValue == (int)NodeCombineOpsTypes.SmoothIntersection)
        {
            //csg.NodeCombineSmoothness = Mathf.Clamp(EditorGUILayout.FloatField("Node Combine Smoothness", csg.NodeCombineSmoothness), 0.0f, Mathf.Infinity);
            EditorGUILayout.PropertyField(_nodeCombineSmoothness);
            csg.NodeCombineSmoothness = Mathf.Clamp(_nodeCombineSmoothness.floatValue, 0.0f, Mathf.Infinity);
        }
        else if (_nodeCombineOpType.intValue == (int)NodeCombineOpsTypes.Lerp)
        {
            label.text = "Interpolation Value";
            EditorGUILayout.PropertyField(_nodeCombineSmoothness, label);
            //csg.NodeCombineSmoothness = Mathf.Clamp(_nodeCombineSmoothness.floatValue, 0.0f, Mathf.Infinity);
        }


        EditorGUI.BeginChangeCheck();
        EditorGUILayout.PropertyField(_secondNode);
        secondNodeChanged = EditorGUI.EndChangeCheck();
        secondNodeRef     = csg.SecondNode;


        EditorGUI.BeginDisabledGroup(!csg.IsRoot);
        // Determine how the CSG will interact with the scene.
        label.text = "CSG Combine Op";
        if (csg.IsRoot)
        {
            label.tooltip = "How the CSG will interact with the scene.";
        }
        else
        {
            label.tooltip = "Overridden by parent CSG.";
        }

        displayCombineOp(label, csg);
        EditorGUI.EndDisabledGroup();



        // Display Alterations
        displayAlterations(label, csg);


        serializedObject.ApplyModifiedProperties();


        // Avoids change if the same node was used for both slots.
        if (csg.FirstNode && (csg.FirstNode == csg.SecondNode))
        {
            // First slot was the same as the second's slot.
            if (firstNodeChanged)
            {
                firstNodeChanged = false;
                csg.FirstNode    = null;
            }
            // Second slot was the same as the first's slot.
            else
            {
                secondNodeChanged = false;
                csg.SecondNode    = null;
            }
        }

        // First node has been added, changed, or removed. (Avoids change if user selected the same first node.)
        if (firstNodeChanged && (csg.FirstNode != firstNodeRef))
        {
            // First node was just added/changed.
            if (csg.FirstNode)
            {
                if (csg.IsFirstPrim)
                {
                    (csg.FirstNode as RMPrimitive).CSGNode = true;
                }
                else
                {
                    (csg.FirstNode as CSG).IsRoot = false;
                }
            }
            // Previous first node was just removed/changed, iff not previously empty.
            if (firstNodeRef)
            {
                if (firstNodeRef.IsPrim)
                {
                    (firstNodeRef as RMPrimitive).CSGNode = false;
                }
                else
                {
                    (firstNodeRef as CSG).IsRoot = true;
                }
            }
        }

        // Second node has been added, changed, or removed. (Avoids change if user selected the same second node.)
        if (secondNodeChanged && (csg.SecondNode != secondNodeRef))
        {
            // Second node was just added/changed.
            if (csg.SecondNode)
            {
                if (csg.IsSecondPrim)
                {
                    (csg.SecondNode as RMPrimitive).CSGNode = true;
                }
                else
                {
                    (csg.SecondNode as CSG).IsRoot = false;
                }
            }
            // Previous second node was just removed/changed, iff not previously empty.
            if (secondNodeRef)
            {
                if (secondNodeRef.IsPrim)
                {
                    (secondNodeRef as RMPrimitive).CSGNode = false;
                }
                else
                {
                    (secondNodeRef as CSG).IsRoot = true;
                }
            }
        }


        // Update and reload the shader.
        //if (nodeCombineOpChanged)
        //    Camera.main.GetComponent<ShaderBuilder>().build();

        //if (combineOpChanged)
        //    Camera.main.GetComponent<ShaderBuilder>().build();
    }