Provides a noise module that maps the output value from a source module onto a terrace-forming curve. [OPERATOR]
Inheritance: ModuleBase
コード例 #1
0
        private static List<LoadedModule> GetModules(XmlNodeList moduleList)
        {
            List<LoadedModule> loadedModules = new List<LoadedModule>();

            foreach (XmlNode node in moduleList)
            {
                string id = node.Attributes["guid"].Value;
                Point position = new Point(double.Parse(node.Attributes["position"].Value.Split(',')[0]), double.Parse(node.Attributes["position"].Value.Split(',')[1]));
                ModuleBase module = null;

                List<string> links = new List<string>();

                switch (node.Attributes["type"].Value)
                {
                    case "Billow":
                        Billow billow = new Billow();
                        billow.Frequency = double.Parse(node.SelectSingleNode("Frequency").InnerText);
                        billow.Lacunarity = double.Parse(node.SelectSingleNode("Lacunarity").InnerText);
                        billow.OctaveCount = int.Parse(node.SelectSingleNode("OctaveCount").InnerText);
                        billow.Persistence = double.Parse(node.SelectSingleNode("Persistence").InnerText);
                        billow.Quality = (QualityMode)Enum.Parse(typeof(QualityMode), node.SelectSingleNode("Quality").InnerText);
                        billow.Seed = int.Parse(node.SelectSingleNode("Seed").InnerText);
                        module = billow;
                        break;
                    case "Checker":
                        module = new Checker();
                        break;
                    case "Const":
                        Const con = new Const();
                        con.Value = double.Parse(node.SelectSingleNode("Value").InnerText);
                        module = con;
                        break;
                    case "Cylinders":
                        Cylinders cylinder = new Cylinders();
                        cylinder.Frequency = double.Parse(node.SelectSingleNode("Frequency").InnerText);
                        module = cylinder;
                        break;
                    case "Perlin":
                        Perlin perlin = new Perlin();
                        perlin.Frequency = double.Parse(node.SelectSingleNode("Frequency").InnerText);
                        perlin.Lacunarity = double.Parse(node.SelectSingleNode("Lacunarity").InnerText);
                        perlin.OctaveCount = int.Parse(node.SelectSingleNode("OctaveCount").InnerText);
                        perlin.Persistence = double.Parse(node.SelectSingleNode("Persistence").InnerText);
                        perlin.Quality = (QualityMode)Enum.Parse(typeof(QualityMode), node.SelectSingleNode("Quality").InnerText);
                        perlin.Seed = int.Parse(node.SelectSingleNode("Seed").InnerText);
                        module = perlin;
                        break;
                    case "RidgedMultifractal":
                        RidgedMultifractal ridgedMF = new RidgedMultifractal();
                        ridgedMF.Frequency = double.Parse(node.SelectSingleNode("Frequency").InnerText);
                        ridgedMF.Lacunarity = double.Parse(node.SelectSingleNode("Lacunarity").InnerText);
                        ridgedMF.OctaveCount = int.Parse(node.SelectSingleNode("OctaveCount").InnerText);
                        ridgedMF.Quality = (QualityMode)Enum.Parse(typeof(QualityMode), node.SelectSingleNode("Quality").InnerText);
                        ridgedMF.Seed = int.Parse(node.SelectSingleNode("Seed").InnerText);
                        module = ridgedMF;
                        break;
                    case "Spheres":
                        Spheres spheres = new Spheres();
                        spheres.Frequency = double.Parse(node.SelectSingleNode("Frequency").InnerText);
                        module = spheres;
                        break;
                    case "Voronoi":
                        Voronoi voronoi = new Voronoi();
                        voronoi.Frequency = double.Parse(node.SelectSingleNode("Frequency").InnerText);
                        voronoi.Displacement = double.Parse(node.SelectSingleNode("Displacement").InnerText);
                        voronoi.UseDistance = bool.Parse(node.SelectSingleNode("UseDistance").InnerText);
                        voronoi.Seed = int.Parse(node.SelectSingleNode("Seed").InnerText);
                        module = voronoi;
                        break;
                    case "Abs":
                        module = new Abs();
                        XmlNode absInputs = node.SelectSingleNode("ModuleInputs");
                        links.Add(absInputs.SelectSingleNode("Input").InnerText);
                        break;
                    case "Add":
                        module = new Add();
                        XmlNode addInputs = node.SelectSingleNode("ModuleInputs");
                        links.Add(addInputs.SelectSingleNode("Left").InnerText);
                        links.Add(addInputs.SelectSingleNode("Right").InnerText);
                        break;
                    case "Blend":
                        module = new Blend();
                        XmlNode blendInputs = node.SelectSingleNode("ModuleInputs");
                        links.Add(blendInputs.SelectSingleNode("Left").InnerText);
                        links.Add(blendInputs.SelectSingleNode("Right").InnerText);
                        links.Add(blendInputs.SelectSingleNode("Operator").InnerText);
                        break;
                    case "Cache":
                        module = new Cache();
                        XmlNode cacheInputs = node.SelectSingleNode("ModuleInputs");
                        links.Add(cacheInputs.SelectSingleNode("Input").InnerText);
                        break;
                    case "Clamp":
                        Clamp clamp = new Clamp();
                        clamp.Maximum = double.Parse(node.SelectSingleNode("Maximum").InnerText);
                        clamp.Minimum = double.Parse(node.SelectSingleNode("Minimum").InnerText);
                        module = clamp;

                        XmlNode clampInputs = node.SelectSingleNode("ModuleInputs");
                        links.Add(clampInputs.SelectSingleNode("Input").InnerText);
                        break;
                    case "Curve":
                        Curve curve = new Curve();
                        module = curve;

                        foreach (XmlNode cpNode in node.SelectSingleNode("ControlPoints").ChildNodes)
                        {
                            double x = double.Parse(cpNode.InnerText.Split(',')[0]);
                            double y = double.Parse(cpNode.InnerText.Split(',')[1]);
                            curve.Add(x, y);
                        }

                        XmlNode curveInputs = node.SelectSingleNode("ModuleInputs");
                        links.Add(curveInputs.SelectSingleNode("Input").InnerText);
                        break;
                    case "Displace":
                        module = new Displace();
                        XmlNode displaceInputs = node.SelectSingleNode("ModuleInputs");
                        links.Add(displaceInputs.SelectSingleNode("Primary").InnerText);
                        links.Add(displaceInputs.SelectSingleNode("X").InnerText);
                        links.Add(displaceInputs.SelectSingleNode("Y").InnerText);
                        links.Add(displaceInputs.SelectSingleNode("Z").InnerText);
                        break;
                    case "Exponent":
                        Exponent exponent = new Exponent();
                        exponent.Value = double.Parse(node.SelectSingleNode("Value").InnerText);
                        module = exponent;

                        XmlNode exponentInputs = node.SelectSingleNode("ModuleInputs");
                        links.Add(exponentInputs.SelectSingleNode("Input").InnerText);
                        break;
                    case "Invert":
                        module = new Invert();
                        XmlNode invertInputs = node.SelectSingleNode("ModuleInputs");
                        links.Add(invertInputs.SelectSingleNode("Input").InnerText);
                        break;
                    case "Max":
                        module = new Max();
                        XmlNode maxInputs = node.SelectSingleNode("ModuleInputs");
                        links.Add(maxInputs.SelectSingleNode("Left").InnerText);
                        links.Add(maxInputs.SelectSingleNode("Right").InnerText);
                        break;
                    case "Min":
                        module = new Min();
                        XmlNode minInputs = node.SelectSingleNode("ModuleInputs");
                        links.Add(minInputs.SelectSingleNode("Left").InnerText);
                        links.Add(minInputs.SelectSingleNode("Right").InnerText);
                        break;
                    case "Multiply":
                        module = new Multiply();
                        XmlNode multiplyInputs = node.SelectSingleNode("ModuleInputs");
                        links.Add(multiplyInputs.SelectSingleNode("Left").InnerText);
                        links.Add(multiplyInputs.SelectSingleNode("Right").InnerText);
                        break;
                    case "Power":
                        module = new Power();
                        XmlNode powerInputs = node.SelectSingleNode("ModuleInputs");
                        links.Add(powerInputs.SelectSingleNode("Left").InnerText);
                        links.Add(powerInputs.SelectSingleNode("Right").InnerText);
                        break;
                    case "Rotate":
                        Rotate rotate = new Rotate();
                        rotate.X = double.Parse(node.SelectSingleNode("X").InnerText);
                        rotate.Y = double.Parse(node.SelectSingleNode("Y").InnerText);
                        rotate.Z = double.Parse(node.SelectSingleNode("Z").InnerText);
                        module = rotate;

                        XmlNode rotateInputs = node.SelectSingleNode("ModuleInputs");
                        links.Add(rotateInputs.SelectSingleNode("Input").InnerText);
                        break;
                    case "Scale":
                        Scale scale = new Scale();
                        scale.X = double.Parse(node.SelectSingleNode("X").InnerText);
                        scale.Y = double.Parse(node.SelectSingleNode("Y").InnerText);
                        scale.Z = double.Parse(node.SelectSingleNode("Z").InnerText);
                        module = scale;

                        XmlNode scaleInputs = node.SelectSingleNode("ModuleInputs");
                        links.Add(scaleInputs.SelectSingleNode("Input").InnerText);
                        break;
                    case "ScaleBias":
                        ScaleBias scaleBias = new ScaleBias();
                        scaleBias.Scale = double.Parse(node.SelectSingleNode("Scale").InnerText);
                        scaleBias.Bias = double.Parse(node.SelectSingleNode("Bias").InnerText);
                        module = scaleBias;

                        XmlNode scaleBiasInputs = node.SelectSingleNode("ModuleInputs");
                        links.Add(scaleBiasInputs.SelectSingleNode("Input").InnerText);
                        break;
                    case "Select":
                        Select select = new Select();
                        select.Minimum = double.Parse(node.SelectSingleNode("Minimum").InnerText);
                        select.Maximum = double.Parse(node.SelectSingleNode("Maximum").InnerText);
                        select.FallOff = double.Parse(node.SelectSingleNode("FallOff").InnerText);
                        module = select;

                        XmlNode selectInputs = node.SelectSingleNode("ModuleInputs");
                        links.Add(selectInputs.SelectSingleNode("Primary").InnerText);
                        links.Add(selectInputs.SelectSingleNode("Secondary").InnerText);
                        links.Add(selectInputs.SelectSingleNode("Controller").InnerText);
                        break;
                    case "Subtract":
                        module = new Subtract();
                        XmlNode subtractInputs = node.SelectSingleNode("ModuleInputs");
                        links.Add(subtractInputs.SelectSingleNode("Left").InnerText);
                        links.Add(subtractInputs.SelectSingleNode("Right").InnerText);
                        break;
                    case "Terrace":
                        Terrace terrace = new Terrace();
                        module = terrace;

                        foreach (XmlNode cpNode in node.SelectSingleNode("ControlPoints").ChildNodes)
                        {
                            terrace.Add(double.Parse(cpNode.InnerText));
                        }

                        XmlNode terraceInputs = node.SelectSingleNode("ModuleInputs");
                        links.Add(terraceInputs.SelectSingleNode("Input").InnerText);
                        break;
                    case "Translate":
                        Translate translate = new Translate();
                        translate.X = double.Parse(node.SelectSingleNode("X").InnerText);
                        translate.Y = double.Parse(node.SelectSingleNode("Y").InnerText);
                        translate.Z = double.Parse(node.SelectSingleNode("Z").InnerText);
                        module = translate;

                        XmlNode translateInputs = node.SelectSingleNode("ModuleInputs");
                        links.Add(translateInputs.SelectSingleNode("Input").InnerText);
                        break;
                    case "Turbulence":
                        Turbulence turbulence = new Turbulence();
                        turbulence.Frequency = double.Parse(node.SelectSingleNode("Frequency").InnerText);
                        turbulence.Power = double.Parse(node.SelectSingleNode("Power").InnerText);
                        turbulence.Roughness = int.Parse(node.SelectSingleNode("Roughness").InnerText);
                        turbulence.Seed = int.Parse(node.SelectSingleNode("Seed").InnerText);
                        module = turbulence;

                        XmlNode turbulenceInputs = node.SelectSingleNode("ModuleInputs");
                        links.Add(turbulenceInputs.SelectSingleNode("Input").InnerText);
                        break;
                    case "Final":
                        module = new Final();
                        XmlNode finalInputs = node.SelectSingleNode("ModuleInputs");
                        links.Add(finalInputs.SelectSingleNode("Input").InnerText);
                        break;
                    default:
                        break;
                }

                LoadedModule lm = new LoadedModule(id, module, position, links);
                loadedModules.Add(lm);
            }

            return loadedModules;
        }
コード例 #2
0
    public static void genNoise(int channelId)
    {
        moduleBase[channelId] = new Perlin();
        if (teNoiseChanTypeIndex[channelId] == 1)
        {
            int tIdx = teNoiseTypeIndex[channelId];
            if (tIdx == 0) { moduleBase[channelId] = new Perlin(frequency[channelId], lacunarity[channelId], persistance[channelId], octaves[channelId], seed[channelId], QualityMode.High); }
            if (tIdx == 1) { moduleBase[channelId] = new Billow(frequency[channelId], lacunarity[channelId], persistance[channelId], octaves[channelId], seed[channelId], QualityMode.High); }
            if (tIdx == 2) { moduleBase[channelId] = new RidgedMultifractal(frequency[channelId], lacunarity[channelId], octaves[channelId], seed[channelId], QualityMode.High); }
            if (tIdx == 3) { moduleBase[channelId] = new Voronoi(frequency[channelId], displacement[channelId], seed[channelId], distance[channelId]); }
            if (tIdx == 4) { moduleBase[channelId] = new BrownianMotion(frequency[channelId], lacunarity[channelId], octaves[channelId], seed[channelId], QualityMode.High); }
            if (tIdx == 5) { moduleBase[channelId] = new HeterogeneousMultiFractal(frequency[channelId], lacunarity[channelId], octaves[channelId], persistance[channelId], seed[channelId], offset[channelId], QualityMode.High); }
            if (tIdx == 6) { moduleBase[channelId] = new HybridMulti(frequency[channelId], lacunarity[channelId], octaves[channelId], persistance[channelId], seed[channelId], offset[channelId], gain[channelId], QualityMode.High); }
            if (tIdx == 7) { moduleBase[channelId] = new LinearGradientNoise(frequency[channelId]); }
        }
        if (teNoiseChanTypeIndex[channelId] == 2)
        {
            int fIdx = teFunctionTypeIndex[channelId];
            if (fIdx == 0) { moduleBase[channelId] = new Add(moduleBase[srcChannel1Id[channelId]], moduleBase[srcChannel2Id[channelId]]); }
            if (fIdx == 1) { moduleBase[channelId] = new Subtract(moduleBase[srcChannel1Id[channelId]], moduleBase[srcChannel2Id[channelId]]); }
            if (fIdx == 2) { moduleBase[channelId] = new Multiply(moduleBase[srcChannel1Id[channelId]], moduleBase[srcChannel2Id[channelId]]); }
            if (fIdx == 3) { moduleBase[channelId] = new Min(moduleBase[srcChannel1Id[channelId]], moduleBase[srcChannel2Id[channelId]]); }
            if (fIdx == 4) { moduleBase[channelId] = new Max(moduleBase[srcChannel1Id[channelId]], moduleBase[srcChannel2Id[channelId]]); }
            if (fIdx == 5) { moduleBase[channelId] = new Blend(moduleBase[srcChannel1Id[channelId]], moduleBase[srcChannel2Id[channelId]], moduleBase[srcChannel3Id[channelId]]); }
            if (fIdx == 6) { moduleBase[channelId] = new Clamp((double)noiseFuncMin[channelId], (double)noiseFuncMax[channelId], moduleBase[srcChannel1Id[channelId]]); }
			if (fIdx == 7) { moduleBase[channelId] = new Power(moduleBase[srcChannel1Id[channelId]],moduleBase[srcChannel2Id[channelId]]);}
			if (fIdx == 8) { Curve tmpCurve = new Curve(moduleBase[srcChannel1Id[channelId]]);
				double adjust = double.Parse((controlpointcount[channelId]-1).ToString())*0.5;
				for(int i=0;i<controlpointcount[channelId];i++){
					tmpCurve.Add(double.Parse(i.ToString())-adjust,(double)cpval[channelId,i]);
					moduleBase[channelId] = tmpCurve;
				}
			}
			if(fIdx==9){Terrace tmpTerrace = new Terrace(invertTerrace[channelId],moduleBase[srcChannel1Id[channelId]]);
				for(int i=0;i<controlpointcount[channelId];i++){
					tmpTerrace.Add((double)cpval[channelId,i]-0.5);
					moduleBase[channelId] = tmpTerrace;
				}
			}
            if (fIdx == 18) { moduleBase[channelId] = new Mask(moduleBase[srcChannel1Id[channelId]], (double)noiseFuncMin[channelId], (double)noiseFuncMax[channelId]); }
            if (fIdx == 17) { moduleBase[channelId] = new WindexWarp(moduleBase[srcChannel1Id[channelId]]); }
			if (fIdx == 16) { moduleBase[channelId] = new TEWarp(moduleBase[srcChannel1Id[channelId]]); }
            if (fIdx == 15) { moduleBase[channelId] = new Select((double)noiseFuncMin[channelId], (double)noiseFuncMax[channelId], falloff[channelId], moduleBase[srcChannel1Id[channelId]], moduleBase[srcChannel2Id[channelId]], moduleBase[srcChannel3Id[channelId]]); }
			if (fIdx == 14) { moduleBase[channelId] = new Turbulence(power[channelId],moduleBase[srcChannel1Id[channelId]]); }
			if (fIdx == 13) { moduleBase[channelId] = new ScaleBias(scale[channelId],bias[channelId],moduleBase[srcChannel1Id[channelId]]); }
			if (fIdx == 12) { moduleBase[channelId] = new Invert(moduleBase[srcChannel1Id[channelId]]);}
			if (fIdx == 11) { moduleBase[channelId] = new Exponent(exponent[channelId],moduleBase[srcChannel1Id[channelId]]); }
			if (fIdx == 10) { moduleBase[channelId] = new Abs(moduleBase[srcChannel1Id[channelId]]);}
		}
        int resolution = 64;
        int xoffset = 0; int yoffset = 0;
        m_noiseMap[channelId] = new Noise2D(resolution, resolution, moduleBase[channelId]);
        float x1 = xoffset * zoom[channelId];
        float x2 = (xoffset * zoom[channelId]) + ((zoom[channelId] / resolution) * (resolution + 1));
        float y1 = -yoffset * zoom[channelId];
        float y2 = (-yoffset * zoom[channelId]) + ((zoom[channelId] / resolution) * (resolution + 1));
        m_noiseMap[channelId].GeneratePlanar(x1, x2, y1, y2);
        m_textures[channelId] = m_noiseMap[channelId].GetTexture();
        m_textures[channelId].Apply();
    }