Exemplo n.º 1
0
        public static MeshGpuInstancing WithInstanceCustomAccessor(this MeshGpuInstancing instancing, string attribute, IReadOnlyList <Object> values)
        {
            Guard.NotNullOrEmpty(attribute, nameof(attribute));

            attribute = attribute.ToUpperInvariant();
            var expectedType = values.Where(item => item != null).FirstOrDefault()?.GetType();

            if (expectedType == null)
            {
                return(instancing);
            }

            if (expectedType == typeof(int))
            {
                var xValues = values.Select(item => item is int val ? val : 0).ToList();
                return(instancing.WithInstanceAccessor(attribute, xValues));
            }

            if (expectedType == typeof(Single))
            {
                var xValues = values.Select(item => item is float val ? val : 0).ToList();
                return(instancing.WithInstanceAccessor(attribute, xValues));
            }

            throw new ArgumentException(expectedType.Name);
        }
Exemplo n.º 2
0
        public static MeshGpuInstancing WithInstanceAccessors(this MeshGpuInstancing instancing, IReadOnlyList <Transforms.AffineTransform> transforms)
        {
            Guard.NotNull(instancing, nameof(instancing));
            Guard.NotNull(transforms, nameof(transforms));

            var xfrms = transforms.Select(item => item.GetDecomposed());
            var hasS  = xfrms.Any(item => item.Scale != Vector3.One);
            var hasR  = xfrms.Any(item => item.Rotation != Quaternion.Identity);
            var hasT  = xfrms.Any(item => item.Translation != Vector3.Zero);

            if (hasS)
            {
                instancing.WithInstanceAccessor("SCALE", xfrms.Select(item => item.Scale).ToList());
            }
            if (hasR)
            {
                instancing.WithInstanceAccessor("ROTATION", xfrms.Select(item => item.Rotation).ToList());
            }
            if (hasT)
            {
                instancing.WithInstanceAccessor("TRANSLATION", xfrms.Select(item => item.Translation).ToList());
            }

            return(instancing);
        }