Exemple #1
0
    public virtual SurfaceObjectCreator[] GenerateMeshDataFromSurfaceParametrizations(SurfaceGenerator.SurfaceParametrization[] faceParametrization)
    {
        int N = faceParametrization.GetLength(0);

        SurfaceObjectCreator[] objectCreators = new SurfaceObjectCreator[N];

        Action <int> generateFace = (int i) => {
            SurfaceGenerator gen = new SurfaceGenerator();
            SurfaceGenerator.SurfaceParametrization face = faceParametrization[i];

            gen.setParameters(X, Y, true, false);
            gen.setVerticesOutputArrays(new Vector3[X * Y], new Vector3[X * Y], new Vector2[X * Y], 0);
            gen.setIndicesOutputArray(new int[(X - 1) * (Y - 1) * 2 * 3], 0);
            gen.Generate((float x, float y) => withNoise(face(x, y), x, y));

            objectCreators[i] = new SurfaceObjectCreator(gen, this);
        };

        if (enableMultithreading)
        {
            Parallel.For(0, N, 1, generateFace);
        }
        else
        {
            for (int i = 0; i < N; ++i)
            {
                generateFace(i);
            }
        }

        return(objectCreators);
    }
 public ProceduralParameters(SurfaceGenerator surfaceGenerator, ModelBuilder builder)
 {
     if (surfaceGenerator == null) throw new ArgumentNullException("surfaceGenerator");
         if (builder == null) throw new ArgumentNullException("builder");
         Builder = builder;
         SurfaceGenerator = surfaceGenerator;
         TexelGenerator = BasicTexelGeneratorValue;
 }
 public ProceduralParameters SetSurfaceGenerator(SurfaceGenerator value)
 {
     if (value == null)
     {
         throw new ArgumentNullException("value");
     }
     SurfaceGenerator = value; return(this);
 }
        protected override void OnSceneGUI()
        {
            base.OnSceneGUI();
            SurfaceGenerator user = (SurfaceGenerator)target;

            if (user.extrudeSpline != null)
            {
                SplineDrawer.DrawSplineComputer(user.extrudeSpline, 0.0, 1.0, 0.5f);
            }
        }
 void FindOrCreateSurfaceGenerator()
 {
     this.generator              = SurfaceGenerator.Instance;
     generator.OnChunkGenreated -= OnChunkGenerated;
     generator.OnChunkGenreated += OnChunkGenerated;
     terrainRoot = generator.Terrain;
     if (!generator.IsUseableInEditor)
     {
         generator.MakeUseableInEditor();
     }
 }
        protected override void BodyGUI()
        {
            showSize     = false;
            showRotation = false;
            base.BodyGUI();
            SurfaceGenerator user = (SurfaceGenerator)target;

            serializedObject.Update();
            SerializedProperty expand        = serializedObject.FindProperty("_expand");
            SerializedProperty extrude       = serializedObject.FindProperty("_extrude");
            SerializedProperty extrudeSpline = serializedObject.FindProperty("_extrudeSpline");

            EditorGUI.BeginChangeCheck();
            EditorGUILayout.Space();
            EditorGUILayout.LabelField("Shape", EditorStyles.boldLabel);
            EditorGUILayout.PropertyField(expand, new GUIContent("Expand"));
            if (extrudeSpline.objectReferenceValue == null)
            {
                EditorGUILayout.PropertyField(extrude, new GUIContent("Extrude"));
            }
            EditorGUILayout.PropertyField(extrudeSpline, new GUIContent("Extrude Path"));
            if (extrudeSpline.objectReferenceValue != null)
            {
                SerializedProperty extrudeClipFrom = serializedObject.FindProperty("_extrudeFrom");
                SerializedProperty extrudeClipTo   = serializedObject.FindProperty("_extrudeTo");
                float clipFrom = extrudeClipFrom.floatValue;
                float clipTo   = extrudeClipTo.floatValue;
                EditorGUILayout.MinMaxSlider(new GUIContent("Extrude Clip Range:"), ref clipFrom, ref clipTo, 0f, 1f);
                extrudeClipFrom.floatValue = clipFrom;
                extrudeClipTo.floatValue   = clipTo;
            }
            if (EditorGUI.EndChangeCheck())
            {
                for (int i = 0; i < users.Length; i++)
                {
                    users[i].Rebuild();
                }
                serializedObject.ApplyModifiedProperties();
            }

            UVControls(user);

            if (extrude.floatValue != 0f || extrudeSpline.objectReferenceValue != null)
            {
                SerializedProperty sideUvOffset = serializedObject.FindProperty("_sideUvOffset");
                SerializedProperty sideUvScale  = serializedObject.FindProperty("_sideUvScale");
                SerializedProperty uniformUvs   = serializedObject.FindProperty("_uniformUvs");

                EditorGUILayout.PropertyField(sideUvOffset, new GUIContent("Side UV Offset"));
                EditorGUILayout.PropertyField(sideUvScale, new GUIContent("Side UV Scale"));
                EditorGUILayout.PropertyField(uniformUvs, new GUIContent("Unform UVs"));
            }
        }
 public ProceduralParameters(SurfaceGenerator surfaceGenerator, ModelBuilder builder)
 {
     if (surfaceGenerator == null)
     {
         throw new ArgumentNullException("surfaceGenerator");
     }
     if (builder == null)
     {
         throw new ArgumentNullException("builder");
     }
     Builder          = builder;
     SurfaceGenerator = surfaceGenerator;
     TexelGenerator   = BasicTexelGeneratorValue;
 }
Exemple #8
0
    public virtual SurfaceObjectCreator[] GenerateMeshDataFromSurfaceParametrizations(SurfaceGenerator.SurfaceParametrization[] faceParametrization)
    {
        int N = faceParametrization.GetLength(0);

        SurfaceObjectCreator[] objectCreators = new SurfaceObjectCreator[N];

        Action <int> generateFace = (int i) => {
            SurfaceGenerator gen = new SurfaceGenerator();
            SurfaceGenerator.SurfaceParametrization face = faceParametrization[i];

            gen.setParameters(X, Y, true, false);
            gen.setVerticesOutputArrays(new Vector3[X * Y], new Vector3[X * Y], new Vector2[X * Y], 0);
            gen.setIndicesOutputArray(new int[(X - 1) * (Y - 1) * 2 * 3], 0);
            gen.setColorsOutputArray(new Color[X * Y], 0);
            gen.Generate((float x, float y) => {
                SurfaceGenerator.Vertex vert;
                vert.position = radius * face(x, y);
                vert.normal   = Vector3.zero;
                vert.uv       = new Vector2(x, y);
                vert.color    = Color.white;
                return(vert);
            });

            objectCreators[i] = new SurfaceObjectCreator(gen, this);
        };

        if (enableMultithreading)
        {
            Parallel.For(0, N, 1, generateFace);
        }
        else
        {
            for (int i = 0; i < N; ++i)
            {
                generateFace(i);
            }
        }

        return(objectCreators);
    }
Exemple #9
0
 private static void CreateInstance()
 {
     instance = new SurfaceGenerator();
     instance.Awake();
     instance.MakeUseableInEditor();
 }
 public ProceduralParameters StartProcedural(SurfaceGenerator generator)
 {
     return new ProceduralParameters(generator, this);
 }
 public ProceduralParameters SetSurfaceGenerator(SurfaceGenerator value)
 {
     if (value == null) throw new ArgumentNullException("value"); SurfaceGenerator = value; return this;
 }
 public ProceduralParameters StartProcedural(SurfaceGenerator generator)
 {
     return(new ProceduralParameters(generator, this));
 }
Exemple #13
0
 public SurfaceObjectCreator(SurfaceGenerator data, MeshGenerator gen)
 {
     this.data = data;
     this.gen  = gen;
 }