MathSculptorAddinSample

From Second Life Wiki
Jump to navigation Jump to search

The Example below is a very basic sample Addin for Math Sculptor. It has only one dependency which is the ISculptAddin which has not dependencies beyond Microsoft .NET 2.0. ISculptAddin source can be found at MathSculptorInterface


using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using System.Resources;
using Burhop.MathSculptor;

namespace SampleAddin
{
    public class SampleAddin : ISculptAddin
    {
        int radius1;
        int radius2;

        #region ISculptAddin Members

        public string Description
        {
            get
            {
                return "Creates shapes based off a circle whose radius can be modified";
            }
        }

        public System.Drawing.Image IconImage
        {
            get { return global::SampleAddin.Properties.Resources.SampleAddinImage; }
        }

        public string LongDescription
        {
            get
            {
                return "This basic addin shows how to create your our DLLs for your own more unique sculptured primitives.";
            }
        }

        public List<ISculptParam> Params
        {
            get
            {
                List<ISculptParam> pList = new List<ISculptParam>();
                SculptParam<int> radius1 = new SculptParam<int>();
                SculptParam<int> radius2 = new SculptParam<int>();

                //Param 1
                radius1.Name = "X Radius";
                radius1.Value = 100;
                radius1.LowValue = 0;
                radius1.HighValue = 127;

                //Param 2
                radius2.Name = "Y Radius";
                radius2.Value = 100;
                radius2.LowValue = 0;
                radius2.HighValue = 127;

                pList.Add(radius1);
                pList.Add(radius2);
                return pList;
            }
            set
            {
                SculptParam<int> iParam;
                iParam = value[0] as SculptParam<int>;
                radius1 = iParam.Value;
                iParam = value[1] as SculptParam<int>;
                radius2 = iParam.Value;
            }
        }

        public xyz getXYZ(double u, double v)
        {
            xyz result;
            //A Cylinder
            result.x = (byte)(radius1 * Math.Sin(u * 2 * Math.PI) + 127);
            result.y = (byte)(radius2 * Math.Cos(u * 2 * Math.PI) + 127);
            result.z = (byte)(v * 256);
            return result;
        }

        #endregion
    }
}