Ejemplo n.º 1
0
        public void SetApexHeight(Point2D apexPoint, float value, int lod)
        {
            Preconditions.Assert(lod >= _submap.LodFactor, "Cant set apex height. Lod factor is too small");
            var pixelSize = (int)Math.Pow(2, lod - _submap.LodFactor);

            if (Equals(apexPoint, _submap.SubmapPosition.DownLeftPoint))
            {
                _submap.Heightmap.SetDownLeftApexMarginHeight(value, pixelSize);
            }
            else if (Equals(apexPoint, _submap.SubmapPosition.DownRightPoint))
            {
                _submap.Heightmap.SetDownRightApexMarginHeight(value, pixelSize);
            }
            else if (Equals(apexPoint, _submap.SubmapPosition.TopLeftPoint))
            {
                _submap.Heightmap.SetTopLeftApexMarginHeight(value, pixelSize);
            }
            else if (Equals(apexPoint, _submap.SubmapPosition.TopRightPoint))
            {
                _submap.Heightmap.SetTopRightApexMarginHeight(value, pixelSize);
            }
            else
            {
                Preconditions.Fail(string.Format("Point {0} is not apex point", apexPoint));
            }
        }
Ejemplo n.º 2
0
        private IEnumerable <SolidTextureGeneratingStatus> Generate(int sideSize, int maxPixelsPerDispatch, string kernelName)
        {
            var slicesPerDispatch = (int)Math.Floor((float)maxPixelsPerDispatch / (sideSize * sideSize));

            Preconditions.Assert(slicesPerDispatch > 0, "MaxPixelsPerDispatch must be bigger, now it is 0");

            var texture = new RenderTexture(sideSize, sideSize, 0, RenderTextureFormat.R8, RenderTextureReadWrite.Default);

            texture.dimension         = TextureDimension.Tex3D;
            texture.enableRandomWrite = true;
            texture.volumeDepth       = sideSize;
            texture.wrapMode          = TextureWrapMode.Repeat;
            texture.Create();

            for (int i = 0; i < Mathf.CeilToInt((float)sideSize / slicesPerDispatch); i++)
            {
                ExecuteDispatch(sideSize, i, slicesPerDispatch, texture, kernelName).Wait();
                yield return(new SolidTextureGeneratingStatus()
                {
                    Done = false,
                    SolidTexture = texture
                });
            }
            yield return(new SolidTextureGeneratingStatus()
            {
                Done = true,
                SolidTexture = texture
            });
        }
Ejemplo n.º 3
0
        public ulong[] GenerateUniformGroupFromCycle(List <int> cycle, uint dimensions)
        {
            Preconditions.Assert(cycle.Count <= 64, "Cycle count must be <= 64 (ulong size)");
            ulong[] uniforms = new ulong[dimensions];
            for (int i = 0; i < cycle.Count; i++)
            {
                for (int d = 0; d < dimensions; d++)
                {
                    uniforms[d] = uniforms[d] << 1;
                    ulong bit = (((ulong)cycle[i]) >> d) & 1;  // we take i-th bit counting from right
                    uniforms[d] = uniforms[d] | bit;
                }
            }

            // le trick
            int repetitionsCount = Mathf.FloorToInt(64 / cycle.Count);
            int baseSize         = cycle.Count;

            for (int d = 0; d < dimensions; d++)
            {
                ulong repetitionBase = uniforms[d];
                for (int i = 1; i < repetitionsCount; i++)
                {
                    uniforms[d] = uniforms[d] | (repetitionBase << i * baseSize);
                }
            }

            return(uniforms);
        }
Ejemplo n.º 4
0
 public override void StartBehaviourTreeUpdate(BehaviourTreeRoot root)
 {
     Preconditions.Assert(_rootSnapshot == null, "RootSnapshotNotNull");
     Preconditions.Assert(_snapshotsStack == null, "SnapshotStack not null");
     _rootSnapshot   = CreateBaseTaskSnapshot(root.Child);
     _snapshotsStack = new Stack <AiRegistryTaskSnapshot>();
 }
Ejemplo n.º 5
0
        public void AddMultistepOrder(MultistepRenderingProcessOrder <Texture, TextureRenderingTemplate> processOrder)
        {
            var template = processOrder.Order;

            Preconditions.Assert(template.RenderingRectangle == null, "E781: Cannot render multistep when filling RenderTexture!");

            var outTextureInfo = template.OutTextureInfo;
            var shaderName     = template.ShaderName;
            var pack           = template.UniformPack;
            var material       = new Material(Shader.Find(shaderName));

            template.Keywords.EnableInMaterial(material);
            pack.SetUniformsToMaterial(material);
            var renderTextureFormat = template.RenderTextureFormat;

            MultistepTextureRenderingInput input = new MultistepTextureRenderingInput()
            {
                MultistepCoordUniform = new MultistepRenderingCoordUniform(
                    new Vector4(
                        template.Coords.X,
                        template.Coords.Y,
                        template.Coords.Width,
                        template.Coords.Height
                        ), "_Coords"),
                OutTextureinfo          = outTextureInfo,
                RenderTextureInfoFormat = renderTextureFormat,
                RenderMaterial          = material,
                StepSize        = _configuration.StepSize,
                CreateTexture2D = template.CreateTexture2D
            };

            _multistepTextureRenderer.StartRendering(input);
            _multistepProcessOrder = processOrder;
        }
Ejemplo n.º 6
0
        public HeightmapMarginWithInfo UpdateWherePossible(HeightmapMarginWithInfo newMargin)
        {
            //Preconditions.Assert( _heightmapMargin.Length == newMargin.HeightmapLength, todo change not to length but to lods
            //    string.Format("Current margin length is {0} != new margin length == {1} ", _heightmapMargin.Length, newMargin.HeightmapLength));
            Preconditions.Assert(
                (newMargin.Position.IsHorizontal && Position.IsHorizontal) ||
                (newMargin.Position.IsVertical && Position.IsVertical),
                string.Format("Current and new margins are one vertical one horizontal: Old {0} new {1}",
                              _heightmapMargin, newMargin));

            bool haveCommonElements = Position.HaveCommonElementWith(newMargin.Position);

            Preconditions.Assert(haveCommonElements,
                                 string.Format("Current {0} and new {1} margin dont have common elements", HeightmapMargin, newMargin));

            MarginPosition commonSegment = Position.GetCommonSegment(newMargin.Position);

            var ourStartPercent = Position.InvLerp(commonSegment.StartPoint);
            var ourStartOffset  = (int)Math.Round((double)HeightmapWorkingLength * ourStartPercent);

            var ourEndPercent = Position.InvLerp(commonSegment.EndPoint);
            var ourEndOffset  = (int)Math.Round((double)HeightmapWorkingLength * ourEndPercent);

            var theirStartPercent = newMargin.Position.InvLerp(commonSegment.StartPoint);
            var theirStartOffset  = (int)Math.Round((double)newMargin.HeightmapWorkingLength * theirStartPercent);

            var theirEndPercent = newMargin.Position.InvLerp(commonSegment.EndPoint);
            var theirEndOffset  = (int)Math.Round((double)newMargin.HeightmapWorkingLength * theirEndPercent);

            return(new HeightmapMarginWithInfo(
                       SetMarginSubElement(ourStartOffset, ourEndOffset, theirStartOffset, theirEndOffset, newMargin),
                       Position, LodFactor));
        }
        public StripRegistrationResult RegisterStrip(StripSide leader)
        {
            Preconditions.Assert(
                Math.Abs(leader.NormalizedMarginUvOfTerrain.x) < 0.00001f &&
                Math.Abs(leader.NormalizedMarginUvOfTerrain.y - 1) < 0.00001f,
                "Leader's marginUv must be 0-1, but is " + leader.NormalizedMarginUvOfTerrain);

            for (int i = 0; i < _stripColumns.Length; i++)
            {
                var column = _stripColumns[i];
                if (column.HasEmptyStrip)
                {
                    var stripInColumnIndex = column.AllocateStrip(leader);
                    return(new StripRegistrationResult()
                    {
                        StripPosition =
                            new WeldStripPosition()
                        {
                            ColumnIndex = i,
                            StripInColumnIndex = stripInColumnIndex
                        },
                        WeldUvs = TerrainWeldUvs.CreateFrom(leader.WeldSideType,
                                                            CreateNormalizedWeldRange(
                                                                CalculateWeldRange(stripInColumnIndex, leader.NormalizedMarginUvOfTerrain), i))
                    });
                }
            }
            Preconditions.Fail("E22. There are no empty strips");
            return(null);
        }
        public WeldStrip GetSegment(int index)
        {
            var strip = _strips[index];

            Preconditions.Assert(strip != null, $"E64 Strip of index {index} is not allocated");
            return(strip);
        }
        public void RemoveTerrain(int terrainId)
        {
            foreach (var pair in _terrainSideToStripPositions.Where(c => c.Key.TerrainId == terrainId)
                     .ToList()) // when given terrain is leader
            {
                _terrainSideToStripPositions.Remove(pair.Key);
                var wasRemoved = _level2Manager.RemoveWeld(pair.Value, terrainId);
                _followerStripPositions.Where(c => c.Value.Equals(pair.Value)).ToList()
                .ForEach(c => _followerStripPositions.Remove(c.Key));

                Preconditions.Assert(wasRemoved, "leader was removed, but there was no removal of strip");
            }
            foreach (var pair in _followerStripPositions.Where(c => c.Key.TerrainId == terrainId)
                     .ToList()) // when given terrain is follower
            {
                var wasRemoved = _level2Manager.RemoveWeld(pair.Value, terrainId);
                if (wasRemoved) //last follower - can removfe leader
                {
                    _terrainSideToStripPositions.Where(c => c.Value.Equals(pair.Value)).ToList()
                    .ForEach(c => _terrainSideToStripPositions.Remove(c.Key));
                }

                _followerStripPositions.Remove(pair.Key);
            }
        }
        private Vector2 CalculateFollowerMarginUv(WeldSideSource biggerTerrain, WeldSideSource smallerTerrain)
        {
            var biggerSideRange = new Vector2(0, 0);

            if (biggerTerrain.SideType.GetOrientation() == WeldOrientation.Horizontal)
            {
                biggerSideRange = RectangleUtils.CalculateSubPosition(biggerTerrain.Terrain.DetailGlobalArea,
                                                                      biggerTerrain.Terrain.UvCoordsPositions2D).XRange;
            }
            else
            {
                biggerSideRange = RectangleUtils.CalculateSubPosition(biggerTerrain.Terrain.DetailGlobalArea,
                                                                      biggerTerrain.Terrain.UvCoordsPositions2D).YRange;
            }

            var smallerSideRange = new Vector2(0, 0);

            if (smallerTerrain.SideType.GetOrientation() == WeldOrientation.Horizontal)
            {
                smallerSideRange = RectangleUtils.CalculateSubPosition(smallerTerrain.Terrain.DetailGlobalArea,
                                                                       smallerTerrain.Terrain.UvCoordsPositions2D).XRange;
            }
            else
            {
                smallerSideRange = RectangleUtils.CalculateSubPosition(smallerTerrain.Terrain.DetailGlobalArea,
                                                                       smallerTerrain.Terrain.UvCoordsPositions2D).YRange;
            }

            var uv = VectorUtils.CalculateSubelementUv(biggerSideRange, smallerSideRange);

            Preconditions.Assert(uv.IsNormalized(),
                                 $"E76 Margin uv is not normalized: {uv}, biggerSideRange:{biggerSideRange}, smallerSideRange {smallerSideRange}");
            return(uv);
        }
 public void AddSide(WeldSideSource weldSideSource)
 {
     if (weldSideSource.SideType == WeldSideType.Bottom)
     {
         Preconditions.Assert(First == null,
                              $"E12 Bottom of weld is arleady taken. New {weldSideSource}, old {First}");
         First = weldSideSource;
     }
     else if (weldSideSource.SideType == WeldSideType.Left)
     {
         Preconditions.Assert(First == null,
                              $"E12 Left of weld is arleady taken. New {weldSideSource}, old {First}");
         First = weldSideSource;
     }
     else if (weldSideSource.SideType == WeldSideType.Top)
     {
         Preconditions.Assert(Second == null,
                              $"E12 Top of weld is arleady taken. New {weldSideSource}, old {Second}");
         Second = weldSideSource;
     }
     else if (weldSideSource.SideType == WeldSideType.Right)
     {
         Preconditions.Assert(Second == null,
                              $"E12 Right of weld is arleady taken. New {weldSideSource}, old {Second}");
         Second = weldSideSource;
     }
     else
     {
         Preconditions.Fail("Not supported sideType " + weldSideSource.SideType);
     }
 }
Ejemplo n.º 12
0
        public async Task <TextureWithSize> RetriveHeightDetailElementAsync(string filename)
        {
            IntVector2 textureSize = new IntVector2(241, 241);
            var        path        = _mainDictionaryPath + filename + _extension;

            Preconditions.Assert(File.Exists(path), $"Cannot retrive heightDetailElement of path {path} as it does not exist");
            {
                var texture = await _commonExecutor.AddAction(() =>
                {
                    var tex = SavingFileManager.LoadPngTextureFromFile(path, textureSize.X, textureSize.Y,
                                                                       TextureFormat.ARGB32, true, true);
                    tex.wrapMode = TextureWrapMode.Clamp;
                    return(tex);
                });

                var transformator = new TerrainTextureFormatTransformator(_commonExecutor);
                var plainTexture  = await transformator.EncodedHeightTextureToPlainAsync(new TextureWithSize()
                {
                    Texture = texture,
                    Size    = textureSize
                });

                return(new TextureWithSize()
                {
                    Size = textureSize,
                    Texture = plainTexture
                });
            }
        }
 public void AddVectorArrayToBlock(IUniformArray uniformArray, int elementsToSkipCount, int elementsToTakeCount)
 {
     Preconditions.Assert(uniformArray.Count == _arraySize,
                          string.Format("Cant add vector of length {0} to block, as block length is {1}", uniformArray.Count,
                                        _arraySize));
     uniformArray.AddToBlock(_block, elementsToSkipCount, elementsToTakeCount);
 }
Ejemplo n.º 14
0
        public List <uint> ClaimForGroup(List <Vector2> positions)
        {
            Preconditions.Assert(!IsDirty, "Cannot claim for group, registry is dirty");
            Preconditions.Assert(IsEmpty, "Cannot claim for group, registry is not empty");
            Preconditions.Assert(positions.Count <= _configuration.ScopeLength, "Group count is bigger than  scopeLength, count is " + positions.Count);

            _localeArray = ConstantSizeClaimableContainer <Vector2?> .CreateFull(_configuration.ScopeLength);

            for (int i = 0; i < positions.Count; i++)
            {
                _localeArray.SetElementWithoutClaimedSpaceChanges(positions[i], i);
            }

            var outList = new List <uint>();

            for (uint i = 0; i < positions.Count; i++)
            {
                _updateOrders.Add(new EPropLocaleBufferScopeUpdateOrder()
                {
                    Index        = i,
                    FlatPosition = positions[(int)i]
                });
                outList.Add(i);
            }

            return(outList);
        }
        public void AddSegment(SegmentInformation segmentInfo)
        {
            var sap = segmentInfo.SegmentAlignedPosition;

            Preconditions.Assert(!_tokensDict.ContainsKey(sap), $"There arleady is segment of sap {sap}");

            RequiredSegmentSituation requiredSituation;
            bool fillingIsNecessary;

            if (segmentInfo.SegmentState == SegmentState.Active)
            {
                fillingIsNecessary = true;
                requiredSituation  = RequiredSegmentSituation.Filled;
            }
            else if (segmentInfo.SegmentState == SegmentState.Standby)
            {
                fillingIsNecessary = false;
                requiredSituation  = RequiredSegmentSituation.Filled;
            }
            else
            {
                fillingIsNecessary = false;
                requiredSituation  = RequiredSegmentSituation.Created;
            }
            var newToken = new SegmentGenerationProcessToken(SegmentGenerationProcessSituation.BeforeStartOfCreation, requiredSituation);

            _tokensDict[sap] = new SegmentGenerationProcessTokenWithFillingNecessity()
            {
                Token = newToken,
                FillingIsNecessary = fillingIsNecessary
            };
            _executor.ExecuteSegmentAction(newToken, sap);
        }
Ejemplo n.º 16
0
        public async Task <bool> AddAssetAsync(TQuery query, TAsset asset)
        {
            LogUsedMemory();
            var activeTreeElement = TryRetriveAssetFromTree(query);

            Preconditions.Assert(activeTreeElement == null,
                                 "There arleady is one detailElement of given description: qa: " + query);

            var newElement = new ReferenceCountedAsset()
            {
                Element        = asset,
                ReferenceCount = 1
            };

            await ClearNonReferencedElements();

            if (await ThereIsPlaceForNewAssetAsync(asset))
            {
                await AddElementToActiveTreeAsync(query, newElement);

                return(true);
            }
            else
            {
                return(false);
            }
        }
Ejemplo n.º 17
0
 public HeightmapArray SimplyfyHeightmapNoMargins(HeightmapArray heightmap, int newWidth, int newHeight)
 {
     Preconditions.Assert(!heightmap.HasMargin, "heightmap Does Have margins");
     float[,] newHeightmap = SimplyfyByBlockAverageNoMargins(heightmap.HeightmapAsArray, newWidth,
                                                             newHeight);
     return(new HeightmapArray(newHeightmap));
 }
Ejemplo n.º 18
0
        public INprRenderingPostProcessingDirector ConfigureEnviroment(HatchGeneratingMode mode, GameObject cameraObject, GameObject hatchedObject)
        {
            Preconditions.Assert(PerModeConfigurations.Any(c => c.Mode == mode), "There is no configuration for mode " + mode);
            var conf = PerModeConfigurations.First(c => c.Mode == mode);

            hatchedObject.GetComponent <MeshRenderer>().material = conf.ObjectMaterial;
            if (conf.SourceGameObject != null)
            {
                foreach (var sourceComponent in conf.SourceGameObject.GetComponents <MonoBehaviour>())
                {
                    var newComponent = hatchedObject.AddComponent(sourceComponent.GetType());
                    ComponentUtils.CopyClassValues(sourceComponent, newComponent);
                }
            }


            INprRenderingPostProcessingDirector ppDirector = null;

            if (conf.SourceCameraObject != null)
            {
                foreach (var sourceComponent in conf.SourceCameraObject.GetComponents <MonoBehaviour>())
                {
                    var newComponent = cameraObject.AddComponent(sourceComponent.GetType());
                    ComponentUtils.CopyClassValues(sourceComponent, newComponent);
                    if (newComponent is INprRenderingPostProcessingDirector)
                    {
                        ppDirector = (INprRenderingPostProcessingDirector)newComponent;
                    }
                }
            }

            return(ppDirector);
        }
Ejemplo n.º 19
0
 public HeightmapMargin SetLength(int newWorkingLength)
 {
     if (WorkingLength > newWorkingLength)
     {
         Preconditions.Assert(WorkingLength % newWorkingLength == 0,
                              "New margin is not multiplication of current margin");
         var     newPointSize = Length / newWorkingLength;
         float[] newValues    = new float[newWorkingLength + 1];
         for (var i = 0; i < newWorkingLength; i++)
         {
             newValues[i] = _marginValues.Skip(i * newPointSize).Take(newPointSize).Sum() /
                            newPointSize; //average
         }
         newValues[newWorkingLength] = _marginValues[WorkingLength];
         return(new HeightmapMargin(newValues));
     }
     else if (WorkingLength < newWorkingLength)
     {
         Preconditions.Assert(newWorkingLength % WorkingLength == 0,
                              "New margin is not multiplication of current margin");
         var     newPointSize = newWorkingLength / WorkingLength;
         float[] newValues    = new float[newWorkingLength + 1];
         for (var i = 0; i < WorkingLength; i++)
         {
             for (var j = 0; j < newPointSize; j++)
             {
                 newValues[i * newPointSize + j] = Mathf.Lerp(_marginValues[i], _marginValues[i + 1],
                                                              (float)j / newPointSize);
             }
         }
         newValues[newWorkingLength] = _marginValues[WorkingLength];
         return(new HeightmapMargin(newValues));
     }
     return(new HeightmapMargin(_marginValues));
 }
Ejemplo n.º 20
0
 private void AssertPositionsAreCorrect(Point2D endPos, Point2D startPos)
 {
     Preconditions.Assert(!Equals(startPos, endPos),
                          string.Format("Start pos {0} and end pos {1} of margin can't be the same", startPos, endPos));
     Preconditions.Assert(startPos.X == endPos.X || startPos.Y == endPos.Y,
                          string.Format("Start pos {0} and end pos {1} are not horizontal nor vertical", startPos, endPos));
 }
Ejemplo n.º 21
0
        public float GetValue(IntVector2 point)
        {
            Preconditions.Assert(point.Y >= _yStart && point.Y < _yStart + _subArrayHeight, "Y not in area");
            float value = 0;

            value = _array[point.X, point.Y - _yStart];
            return(value);
        }
Ejemplo n.º 22
0
        public void Set(Vector2 point)
        {
            var pos = FindCellPosition(point);

            Preconditions.Assert(!_array[pos.X, pos.Y].HasValue,
                                 $"Grid cell of index {pos.X} {pos.Y} arleady has value!");
            _array[pos.X, pos.Y] = point;
        }
Ejemplo n.º 23
0
 public HeightmapArray SimplyfyHeightmap(HeightmapArray heightmap, int newWorkingWidth, int newWorkingHeight)
 {
     Preconditions.Assert(heightmap.HasMargin, "heightmap Does Not Have margins");
     float[,] newHeightmap = SimplyfyByBlockAverageIgnoreMergeMargins(heightmap.HeightmapAsArray,
                                                                      newWorkingWidth,
                                                                      newWorkingHeight);
     return(new HeightmapArray(newHeightmap));
 }
Ejemplo n.º 24
0
        public Dictionary <LocaleBufferScopeIndexType, EPropLocaleBufferScopeRegistry> TakeAwayScopes()
        {
            Preconditions.Assert(!IsDirty, "One of the scopes is still dirty");
            var toReturn = _scopes;

            _scopes = new Dictionary <LocaleBufferScopeIndexType, EPropLocaleBufferScopeRegistry>();
            return(toReturn);
        }
Ejemplo n.º 25
0
 private void FreeScopes(List <LocaleBufferScopeIndexType> scopesToFree)
 {
     foreach (var id in scopesToFree)
     {
         Preconditions.Assert(!_scopes[id].IsDirty, $"Scope of id {id} we are trying to free is still dirty");
         _scopes[id] = null;
     }
 }
        private async Task FillSegment(SegmentGenerationProcessToken token, IntVector2 sap)
        {
            Preconditions.Assert(token.CurrentSituation == SegmentGenerationProcessSituation.Created, "Unexpected situaton " + token.CurrentSituation);
            token.CurrentSituation = SegmentGenerationProcessSituation.DuringFilling;
            await _segmentFillingFunc(sap, _currentlyCreatedSegments[sap]);

            token.CurrentSituation = SegmentGenerationProcessSituation.Filled;
        }
Ejemplo n.º 27
0
        public void CreatedNewNode(Ring1Node ring1Node)
        {
            Preconditions.Assert(!_ring1NodePositionsToId.ContainsKey(ring1Node.Ring1Position),
                                 "Terrain was not created for this node");
            var newId = _lastId++;

            _ring1NodePositionsToId[ring1Node.Ring1Position] = newId;
            _currentOrder.NewListenersGenerator[newId]       = () => _newListenersCreator.CreateNewListener(ring1Node);
        }
Ejemplo n.º 28
0
        public MeshCurvatureDetailSE Generate(UnaliasedMesh mesh, int radius = 5, bool useKring = true)
        {
            //var originalVertices = mesh.vertices;
            //var originalTriangles = mesh.triangles;

            //var verticlesToOriginalVerticles = new Dictionary<Vector3, List<int>>();
            //for (int i = 0; i < originalVertices.Length; i++)
            //{
            //    var vert = originalVertices[i];
            //    if (!verticlesToOriginalVerticles.ContainsKey(vert))
            //    {
            //        verticlesToOriginalVerticles[vert] = new List<int>();
            //    }
            //    verticlesToOriginalVerticles[vert].Add(i);
            //}

            //var vertices = verticlesToOriginalVerticles.Keys.ToArray();

            //var originalIndexToIndexDict = new int[originalVertices.Length];
            //for (int i = 0; i < vertices.Length; i++)
            //{
            //    var v = vertices[i];
            //    foreach (var originalIndex in verticlesToOriginalVerticles[v])
            //    {
            //        originalIndexToIndexDict[originalIndex] = i;
            //    }
            //}

            //var triangles = originalTriangles
            //    .Select(c => originalIndexToIndexDict[c])
            //    .ToArray();

            var verticesFlatArray = mesh.Vertices.SelectMany(c => c.ToArray()).ToArray();
            var verticesCount     = mesh.Vertices.Length;
            var trianglesCount    = mesh.Triangles.Length / 3;

            var outDirection1 = new float[3 * verticesCount];
            var outDirection2 = new float[3 * verticesCount];
            var outValues1    = new float[verticesCount];
            var outValues2    = new float[verticesCount];

            PrincipalCurvatureDll.EnableLogging();
            int callStatus = PrincipalCurvatureDll.compute_principal_curvature(verticesFlatArray, verticesCount, mesh.Triangles, trianglesCount, outDirection1, outDirection2,
                                                                               outValues1, outValues2, radius, useKring);

            Preconditions.Assert(callStatus == 0, "Calling compute_principal_curvature failed, as returned status " + callStatus);

            var od1 = FlatArrayToVectorArray(outDirection1);
            var od2 = FlatArrayToVectorArray(outDirection2);

            return(MeshCurvatureDetailSE.CreateDetail(
                       mesh.OriginalIndexToIndex.Select(c => od1[c]).ToArray(),
                       mesh.OriginalIndexToIndex.Select(c => od2[c]).ToArray(),
                       mesh.OriginalIndexToIndex.Select(c => outValues1[c]).ToArray(),
                       mesh.OriginalIndexToIndex.Select(c => outValues2[c]).ToArray()
                       ));
        }
Ejemplo n.º 29
0
 private static Vector3[] FlatArrayToVectorArray(float[] flatArray)
 {
     Preconditions.Assert(flatArray.Length % 3 == 0, "Input array length must be divible by 3, but is " + flatArray.Length);
     return(flatArray
            .Select((c, i) => new { v = c, index = i })
            .GroupBy(c => c.index / 3)
            .Select(c => c.ToArray())
            .Select(c => new Vector3(c[0].v, c[1].v, c[2].v))
            .ToArray());
 }
        public GrassPack(Matrix4x4[] maticesArray, MyMaterialPropertyBlock propertiesBlock)
        {
            Preconditions.Assert(maticesArray.Length <= Constants.MaxInstancesPerPack,
                                 String.Format("In grass pack there can be at max {0} elements, but is {1}", Constants.MaxInstancesPerPack, maticesArray.Length));

            CastShadows    = ShadowCastingMode.Off;
            MaticesArray   = maticesArray;
            InstancesCount = maticesArray.Length;
            MyBlock        = propertiesBlock;
        }