public static PackedGeometry Pack(LineSet lineSet)
        {
            PackedGeometry packed;
            Coordinate     coordinate;

            packed = new PackedGeometry();

            coordinate = (Coordinate)lineSet.ChildrenWithAppliedReferences.FirstOrDefault(n => n.GetType() == typeof(Coordinate));

            packed.RGBA             = false;
            packed.RGB              = false;
            packed.Coloring         = false;
            packed.generateColorMap = false;

            if (coordinate != null)
            {
                packed._coords = X3DTypeConverters.MFVec3f(coordinate.point);

                packed.restartIndex = null;
                packed.vertexStride = 2;
                packed.vertexCount  = lineSet.vertexCount;

                packed.Interleave();
            }

            return(packed);
        }
        public static PackedGeometry Pack(IndexedLineSet ils)
        {
            PackedGeometry packed;
            Coordinate     coordinate;

            packed = new PackedGeometry();
            //packed.Texturing = ifs.texCoordinate != null;// || parentShape.texturingEnabled;

            coordinate = (Coordinate)ils.ChildrenWithAppliedReferences.FirstOrDefault(n => n.GetType() == typeof(Coordinate));

            packed.RGBA             = false;
            packed.RGB              = false;
            packed.Coloring         = false;
            packed.generateColorMap = false;

            if (coordinate != null && !string.IsNullOrEmpty(ils.coordIndex))
            {
                packed._indices = X3DTypeConverters.ParseIndicies(ils.coordIndex);
                packed._coords  = X3DTypeConverters.MFVec3f(coordinate.point);

                if (ils.coordIndex.Contains(RESTART_INDEX.ToString()))
                {
                    packed.restartIndex = RESTART_INDEX;
                }

                packed.vertexStride = 2;

                packed.Interleave();
            }

            return(packed);
        }
        public override void Load()
        {
            base.Load();

            int i;

            // The keyValue field and value_changed events are defined in RGB colour space.
            KeyValues = X3DTypeConverters.MFVec3f(this.keyValue);

            if (KeyValues.Length > Keys.Length)
            {
                Console.WriteLine("[Warning] ColorInterpolator : The number of colours in the keyValue field should be equal to the number of key frames in the key field");
            }

            // OPTIMISE
            for (i = 0; i < Keys.Length; i++)
            {
                if (i >= KeyValues.Length)
                {
                    map[Keys[i]] = Vector3.Zero;
                }
                else
                {
                    map[Keys[i]] = KeyValues[i];
                }
            }
        }
        public static PackedGeometry Pack(IndexedFaceSet ifs)
        {
            PackedGeometry    packed;
            TextureCoordinate texCoordinate;
            Coordinate        coordinate;
            Color             colorNode;
            ColorRGBA         colorRGBANode;

            packed = new PackedGeometry();
            //packed.Texturing = ifs.texCoordinate != null;// || parentShape.texturingEnabled;

            texCoordinate = (TextureCoordinate)ifs.ChildrenWithAppliedReferences.FirstOrDefault(n => n.GetType() == typeof(TextureCoordinate));
            coordinate    = (Coordinate)ifs.ChildrenWithAppliedReferences.FirstOrDefault(n => n.GetType() == typeof(Coordinate));
            colorNode     = (Color)ifs.ChildrenWithAppliedReferences.FirstOrDefault(n => n.GetType() == typeof(Color));
            colorRGBANode = (ColorRGBA)ifs.ChildrenWithAppliedReferences.FirstOrDefault(n => n.GetType() == typeof(ColorRGBA));

            packed.RGBA             = colorRGBANode != null;
            packed.RGB              = colorNode != null;
            packed.Coloring         = packed.RGBA || packed.RGB;
            packed.generateColorMap = packed.Coloring;

            if (packed.RGB && !packed.RGBA)
            {
                packed.color = X3DTypeConverters.Floats(colorNode.color);
            }
            else if (packed.RGBA && !packed.RGB)
            {
                packed.color = X3DTypeConverters.Floats(colorRGBANode.color);
            }

            if (texCoordinate != null && !string.IsNullOrEmpty(ifs.texCoordIndex))
            {
                packed._texIndices = X3DTypeConverters.ParseIndicies(ifs.texCoordIndex);
                packed._texCoords  = X3DTypeConverters.MFVec2f(texCoordinate.point);
                packed.Texturing   = true;
            }

            if (coordinate != null && !string.IsNullOrEmpty(ifs.coordIndex))
            {
                packed._indices = X3DTypeConverters.ParseIndicies(ifs.coordIndex);
                packed._coords  = X3DTypeConverters.MFVec3f(coordinate.point);

                if (!string.IsNullOrEmpty(ifs.colorIndex))
                {
                    packed._colorIndicies = X3DTypeConverters.ParseIndicies(ifs.colorIndex);
                }

                if (ifs.coordIndex.Contains(RESTART_INDEX.ToString()))
                {
                    packed.restartIndex = RESTART_INDEX;
                }

                packed.Interleave();
            }

            return(packed);
        }
        public static PackedGeometry Pack(PointSet pointSet)
        {
            PackedGeometry packed;
            Coordinate     coordinate;
            Color          colorNode;
            ColorRGBA      colorRGBANode;

            packed = new PackedGeometry();

            coordinate    = (Coordinate)pointSet.ChildrenWithAppliedReferences.FirstOrDefault(n => n.GetType() == typeof(Coordinate));
            colorNode     = (Color)pointSet.ChildrenWithAppliedReferences.FirstOrDefault(n => n.GetType() == typeof(Color));
            colorRGBANode = (ColorRGBA)pointSet.ChildrenWithAppliedReferences.FirstOrDefault(n => n.GetType() == typeof(ColorRGBA));

            packed.RGBA             = colorRGBANode != null;
            packed.RGB              = colorNode != null;
            packed.Coloring         = packed.RGBA || packed.RGB;
            packed.generateColorMap = packed.Coloring;

            if (packed.RGB && !packed.RGBA)
            {
                packed.color = X3DTypeConverters.Floats(colorNode.color);
            }
            else if (packed.RGBA && !packed.RGB)
            {
                packed.color = X3DTypeConverters.Floats(colorRGBANode.color);
            }

            if (coordinate != null)
            {
                packed._coords = X3DTypeConverters.MFVec3f(coordinate.point);

                packed.restartIndex = null;
                packed.vertexStride = 1;

                packed.Interleave();
            }

            return(packed);
        }
Пример #6
0
        public override void Load()
        {
            base.Load();

            int            i;
            int            a, b;
            PackedGeometry _pack;

            cubeHandle  = GeometryHandle.Zero;
            innerHandle = GeometryHandle.Zero;
            outerHandle = GeometryHandle.Zero;

            generateCube = !(string.IsNullOrEmpty(frontUrl) || string.IsNullOrEmpty(backUrl) ||
                             string.IsNullOrEmpty(topUrl) || string.IsNullOrEmpty(bottomUrl) ||
                             string.IsNullOrEmpty(leftUrl) || string.IsNullOrEmpty(rightUrl));

            //TODO: replace cube sides that arent available with transparent sides

            generateSkyAndGround = !(string.IsNullOrEmpty(groundColor) || string.IsNullOrEmpty(skyColor) ||
                                     string.IsNullOrEmpty(groundAngle) || string.IsNullOrEmpty(skyAngle));


            // TODO: later render both skydome and skybox together
            // Alpha values in skybox should provide a way to see through to skydome.
            // Skycolor sphere should be slightly larger than groundcolor hemisphere
            // and finally skybox should fit and be smaller than groundcolor hemisphere.

            if (generateSkyAndGround)
            {
                // Sphere
                // interpolate colors from groundColor and skyColor over hemispheres using specified sky and ground angles
                this.groundColors = X3DTypeConverters.MFVec3f(groundColor);
                this.groundAngles = X3DTypeConverters.Floats(groundAngle);
                this.skyColors    = X3DTypeConverters.MFVec3f(skyColor);
                this.skyAngles    = X3DTypeConverters.Floats(skyAngle);

                // Assign colors with matching angles
                colors = new Vector3[groundColors.Length + skyColors.Length];
                for (i = 0; i < skyColors.Length; i++)
                {
                    colors[i] = skyColors[i];
                }
                for (i = skyColors.Length; i < skyColors.Length + groundColors.Length; i++)
                {
                    colors[i] = groundColors[i - skyColors.Length];
                }
                angles    = new float[groundAngles.Length + skyAngles.Length + 2];
                angles[0] = 0;
                for (i = 0; i < skyAngles.Length; i++)
                {
                    angles[i + 1] = skyAngles[i];
                }
                angles[skyAngles.Length + 1] = 0;
                for (i = 0; i < groundAngles.Length; i++)
                {
                    angles[i + skyAngles.Length + 2] = 1.5f + groundAngles[i];
                }



                groundDivisor = (1.0f / groundColors.Length) * (float)Math.PI; // how many colors divided over 90 degrees (lower hemisphere)
                skyDivisor    = (1.0f / groundColors.Length) * (float)Math.PI; // how many colors divided over 90 degrees (upper hemisphere)

                // SKYDOME
                // outer sphere (sky)

                scaleSky     = Vector3.One * 6.0f;                                             // slightly bigger than ground hemisphere
                _shaderOuter = ShaderCompiler.ApplyShader(BackgroundShader.vertexShaderSource, // Make use of the BackgroundShader for Skydome Linear Interpolation
                                                          BackgroundShader.fragmentShaderSource);
                _shaderOuter.Link();

                List <Vertex> geometryOuterSphere = BuildSphereGeometryQuads(60, Vector3.Zero, 1.0f);
                Buffering.BufferShaderGeometry(geometryOuterSphere, out outerHandle.vbo4, out outerHandle.NumVerticies4);

                min = Vector3.Zero;
                max = Vector3.Zero;
                BoundingBox.CalculateBoundingBox(geometryOuterSphere, out max, out min);
                bboxOuter = max - min;

                // inner hemisphere (ground)

                //scaleGround = Vector3.One * 5.6f;
                //_shaderInner = ShaderCompiler.ApplyShader(BackgroundShader.vertexShaderSource,
                //                                 BackgroundShader.fragmentShaderSource);
                //_shaderInner.Link();

                //List<Vertex> geometryInnerHemisphere = BuildHemisphereGeometryQuads(60, new Vector3(0, 0.0f,0), 1.0f, false);
                //Buffering.BufferShaderGeometry(geometryInnerHemisphere, out innerHandle.vbo4, out innerHandle.NumVerticies4);

                //min = Vector3.Zero;
                //max = Vector3.Zero;
                //BoundingBox.CalculateBoundingBox(geometryInnerHemisphere, out max, out min);
                //bboxInner = max - min;


                skydomeTexture = MakeSkydomeTexture();
            }

            if (generateCube)
            {
                tex_cube = createCubeMapFromURIs();

                // SKYBOX
                // innermost skybox

                scaleCube = Vector3.One * 3.1f;

                _shaderInnerCube = ShaderCompiler.ApplyShader(CubeMapBackgroundShader.vertexShaderSource,
                                                              CubeMapBackgroundShader.fragmentShaderSource);
                _shaderInnerCube.Link();

                _pack           = new PackedGeometry();
                _pack._indices  = _cube.Indices;
                _pack._coords   = _cube.Vertices;
                _pack.Texturing = true;
                //_pack._colorIndicies = _boxGeometry.Colors;
                _pack._texCoords   = _cube.Texcoords;
                _pack.restartIndex = -1;

                _pack.Interleave();

                // BUFFER GEOMETRY
                cubeHandle = _pack.CreateHandle();
            }
        }