protected void Initialize() { Flex.SetBinding(FlexLayout.DirectionProperty, new Binding(nameof(Direction), source: this)); ButtonImage.SetBinding(Image.SourceProperty, new Binding(nameof(ImageSource), source: this)); ButtonLabel.SetBinding(Label.FontSizeProperty, new Binding(nameof(FontSize), source: this)); ButtonLabel.SetBinding(Label.FontFamilyProperty, new Binding(nameof(FontFamily), source: this)); ButtonLabel.SetBinding(Label.FontAttributesProperty, new Binding(nameof(FontAttributes), source: this)); ButtonLabel.SetBinding(Label.TextProperty, new Binding(nameof(Text), source: this)); ButtonLabel.SetBinding(Label.TextColorProperty, new Binding(nameof(TextColor), source: this)); ButtonLabel.SetBinding(Label.VerticalTextAlignmentProperty, new Binding(nameof(VerticalTextAlignment), source: this)); ButtonLabel.SetBinding(Label.HorizontalTextAlignmentProperty, new Binding(nameof(HorizontalTextAlignment), source: this)); this.GestureRecognizers.Add(new TapGestureRecognizer { Command = new Command(() => { this.Tapped?.Invoke(this, EventArgs.Empty); if (Command != null) { if (Command.CanExecute(CommandParameter)) { Command.Execute(CommandParameter); } } }), }); }
/// <summary> /// This is the method that actually does the work. /// </summary> /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param> protected override void SolveInstance(IGH_DataAccess DA) { counter++; DA.GetData(1, ref n); n = Math.Max(1, n); if (counter % n == 0) { Flex flex = null; DA.GetData(0, ref flex); if (flex != null) { List <FlexParticle> part = flex.Scene.GetFluidParticles(); pts = new GH_Structure <GH_Point>(); vel = new GH_Structure <GH_Vector>(); foreach (FlexParticle fp in part) { GH_Path p = new GH_Path(fp.GroupIndex); pts.Append(new GH_Point(new Point3d(fp.PositionX, fp.PositionY, fp.PositionZ)), p); vel.Append(new GH_Vector(new Vector3d(fp.VelocityX, fp.VelocityY, fp.VelocityZ)), p); } } } DA.SetDataTree(0, pts); DA.SetDataTree(1, vel); }
// Update is called once per frame void Update() { // Map buffers for reading / writing. particles = Flex.Map(_particleBuffer); velocities = Flex.Map(_velocityBuffer); phases = Flex.Map(_phaseBuffer); // Spawn particles. //spawnParticles(particles, velocities, phases); // Render particles. RenderParticles(particles, velocities, phases); // Unmap buffers. Flex.Unmap(_particleBuffer); Flex.Unmap(_velocityBuffer); Flex.Unmap(_phaseBuffer); // Write to device (async). Flex.SetParticles(_solver, _particleBuffer); Flex.SetVelocities(_solver, _velocityBuffer); Flex.SetPhases(_solver, _phaseBuffer); // Tick. Flex.UpdateSolver(_solver, Time.deltaTime, 1); // Read back (async). Flex.GetParticles(_solver, _particleBuffer); Flex.GetVelocities(_solver, _velocityBuffer); Flex.GetPhases(_solver, _phaseBuffer); }
private void Awake() { _library = Flex.Init(); Flex.SolverDesc _solverDesc = new Flex.SolverDesc(); Flex.SetSolverDescDefaults(ref _solverDesc); _solver = Flex.CreateSolver(_library, ref _solverDesc); _particleBuffer = Flex.AllocBuffer(_library, 28, sizeof(float) * 4, Flex.BufferType.Host); _velocityBuffer = Flex.AllocBuffer(_library, 28, sizeof(float) * 4, Flex.BufferType.Host); _phaseBuffer = Flex.AllocBuffer(_library, 28, sizeof(int), Flex.BufferType.Host); _activeBuffer = Flex.AllocBuffer(_library, 28, sizeof(int), Flex.BufferType.Host); unsafe { int *activeIndices = (int *)Flex.Map(_activeBuffer); for (int i = 0; i < 28; ++i) { activeIndices[i] = i; } Flex.Unmap(_activeBuffer); Flex.SetActive(_solver, _activeBuffer); Flex.SetActiveCount(_solver, 28); } }
void Map() { if (m_pointer == default(IntPtr)) { m_pointer = Flex.Map(m_handle); } }
/// <summary> /// This is the method that actually does the work. /// </summary> /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param> protected override void SolveInstance(IGH_DataAccess DA) { counter++; DA.GetData(1, ref n); n = Math.Max(1, n); if (counter % n == 0) { Flex flex = null; DA.GetData(0, ref flex); if (flex != null) { List <FlexParticle> part = flex.Scene.GetAllParticles(); List <int> springsPairIndices = flex.Scene.GetSpringPairIndices(); lineTree = new GH_Structure <GH_Line>(); for (int i = 0; i < springsPairIndices.Count / 2; i++) { lineTree.Append( new GH_Line( new Line( new Point3d(part[springsPairIndices[2 * i]].PositionX, part[springsPairIndices[2 * i]].PositionY, part[springsPairIndices[2 * i]].PositionZ), new Point3d(part[springsPairIndices[2 * i + 1]].PositionX, part[springsPairIndices[2 * i + 1]].PositionY, part[springsPairIndices[2 * i + 1]].PositionZ))), new GH_Path(part[springsPairIndices[2 * i]].GroupIndex)); } } } DA.SetDataTree(0, lineTree); }
void UpdateSolver() { m_particleData.container = this; m_particleData.particleData = FlexExt.MapParticleData(m_containerHandle); UpdateBuffer(m_particleData.particleData); #if UNITY_EDITOR if (m_showTimers) { Flex.GetTimers(m_solverHandle, ref m_timers); } #endif FlexExt.UpdateInstances(m_containerHandle); UpdateDrawFluid(m_particleData); UpdateDetectShapes(m_particleData); m_fluidIndexCount = 0; if (onFlexUpdate != null) { onFlexUpdate(m_particleData); } FlexExt.UnmapParticleData(m_containerHandle); #if UNITY_EDITOR FlexExt.TickContainer(m_containerHandle, Time.fixedDeltaTime, m_substepCount, m_showTimers); #else FlexExt.TickContainer(m_containerHandle, Time.fixedDeltaTime, m_substepCount); #endif }
private void UpdateWind() { // Retrieve the wind from the Flex Solver Flex.Params windParams = new Flex.Params(); Flex.GetParams(container.solver, ref windParams); // Swap the windtype if the current windtype has exceeded its duration if (currentWind.HasEnded) { float lastWindSpeed = currentWind.currentSpeed; float lastSwivel = currentWind.currentSwivel; currentWind = (currentWind.Equals(wind)) ? burstWind : wind; currentWind.Init(lastWindSpeed, lastSwivel); } // Update and set the wind values and rotate the flag parents to look in the right direction currentWind.UpdateWind(); currentWindDirection = Quaternion.AngleAxis(currentWind.currentSwivel, Vector3.up) * windDirection; currentWindDirection.Normalize(); windParams.wind = currentWind.currentSpeed * currentWindDirection; windParams.wind.y = currentWind.currentSpeed / 8f; // <-- MAGIC NUMBER !!! TODO: create a function for upward wind lift. RotateParents(); // Update the wind in the Flex Solver Flex.SetParams(container.solver, ref windParams); }
public void FileNameAccess(string filesystem, string pathname, string name, string basename, string extension) { IFileName filename = null; switch (filesystem.ToLower()) { case "dragondos": filename = DragonDos.GetFileName(pathname); break; case "flex": filename = Flex.GetFileName(pathname); break; case "os9": filename = OS9.GetFileName(pathname); break; case "rsdos": filename = RsDos.GetFileName(pathname); break; default: Assert.True(false, "Unknown filesystem " + filesystem); break; } Assert.Equal(name, filename.Name); Assert.Equal(basename, filename.Base); Assert.Equal(extension, filename.Extension); //TODO Add test for Ascend method //TODO Add test for Descend method }
protected override async void OnAppearing() { base.OnAppearing(); if (topLevelDataModel == null) { topLevelDataModel = await TopLevelDataModel.Load(); } if (Activities == null) { Activities = GatherActivities(); } NavigationPage.SetHasNavigationBar(this, false); foreach (var activity in Activities) { var matchingFrame = Flex.FindByName <Frame> (activity.Name + "Frame"); if (matchingFrame != null) { var binding = new Binding("IsAllowed"); binding.Source = activity; matchingFrame.SetBinding(Frame.IsVisibleProperty, binding); var subButton = matchingFrame.FindByName <ImageButton> (activity.Name); if (subButton != null) { binding = new Binding("IsEnabled"); binding.Source = activity; subButton.SetBinding(ImageButton.IsEnabledProperty, binding); } } } Identifier.Text = topLevelDataModel.UserFirstName; }
public void TestCreateDestroyContainerWithDevice() { Flex.InitDesc desc = new Flex.InitDesc { deviceIndex = -1, enableExtensions = false, #if FLEX_CUDA computeType = Flex.ComputeType.CUDA, #else computeType = Flex.ComputeType.D3D11, #endif renderContext = default(IntPtr), renderDevice = default(IntPtr) }; Flex.Library lib = Flex.Init(Flex.FLEX_VERSION, ErrorCallback, ref desc); Flex.SolverDesc slvDsc = default(Flex.SolverDesc); Flex.SetSolverDescDefaults(ref slvDsc); slvDsc.maxParticles = 1000; Flex.Solver solver = Flex.CreateSolver(lib, ref slvDsc); FlexExt.Container container = FlexExt.CreateContainer(lib, solver, 10000); FlexExt.DestroyContainer(container); Flex.DestroySolver(solver); Flex.Shutdown(lib); }
protected virtual void CreateInstance() { if (m_currentContainer && m_currentContainer.handle && m_currentAsset && m_currentAsset.handle) { int group = m_particleGroup < 0 ? ++sm_nextGroup : m_particleGroup; Flex.Phase flags = Flex.Phase.Default; if (m_selfCollide) { flags |= Flex.Phase.SelfCollide; } if (m_selfCollideFilter) { flags |= Flex.Phase.SelfCollideFilter; } if (m_fluid) { flags |= Flex.Phase.Fluid; } m_phase = Flex.MakePhase(group, flags); m_instanceHandle = m_currentContainer.CreateInstance(m_currentAsset.handle, transform.localToWorldMatrix, Vector3.zero, m_phase, m_massScale); if (m_instanceHandle) { FlexExt.Instance instance = m_instanceHandle.instance; m_indices = new int[m_currentAsset.maxParticles]; m_indexCount = instance.numParticles; if (m_indexCount > 0) { FlexUtils.FastCopy(instance.particleIndices, 0, ref m_indices[0], 0, sizeof(int) * m_indexCount); } } } }
public void TestCreateDestroyInstance() { Flex.Library lib = Flex.Init(Flex.FLEX_VERSION, ErrorCallback); Flex.SolverDesc slvDsc = default(Flex.SolverDesc); Flex.SetSolverDescDefaults(ref slvDsc); slvDsc.maxParticles = 1000; Flex.Solver solver = Flex.CreateSolver(lib, ref slvDsc); FlexExt.Container container = FlexExt.CreateContainer(lib, solver, 1000); FlexExt.Asset.Handle asset = CreateTestClothAsset(); FlexExt.ParticleData data = FlexExt.MapParticleData(container); Matrix4x4 transform = Matrix4x4.identity; FlexExt.Instance.Handle instance = FlexExt.CreateInstance(container, ref data, asset, ref transform, 1.0f, 1.0f, 1.0f, Flex.MakePhase(1, Flex.Phase.Default), 1.0f); Assert.AreEqual(asset.asset.numParticles, instance.instance.numParticles); FlexExt.DestroyInstance(container, instance); FlexExt.UnmapParticleData(container); FlexExt.DestroyAsset(asset); FlexExt.DestroyContainer(container); Flex.DestroySolver(solver); Flex.Shutdown(lib); }
void UpdateParams() { Flex.Params prms = new Flex.Params(); Flex.GetParams(m_solverHandle, ref prms); prms.numIterations = m_iterationCount; prms.gravity = m_gravity; prms.radius = m_radius; prms.solidRestDistance = m_solidRest; prms.fluidRestDistance = m_fluidRest; prms.staticFriction = m_staticFriction; prms.dynamicFriction = m_dynamicFriction; prms.particleFriction = m_particleFriction; prms.restitution = m_restitution; prms.adhesion = m_adhesion; prms.sleepThreshold = m_sleepThreshold; prms.maxSpeed = m_maxSpeed; prms.maxAcceleration = m_maxAcceleration; prms.shockPropagation = m_shockPropagation; prms.dissipation = m_dissipation; prms.damping = m_damping; prms.wind = m_wind; prms.drag = m_drag; prms.lift = m_lift; //prms.fluid = m_fluid; prms.cohesion = m_cohesion; prms.surfaceTension = m_surfaceTension; prms.viscosity = m_viscosity; prms.vorticityConfinement = m_vorticityConfinement; prms.anisotropyScale = m_anisotropyScale; prms.anisotropyMin = m_anisotropyMin; prms.anisotropyMax = m_anisotropyMax; prms.smoothing = m_smoothing; prms.solidPressure = m_solidPressure; prms.freeSurfaceDrag = m_freeSurfaceDrag; prms.buoyancy = m_buoyancy; prms.diffuseThreshold = m_diffuseThreshold; prms.diffuseBuoyancy = m_diffuseBuoyancy; prms.diffuseDrag = m_diffuseDrag; prms.diffuseBallistic = m_diffuseBallistic; //prms.diffuseSortAxis = m_diffuseSortAxis; prms.diffuseLifetime = m_diffuseLifetime; //prms.plasticThreshold = m_plasticThreshold; //prms.plasticCreep = m_plasticCreep; prms.collisionDistance = m_collisionDistance; prms.particleCollisionMargin = m_particleCollisionMargin; prms.shapeCollisionMargin = m_shapeCollisionMargin; prms.numPlanes = m_planes.Length; prms.plane0 = m_planes.Length > 0 ? m_planes[0] : Vector4.zero; prms.plane1 = m_planes.Length > 1 ? m_planes[1] : Vector4.zero; prms.plane2 = m_planes.Length > 2 ? m_planes[2] : Vector4.zero; prms.plane3 = m_planes.Length > 3 ? m_planes[3] : Vector4.zero; prms.plane4 = m_planes.Length > 4 ? m_planes[4] : Vector4.zero; prms.plane5 = m_planes.Length > 5 ? m_planes[5] : Vector4.zero; prms.plane6 = m_planes.Length > 6 ? m_planes[6] : Vector4.zero; prms.plane7 = m_planes.Length > 7 ? m_planes[7] : Vector4.zero; prms.relaxationMode = m_relaxationMode; prms.relaxationFactor = m_relaxationFactor; Flex.SetParams(m_solverHandle, ref prms); }
private void ProcessParticles(bool countChanged) { for (int iId = 0; iId < m_flexGameObjects.Count && iId < m_activeInstacesCount; iId++) { Transform tr = m_flexGameObjects[iId].transform; FlexParticles particles = m_flexGameObjects[iId]; if (particles && particles.enabled) { if (m_flexGameObjects[iId].m_initialized) //if initialized just update some arrays { Array.Copy(particles.m_particles, 0, m_particles, particles.m_particlesIndex, particles.m_particlesCount); Array.Copy(particles.m_restParticles, 0, m_restParticles, particles.m_particlesIndex, particles.m_particlesCount); Array.Copy(particles.m_velocities, 0, m_velocities, particles.m_particlesIndex, particles.m_particlesCount); Array.Copy(particles.m_particlesActivity, 0, m_particlesActivity, particles.m_particlesIndex, particles.m_particlesCount); particles.m_collisionGroup = particles.m_collisionGroup == -1 ? iId : particles.m_collisionGroup; int phase = Flex.MakePhase(particles.m_collisionGroup, (int)particles.m_interactionType); for (int pId = 0; pId < particles.m_particlesCount; pId++) { m_phases[pId + particles.m_particlesIndex] = phase; } //needs to update this if the flex game object is changing position in the containcer (i.e. iId) //particles.m_collisionGroup = particles.m_collisionGroup == -1 ? iId : particles.m_collisionGroup; //int phase = Flex.MakePhase(particles.m_collisionGroup, (int)particles.m_interactionType); //for (int pId = 0; pId < particles.m_particlesCount; pId++) //{ // m_phases[pId + particles.m_particlesIndex] = phase; //} } else // do the full init { //if group is -1 set the consecutive bodyId, else use a user defined number particles.m_collisionGroup = particles.m_collisionGroup == -1 ? iId : particles.m_collisionGroup; int phase = Flex.MakePhase(particles.m_collisionGroup, (int)particles.m_interactionType); float invMass = particles.m_mass == 0 ? 0.0f : 1.0f / particles.m_mass; for (int pId = 0; pId < particles.m_particlesCount; pId++) { m_particles[pId + particles.m_particlesIndex].pos = tr.TransformPoint(particles.m_particles[pId].pos); m_particles[pId + particles.m_particlesIndex].invMass = particles.m_overrideMass ? invMass : particles.m_particles[pId].invMass; m_restParticles[pId + particles.m_particlesIndex] = particles.m_restParticles[pId]; //m_velocities[pId + particles.m_particlesIndex] = particles.m_velocities[pId]; m_velocities[pId + particles.m_particlesIndex] = particles.m_initialVelocity; m_colors[pId + particles.m_particlesIndex] = particles.m_colours[pId]; m_phases[pId + particles.m_particlesIndex] = phase; m_particlesActivity[pId + particles.m_particlesIndex] = particles.m_particlesActivity[pId]; } m_flexGameObjects[iId].m_initialized = true; } } } //m_particlesCount = UpdateActiveSet(); m_activeParticlesCount = UpdateActiveSet(); }
// StyleSetAspectRatio sets axpect ratio public void StyleSetAspectRatio(float aspectRatio) { if (this.nodeStyle.AspectRatio != aspectRatio) { this.nodeStyle.AspectRatio = aspectRatio; Flex.nodeMarkDirtyInternal(this); } }
// StyleSetFlexDirection sets flex directions public void StyleSetFlexDirection(FlexDirection flexDirection) { if (this.nodeStyle.FlexDirection != flexDirection) { this.nodeStyle.FlexDirection = flexDirection; Flex.nodeMarkDirtyInternal(this); } }
public void Load() { Flex lic = new Flex("..\\..\\artifacts\\testlic.xml"); Assert.AreEqual(lic.Company, "Projzilla"); Assert.AreEqual(lic.Name, "David McCormack"); Assert.AreEqual(lic.Email, "*****@*****.**"); }
// StyleSetDisplay sets display public void StyleSetDisplay(Display display) { if (this.nodeStyle.Display != display) { this.nodeStyle.Display = display; Flex.nodeMarkDirtyInternal(this); } }
// StyleSetFlexWrap sets flex wrap public void StyleSetFlexWrap(Wrap flexWrap) { if (this.nodeStyle.FlexWrap != flexWrap) { this.nodeStyle.FlexWrap = flexWrap; Flex.nodeMarkDirtyInternal(this); } }
// StyleSetAlignSelf sets align self public void StyleSetAlignSelf(Align alignSelf) { if (this.nodeStyle.AlignSelf != alignSelf) { this.nodeStyle.AlignSelf = alignSelf; Flex.nodeMarkDirtyInternal(this); } }
// StyleSetAlignItems sets align content public void StyleSetAlignItems(Align alignItems) { if (this.nodeStyle.AlignItems != alignItems) { this.nodeStyle.AlignItems = alignItems; Flex.nodeMarkDirtyInternal(this); } }
// StyleSetAlignContent sets align content public void StyleSetAlignContent(Align alignContent) { if (this.nodeStyle.AlignContent != alignContent) { this.nodeStyle.AlignContent = alignContent; Flex.nodeMarkDirtyInternal(this); } }
// StyleSetJustifyContent sets justify content public void StyleSetJustifyContent(Justify justifyContent) { if (this.nodeStyle.JustifyContent != justifyContent) { this.nodeStyle.JustifyContent = justifyContent; Flex.nodeMarkDirtyInternal(this); } }
void CopyBufferContent(Flex.Buffer source, ComputeBuffer target) { IntPtr ptr = Flex.Map(source, Flex.MapFlags.Wait); FlexUtils.FastCopy(ptr, m_temporaryBuffer); target.SetData(m_temporaryBuffer); Flex.Unmap(source); }
// StyleSetFlex sets flex public void StyleSetFlex(float flex) { if (this.nodeStyle.Flex != flex) { this.nodeStyle.Flex = flex; Flex.nodeMarkDirtyInternal(this); } }
// StyleSetFlexGrow sets flex grow public void StyleSetFlexGrow(float flexGrow) { if (this.nodeStyle.FlexGrow != flexGrow) { this.nodeStyle.FlexGrow = flexGrow; Flex.nodeMarkDirtyInternal(this); } }
// StyleSetFlexShrink sets flex shrink public void StyleSetFlexShrink(float flexShrink) { if (this.nodeStyle.FlexShrink != flexShrink) { this.nodeStyle.FlexShrink = flexShrink; Flex.nodeMarkDirtyInternal(this); } }
// StyleSetOverflow sets overflow public void StyleSetOverflow(Overflow overflow) { if (this.nodeStyle.Overflow != overflow) { this.nodeStyle.Overflow = overflow; Flex.nodeMarkDirtyInternal(this); } }
// StyleSetDirection sets direction public void StyleSetDirection(Direction direction) { if (this.nodeStyle.Direction != direction) { this.nodeStyle.Direction = direction; Flex.nodeMarkDirtyInternal(this); } }
public byte* Put(string s) { int cbAvailable = AvailableBytes, sLen = s.Length, misalignment = sLen & 0x7; // strive for 8-byte alignment if (misalignment != 0) sLen += 8 - misalignment; if (sLen <= cbAvailable) { byte[] bytes = Encoding.ASCII.GetBytes(s); fixed (byte* pBytes = bytes) NativeMethods.memcpy(_byteBufPtr, pBytes, (UIntPtr)bytes.Length); var pStart = _byteBufPtr; _byteBufPtr += sLen; return pStart; } return (_next ?? (_next = new Flex())).Put(s); }