Beispiel #1
0
 private void OnEnable()
 {
     _params                     = (ParamsData)target;
     _titlesLabelField           = new GUIStyle();
     _titlesLabelField.fontSize  = 20;
     _titlesLabelField.fontStyle = FontStyle.BoldAndItalic;
 }
Beispiel #2
0
 /// <summary>百度语音识别事件</summary>
 private void OnSpeechEventListener(SpeechEventListenerInfo callbackMessage)
 {
     if (callbackMessage.state.Equals(SpeechConstant.CALLBACK_EVENT_WAKEUP_SUCCESS))
     {
         stateText.text = "唤醒成功!";
         ParamsData wakeupParams = Serializable.GetWakeupParams(callbackMessage.param);
         Debug.Log("errorCode:" + wakeupParams.errorCode);
         Debug.Log("errorDesc:" + wakeupParams.errorDesc);
         content.text = wakeupParams.word;
     }
 }
Beispiel #3
0
 /// <summary>
 /// This procedure contains the user code. Input parameters are provided as regular arguments,
 /// Output parameters as ref arguments. You don't have to assign output parameters,
 /// they will have a default value.
 /// </summary>
 private void RunScript(bool store, string path, List <int> NumSliders, List <int> SliderVals, int NumPoints, List <Point3d> Points)
 {
     if (store)
     {
         //      string outputpath = @"C:\Users\ddxgo\Documents\Rhino\20200626c#expts\testjsonout.txt";
         string     jsonstring;
         ParamsData paramsdata = new ParamsData(NumSliders, SliderVals, NumPoints, Points);
         jsonstring = JsonConvert.SerializeObject(paramsdata);
         File.WriteAllText(path, jsonstring);
     }
 }
Beispiel #4
0
    public void Draw()
    {
        inPoint.Draw();
        outPoint.Draw();


        EditorGUILayout.BeginHorizontal();
        EditorGUILayout.LabelField("Start:", GUILayout.Width(70));
        Start = EditorGUILayout.Toggle(Start);
        EditorGUILayout.EndHorizontal();

        EditorGUILayout.BeginHorizontal();
        EditorGUILayout.LabelField("Finish:", GUILayout.Width(70));
        Finish = EditorGUILayout.Toggle(Finish);
        EditorGUILayout.EndHorizontal();

        EditorGUILayout.BeginHorizontal();
        EditorGUILayout.LabelField("Condition:", GUILayout.Width(70));
        Condition = EditorGUILayout.Toggle(Condition);
        EditorGUILayout.EndHorizontal();

        if (Finish == false && Condition == false)
        {
            Quest        = (QuestData)EditorGUILayout.ObjectField(Quest, typeof(QuestData), true);
            Param        = (ParamsData)EditorGUILayout.ObjectField(Param, typeof(ParamsData), true);
            currentQuest = EditorGUILayout.Toggle("Current Quest", currentQuest);
        }
        if (Start == true)
        {
            Finish    = false;
            Condition = false;
        }
        if (Condition == true)
        {
            Start  = false;
            Finish = false;
            EditorGUILayout.LabelField("Condicion:", GUILayout.Width(70));
            level   = EditorGUILayout.IntField("Level", level);
            killed  = EditorGUILayout.TextField("Killed", killed);
            item    = EditorGUILayout.TextField("Item", item);
            explore = EditorGUILayout.TextField("Explored", explore);
            know    = EditorGUILayout.TextField("Know", know);
            if (GUILayout.Button("CheckParams"))
            {
                CheckParams(level, killed, item, explore, know);
            }
        }
        if (Finish == true)
        {
            Start     = false;
            Condition = false;
            Param     = (ParamsData)EditorGUILayout.ObjectField(Param, typeof(ParamsData), true);
        }
    }
Beispiel #5
0
 private bool getMetodParamsCount1Value(ParameterInfo parameter, ParamsData paramsData, string paramJson, out object value)
 {
     value = null;
     if (paramsData == null ||
         paramsData.ParamsCount != 1 ||
         string.IsNullOrWhiteSpace(paramsData.Param1Name) ||
         paramsData.Param1Name.ToLower() != parameter.Name.ToLower()
         )
     {
         return(false);
     }
     value = paramJson.ToObject(parameter.ParameterType);
     return(true);
 }
Beispiel #6
0
        private ParamsData getMetod1Param(InvokeData data)
        {
            var parameters = data.Method.GetParameters();
            var result     = new ParamsData();
            var param1Name = string.Empty;

            result.ParamsCount = parameters.Length;
            foreach (var parameter in parameters)
            {
                if (isActionParameter(parameter))
                {
                    result.ParamsCount--;
                    continue;
                }
                try
                {
                    var flag = getMetodParameterValueByName(parameter, data.NameParams, out object value);
                    if (flag)
                    {
                        result.ParamsCount--;
                        continue;
                    }
                }
                catch (Exception ex)
                {
                }
                try
                {
                    var flag = getMetodParameterValueByType(parameter, data.TypeParams, out object value);
                    if (flag)
                    {
                        result.ParamsCount--;
                        continue;
                    }
                }
                catch (Exception ex)
                {
                }
                param1Name = parameter.Name;
            }

            if (result.ParamsCount == 1)
            {
                result.Param1Name = param1Name;
            }

            return(result);
        }
        public void GetGroupUserList()
        {
            int      groupId   = Convert.ToInt32(ParamsData["groupId"]);
            int      pageIndex = Convert.ToInt32(ParamsData["page"]);
            int      rows      = Convert.ToInt32(ParamsData["rows"]);
            PageInfo page      = new PageInfo(rows, pageIndex);

            page.KeyName = "code";
            DataTable dt  = null;
            UserDao   dao = NewDao <UserDao>();

            if (ParamsData.ContainsKey("key"))
            {
                dt = dao.GetUserData(groupId, ParamsData["key"], page);
            }
            else
            {
                dt = dao.GetUserData(groupId, "", page);
            }
            JsonResult = ToGridJson(dt, page.totalRecord);
        }
Beispiel #8
0
    private void SolutionCallback(GH_Document doc)
    {
        //read file, deserialize json, send variables out of the extracted class

        string     jsonstring = File.ReadAllText(_path);
        ParamsData paramdata  = new ParamsData();

        paramdata   = JsonConvert.DeserializeObject <ParamsData>(jsonstring);
        _n          = paramdata.NumSliders;
        _dataIn     = paramdata.SliderVals;
        _pointsdata = paramdata.Points;


        Random rnd = new Random();

        List <IGH_DocumentObject> deletions       = new List <IGH_DocumentObject>(); //list of objects to delete from grasshopper document
        List <OutputParam>        outputParams    = new List <OutputParam>();        //list of the slider grouping params and their output connections
        List <IGH_Param>          PointRecvParams = new List <IGH_Param>();          //list of what the point param is connected to

        foreach (IGH_DocumentObject obj in GrasshopperDocument.Objects)
        {
            if (obj.NickName.StartsWith(_controlComponentName)) //the point and integer params i've created
            {
                deletions.Add(obj);
                IGH_Param tempParam = obj as IGH_Param; //cast obj into a param to locate sources and recipients
                if (tempParam.SourceCount > 0)
                {
                    deletions.AddRange(tempParam.Sources); //add source sliders to deletions list
                }

                if (obj.NickName.StartsWith(_controlComponentName + "points"))
                {
                    foreach (IGH_Param recip in tempParam.Recipients)
                    {
                        PointRecvParams.Add(recip);
                    }
                }

                if (obj.NickName.StartsWith(_controlComponentName + "slids")) //the integer params
                {
                    int ObjectIndex;
                    Int32.TryParse(System.Text.RegularExpressions.Regex.Match(obj.NickName, @"(\d+)\z").Value, out ObjectIndex); //regex to extract index number from end of param name
                    List <IGH_Param> receivingParams = new List <IGH_Param>();
                    foreach (IGH_Param recip in tempParam.Recipients)
                    {
                        receivingParams.Add(recip);
                    }
                    outputParams.Add(new OutputParam(ObjectIndex, receivingParams)); //put output param index and recipients into an object in a list
                }
            }
        }

        foreach (IGH_DocumentObject delobj in deletions) //delete the stuff
        {
            GrasshopperDocument.RemoveObject(delobj, false);
        }

        List <Grasshopper.Kernel.Parameters.Param_Integer> targetParam = new List <Grasshopper.Kernel.Parameters.Param_Integer>(); //holds the new output params as we build them  //rename targetParam

        for (int index = 0; index < _n.Count; index++)                                                                             //this loop runs once per slider bank    //rename index

        {
            targetParam.Add(new Grasshopper.Kernel.Parameters.Param_Integer());    //create the new output param
            targetParam[index].NickName = _controlComponentName + "slids" + index; //assign the name to the output param including the index number
            GrasshopperDocument.AddObject(targetParam[index], false);

            if (index == 0) //put param in place
            {
                targetParam[index].Attributes.Pivot = new System.Drawing.PointF(Component.Attributes.Pivot.X + 20, Component.Attributes.Pivot.Y + 110);
            }
            else
            {
                _n[index] = _n[index] + _n[index - 1]; //aggregate list of number of sliders per bank to create slider index breakpoints
                targetParam[index].Attributes.Pivot = new System.Drawing.PointF(Component.Attributes.Pivot.X + 20, Component.Attributes.Pivot.Y + 110 + _n[index - 1] * 20 + index * 10);
            }

            if (outputParams.Exists(opar => opar.outParam == index)) //looks in the list of deleted output params and determines if one has the same index as the param being created
            {
                foreach (IGH_Param receivingParam in outputParams.Find(opar => opar.outParam == index).recvParams)
                {
                    receivingParam.AddSource(targetParam[index]); //connects the new param to the old param stuff
                }
            }
        }

        Grasshopper.Kernel.Parameters.Param_Point pointsParam = new Grasshopper.Kernel.Parameters.Param_Point();
        pointsParam.NickName = _controlComponentName + "points";
        GrasshopperDocument.AddObject(pointsParam, false);
        pointsParam.Attributes.Pivot = new System.Drawing.PointF(Component.Attributes.Pivot.X + 20, Component.Attributes.Pivot.Y + 70);
        foreach (IGH_Param receivingParam in PointRecvParams)
        {
            receivingParam.AddSource(pointsParam);
        }

        pointsParam.SetPersistentData(_pointsdata.ToArray());



        int Yoffset      = -12;
        int CurrentParam = 0;

        for (int i = 0; i < _n[_n.Count - 1]; i++)
        {
            if (_n.Exists(x => x == i))
            {
                Yoffset = Yoffset + 10;
                CurrentParam++;
            }
            //instantiate  new slider
            Grasshopper.Kernel.Special.GH_NumberSlider slid = new Grasshopper.Kernel.Special.GH_NumberSlider();
            slid.CreateAttributes(); //sets up default values, and makes sure your slider doesn't crash rhino

            //customise slider (position, ranges etc)
            //targetParam.Attributes.Bounds


            slid.Attributes.Pivot     = new System.Drawing.PointF((float)targetParam[0].Attributes.Pivot.X - slid.Attributes.Bounds.Width - 70, (float)targetParam[0].Attributes.Pivot.Y + i * 20 + Yoffset);
            slid.Slider.Maximum       = 100;
            slid.Slider.Minimum       = 0;
            slid.Slider.DecimalPlaces = 0;
            // slid.SetSliderValue((decimal) (rnd.Next(-50, 51)));

            if (i + 1 > _dataIn.Count)
            {
                slid.SetSliderValue(_dataIn[_dataIn.Count - 1]);
            }
            else
            {
                slid.SetSliderValue(_dataIn[i]);
            }

            //Until now, the slider is a hypothetical object.
            // This command makes it 'real' and adds it to the canvas.
            GrasshopperDocument.AddObject(slid, false);

            //Connect the new slider to this component
            targetParam[CurrentParam].AddSource(slid);
        }
    }
 public SDF(List <ModelInfo> modelsP, ParamsData paramsObjP)
 {
     paramsObj = paramsObjP;
     models    = modelsP;
 }
Beispiel #10
0
    static unsafe void RunCompute(Sample sample, bool indirectSupported)
    {
        // build vertex layouts
        var quadLayout = new VertexLayout();

        quadLayout.Begin()
        .Add(VertexAttributeUsage.Position, 2, VertexAttributeType.Float)
        .End();

        var computeLayout = new VertexLayout();

        computeLayout.Begin()
        .Add(VertexAttributeUsage.TexCoord0, 4, VertexAttributeType.Float)
        .End();

        // static quad data
        var vb = new VertexBuffer(MemoryBlock.FromArray(QuadVertices), quadLayout);
        var ib = new IndexBuffer(MemoryBlock.FromArray(QuadIndices));

        // create compute buffers
        var currPositionBuffer0 = new DynamicVertexBuffer(1 << 15, computeLayout, BufferFlags.ComputeReadWrite);
        var currPositionBuffer1 = new DynamicVertexBuffer(1 << 15, computeLayout, BufferFlags.ComputeReadWrite);
        var prevPositionBuffer0 = new DynamicVertexBuffer(1 << 15, computeLayout, BufferFlags.ComputeReadWrite);
        var prevPositionBuffer1 = new DynamicVertexBuffer(1 << 15, computeLayout, BufferFlags.ComputeReadWrite);

        // load shaders
        var particleProgram        = ResourceLoader.LoadProgram("vs_particle", "fs_particle");
        var initInstancesProgram   = ResourceLoader.LoadProgram("cs_init_instances");
        var updateInstancesProgram = ResourceLoader.LoadProgram("cs_update_instances");

        // indirect rendering support
        var  indirectProgram = SharpBgfx.Program.Invalid;
        var  indirectBuffer  = IndirectBuffer.Invalid;
        bool useIndirect     = false;

        if (indirectSupported)
        {
            indirectProgram = ResourceLoader.LoadProgram("cs_indirect");
            indirectBuffer  = new IndirectBuffer(2);
            useIndirect     = true;
        }

        // setup params uniforms
        var paramData = new ParamsData {
            TimeStep          = 0.0157f,
            DispatchSize      = 32,
            Gravity           = 0.109f,
            Damping           = 0.25f,
            ParticleIntensity = 0.64f,
            ParticleSize      = 0.279f,
            BaseSeed          = 57,
            ParticlePower     = 3.5f,
            InitialSpeed      = 3.2f,
            InitialShape      = 1,
            MaxAccel          = 100.0f
        };

        // have the compute shader run initialization
        var u_params = new Uniform("u_params", UniformType.Vector4, 3);

        Bgfx.SetUniform(u_params, &paramData, 3);
        Bgfx.SetComputeBuffer(0, prevPositionBuffer0, ComputeBufferAccess.Write);
        Bgfx.SetComputeBuffer(1, currPositionBuffer0, ComputeBufferAccess.Write);
        Bgfx.Dispatch(0, initInstancesProgram, MaxParticleCount / ThreadGroupUpdateSize);

        // start the frame clock
        var clock = new Clock();

        clock.Start();

        // main loop
        while (sample.ProcessEvents(ResetFlags.Vsync))
        {
            // tick the clock
            var elapsed = clock.Frame();
            var time    = clock.TotalTime();

            // write some debug text
            Bgfx.DebugTextClear();
            Bgfx.DebugTextWrite(0, 1, DebugColor.White, DebugColor.Blue, "SharpBgfx/Samples/24-NBody");
            Bgfx.DebugTextWrite(0, 2, DebugColor.White, DebugColor.Cyan, "Description: N-body simulation with compute shaders using buffers.");
            Bgfx.DebugTextWrite(0, 3, DebugColor.White, DebugColor.Cyan, "Frame: {0:F3} ms", elapsed * 1000);

            // fill the indirect buffer if we're using it
            if (useIndirect)
            {
                Bgfx.SetUniform(u_params, &paramData, 3);
                Bgfx.SetComputeBuffer(0, indirectBuffer, ComputeBufferAccess.Write);
                Bgfx.Dispatch(0, indirectProgram);
            }

            // update particle positions
            Bgfx.SetComputeBuffer(0, prevPositionBuffer0, ComputeBufferAccess.Read);
            Bgfx.SetComputeBuffer(1, currPositionBuffer0, ComputeBufferAccess.Read);
            Bgfx.SetComputeBuffer(2, prevPositionBuffer1, ComputeBufferAccess.Write);
            Bgfx.SetComputeBuffer(3, currPositionBuffer1, ComputeBufferAccess.Write);
            Bgfx.SetUniform(u_params, &paramData, 3);
            if (useIndirect)
            {
                Bgfx.Dispatch(0, updateInstancesProgram, indirectBuffer, 1);
            }
            else
            {
                Bgfx.Dispatch(0, updateInstancesProgram, paramData.DispatchSize);
            }

            // ping-pong the buffers for next frame
            Swap(ref currPositionBuffer0, ref currPositionBuffer1);
            Swap(ref prevPositionBuffer0, ref prevPositionBuffer1);

            // view transforms for particle rendering
            var viewMatrix = Matrix4x4.CreateLookAt(new Vector3(0.0f, 0.0f, -45.0f), -Vector3.UnitZ, Vector3.UnitY);
            var projMatrix = Matrix4x4.CreatePerspectiveFieldOfView((float)Math.PI / 4, (float)sample.WindowWidth / sample.WindowHeight, 0.1f, 10000.0f);
            Bgfx.SetViewTransform(0, &viewMatrix.M11, &projMatrix.M11);
            Bgfx.SetViewRect(0, 0, 0, sample.WindowWidth, sample.WindowHeight);

            // draw the particles
            Bgfx.SetVertexBuffer(vb);
            Bgfx.SetIndexBuffer(ib);
            Bgfx.SetInstanceDataBuffer(currPositionBuffer0, 0, paramData.DispatchSize * ThreadGroupUpdateSize);
            Bgfx.SetRenderState(RenderState.ColorWrite | RenderState.BlendAdd | RenderState.DepthTestAlways);
            if (useIndirect)
            {
                Bgfx.Submit(0, particleProgram, indirectBuffer);
            }
            else
            {
                Bgfx.Submit(0, particleProgram);
            }

            // done with frame
            Bgfx.Frame();
        }

        // cleanup
        if (indirectSupported)
        {
            indirectProgram.Dispose();
            indirectBuffer.Dispose();
        }

        u_params.Dispose();
        currPositionBuffer0.Dispose();
        currPositionBuffer1.Dispose();
        prevPositionBuffer0.Dispose();
        prevPositionBuffer1.Dispose();
        updateInstancesProgram.Dispose();
        initInstancesProgram.Dispose();
        particleProgram.Dispose();
        ib.Dispose();
        vb.Dispose();
    }
Beispiel #11
0
 private object getMetodParametersValuesByInvoke(ParameterInfo parameter, InvokeData data, ParamsData paramsData)
 {
     try
     {
         var flag = getMetodParameterValue(parameter, data.ParamsJson, out object value);
         if (flag && value != null && !string.IsNullOrWhiteSpace(value.ToString()))
         {
             return(value);
         }
     }
     catch (Exception ex)
     {
     }
     try
     {
         var flag = getMetodParameterValueByName(parameter, data.NameParams, out object value);
         if (flag)
         {
             return(value);
         }
     }
     catch (Exception ex)
     {
     }
     try
     {
         var flag = getMetodParameterValueByType(parameter, data.TypeParams, out object value);
         if (flag)
         {
             return(value);
         }
     }
     catch (Exception ex)
     {
     }
     try
     {
         var flag = getMetodParamsCount1Value(parameter, paramsData, data.ParamsJson, out object value);
         if (flag)
         {
             return(value);
         }
     }
     catch (Exception ex)
     {
     }
     return(null);
 }
Beispiel #12
0
        private object getMetodParametersValues(ParameterInfo parameter, InvokeData data, ParamsData paramsData)
        {
            var value = getMetodParametersValuesByInvoke(parameter, data, paramsData);

            if (value == null || string.IsNullOrWhiteSpace(value.ToString()))
            {
                value = getTypeDefaultValue(parameter);
            }
            return(value);
        }