Пример #1
0
    public void Extrude_Face_CreatesValidGeometry(
        [ValueSource("shapeTypes")] ShapeType shape,
        [ValueSource("extrudeMethods")] ExtrudeMethod extrudeMethod,
        [ValueSource("extrudeDistance")] float distance)
    {
        var mesh = ShapeGenerator.CreateShape(shape);

        try
        {
            int  initialVertexCount = mesh.vertexCount;
            Face face = mesh.facesInternal[m_Random.Next(0, mesh.facesInternal.Length)];
            mesh.Extrude(new Face[] { face }, extrudeMethod, distance);
            mesh.ToMesh();
            mesh.Refresh();
            LogAssert.NoUnexpectedReceived();
            TestUtility.AssertMeshAttributesValid(mesh.mesh);
#if PB_CREATE_TEST_MESH_TEMPLATES
            TestUtility.SaveAssetTemplate(mesh.mesh, mesh.name);
#endif
            Assert.AreEqual(initialVertexCount + face.edgesInternal.Length * 4, mesh.vertexCount);
        }
        catch (Exception e)
        {
            Debug.LogError(e.ToString());
        }
        finally
        {
            if (mesh != null)
            {
                Object.DestroyImmediate(mesh.gameObject);
            }
        }
    }
Пример #2
0
        /**
         *  Do the thing.  Return a pb_ActionResult indicating the success/failure of action.
         */
        public override pb_ActionResult DoAction()
        {
            #if !UNITY_4_6 && !UNITY_4_7
            ShadowCastingMode shadowMode = (ShadowCastingMode)pb_PreferencesInternal.GetInt("pb_CreateShadowObject_shadowMode", (int)ShadowCastingMode.ShadowsOnly);
            #endif
            float         extrudeDistance = pb_PreferencesInternal.GetFloat("pb_CreateShadowObject_volumeSize", .08f);
            ExtrudeMethod extrudeMethod   = (ExtrudeMethod)pb_PreferencesInternal.GetInt("pb_CreateShadowObject_extrudeMethod", (int)ExtrudeMethod.FaceNormal);

            foreach (pb_Object pb in selection)
            {
                pb_Object shadow = GetShadowObject(pb);

                if (shadow == null)
                {
                    continue;
                }

                foreach (pb_Face f in shadow.faces)
                {
                    f.ReverseIndices(); f.manualUV = true;
                }
                shadow.Extrude(shadow.faces, extrudeMethod, extrudeDistance);
                shadow.ToMesh();
                shadow.Refresh();
                shadow.Optimize();

                #if !UNITY_4_6 && !UNITY_4_7
                MeshRenderer mr = shadow.gameObject.GetComponent <MeshRenderer>();
                mr.shadowCastingMode = shadowMode;
                if (shadowMode == ShadowCastingMode.ShadowsOnly)
                {
                    mr.receiveShadows = false;
                }
                #endif

                Collider collider = shadow.GetComponent <Collider>();

                while (collider != null)
                {
                    GameObject.DestroyImmediate(collider);
                    collider = shadow.GetComponent <Collider>();
                }
            }

            // This is necessary!  Otherwise the pb_Editor will be working with caches from
            // outdated meshes and throw errors.
            pb_Editor.Refresh();

            return(new pb_ActionResult(Status.Success, "Create Shadow Object"));
        }
Пример #3
0
        /// <summary>
        /// Perform the action.
        /// </summary>
        /// <returns>Return a pb_ActionResult indicating the success/failure of action.</returns>
        public override ActionResult DoAction()
        {
            ShadowCastingMode shadowMode      = (ShadowCastingMode)EditorPrefs.GetInt("pb_CreateShadowObject_shadowMode", (int)ShadowCastingMode.ShadowsOnly);
            float             extrudeDistance = EditorPrefs.GetFloat("pb_CreateShadowObject_volumeSize", .08f);
            ExtrudeMethod     extrudeMethod   = (ExtrudeMethod)EditorPrefs.GetInt("pb_CreateShadowObject_extrudeMethod", (int)ExtrudeMethod.FaceNormal);

            foreach (ProBuilderMesh mesh in MeshSelection.top)
            {
                ProBuilderMesh shadow = GetShadowObject(mesh);

                if (shadow == null)
                {
                    continue;
                }

                foreach (Face f in shadow.faces)
                {
                    f.SetIndexes(f.indexes.Reverse().ToArray());
                    f.manualUV = true;
                }
                shadow.Extrude(shadow.faces, extrudeMethod, extrudeDistance);
                shadow.ToMesh();
                shadow.Refresh();
                shadow.Optimize();

                                #if !UNITY_4_6 && !UNITY_4_7
                MeshRenderer mr = shadow.gameObject.GetComponent <MeshRenderer>();
                mr.shadowCastingMode = shadowMode;
                if (shadowMode == ShadowCastingMode.ShadowsOnly)
                {
                    mr.receiveShadows = false;
                }
                                #endif

                Collider collider = shadow.GetComponent <Collider>();

                while (collider != null)
                {
                    Object.DestroyImmediate(collider);
                    collider = shadow.GetComponent <Collider>();
                }
            }

            // Refresh the Editor wireframe and working caches.
            ProBuilderEditor.Refresh();

            return(new ActionResult(ActionResult.Status.Success, "Create Shadow Object"));
        }
Пример #4
0
        public override void OnSettingsGUI()
        {
            GUILayout.Label("Create Shadow Volume Options", EditorStyles.boldLabel);

            EditorGUI.BeginChangeCheck();

            EditorGUI.BeginChangeCheck();
            float volumeSize = pb_PreferencesInternal.GetFloat("pb_CreateShadowObject_volumeSize", .07f);

            volumeSize = EditorGUILayout.Slider(gc_volumeSize, volumeSize, 0.001f, 1f);
            if (EditorGUI.EndChangeCheck())
            {
                pb_PreferencesInternal.SetFloat("pb_CreateShadowObject_volumeSize", volumeSize);
            }

            #if !UNITY_4_6 && !UNITY_4_7
            EditorGUI.BeginChangeCheck();
            ShadowCastingMode shadowMode = (ShadowCastingMode)pb_PreferencesInternal.GetInt("pb_CreateShadowObject_shadowMode", (int)ShadowCastingMode.ShadowsOnly);
            shadowMode = (ShadowCastingMode)EditorGUILayout.EnumPopup("Shadow Casting Mode", shadowMode);
            if (EditorGUI.EndChangeCheck())
            {
                pb_PreferencesInternal.SetInt("pb_CreateShadowObject_shadowMode", (int)shadowMode);
            }
            #endif

            EditorGUI.BeginChangeCheck();
            ExtrudeMethod extrudeMethod = (ExtrudeMethod)pb_PreferencesInternal.GetInt("pb_CreateShadowObject_extrudeMethod", (int)ExtrudeMethod.FaceNormal);
            extrudeMethod = (ExtrudeMethod)EditorGUILayout.EnumPopup("Extrude Method", extrudeMethod);
            if (EditorGUI.EndChangeCheck())
            {
                pb_PreferencesInternal.SetInt("pb_CreateShadowObject_extrudeMethod", (int)extrudeMethod);
            }

            if (EditorGUI.EndChangeCheck())
            {
                DoAction();
            }

            GUILayout.FlexibleSpace();

            if (GUILayout.Button("Create Shadow Volume"))
            {
                DoAction();
                SceneView.RepaintAll();
                pb_MenuOption.CloseAll();
            }
        }
Пример #5
0
        static void ExtrudeSingleFace(ExtrudeMethod method, float distance = 1f)
        {
            using (var shapes = new TestUtility.BuiltInPrimitives())
            {
                foreach (var pb in (IEnumerable <ProBuilderMesh>)shapes)
                {
                    int initialVertexCount           = pb.vertexCount;
                    UnityEngine.ProBuilder.Face face = pb.facesInternal[m_Random.Next(0, pb.facesInternal.Length)];
                    pb.Extrude(new UnityEngine.ProBuilder.Face[] { face }, method, 1f);
                    pb.ToMesh();
                    pb.Refresh();
                    LogAssert.NoUnexpectedReceived();
                    TestUtility.AssertMeshAttributesValid(pb.mesh);
#if PB_CREATE_TEST_MESH_TEMPLATES
                    TestUtility.SaveAssetTemplate(pb.mesh, pb.name);
#endif
                    Assert.AreEqual(initialVertexCount + face.edgesInternal.Length * 4, pb.vertexCount);
                }
            }
        }
Пример #6
0
 static string GetExtrudeIconString(ExtrudeMethod m)
 {
     return(m == ExtrudeMethod.VertexNormal ? "Toolbar/ExtrudeFace_VertexNormals"
         : m == ExtrudeMethod.FaceNormal ? "Toolbar/ExtrudeFace_FaceNormals"
         : "Toolbar/ExtrudeFace_Individual");
 }
Пример #7
0
        /// <summary>
        /// Extrude a collection of faces.
        /// </summary>
        /// <param name="mesh">The source mesh.</param>
        /// <param name="faces">The faces to extrude.</param>
        /// <param name="method">Describes how faces are extruded.</param>
        /// <param name="distance">The distance to extrude faces.</param>
        /// <returns>An array of the faces created as a result of the extrusion. Null if the faces paramater is null or empty.</returns>
        public static Face[] Extrude(this ProBuilderMesh mesh, IEnumerable <Face> faces, ExtrudeMethod method, float distance)
        {
            switch (method)
            {
            case ExtrudeMethod.IndividualFaces:
                return(ExtrudePerFace(mesh, faces, distance));

            default:
                return(ExtrudeAsGroups(mesh, faces, method == ExtrudeMethod.FaceNormal, distance));
            }
        }