/// <summary>
        /// Used to control the visibility listing of nodes in the graph.
        /// </summary>
        internal void CopyToShadowDom()
        {
            //TODO: Note when XML Writer is used later we need to write from SwitchChildren instead of Children

            if (this.Children != null && this.Children.Count > 0)
            {
                SceneGraphNode[] tmp = new SceneGraphNode[this.Children.Count];

                this.Children.CopyTo(tmp);

                this.Shadow = tmp.ToList();

                this.Children.Clear();
            }
        }
Exemplo n.º 2
0
        public override void Load()
        {
            base.Load();

            BaseDefinition   = this.Parent;
            PrototypeBody    = BaseDefinition != null ? (ProtoBody)BaseDefinition.Parent : null;
            ProtoDeclaration = PrototypeBody != null ? (ProtoDeclare)PrototypeBody.Parent : null;
            ProtoInterface   = ProtoDeclaration != null?ProtoDeclaration.ItemsByType <ProtoInterface>().FirstOrDefault() : null;

            if (ProtoInterface != null)
            {
                Console.WriteLine("Initilizing prototype IS.");

                Fields = ProtoInterface.ItemsByType <field>();

                Connections = this.ItemsByType <connect>();

                ProtoDeclaration.Initilize(BaseDefinition, Fields, Connections);
            }
            else
            {
                Console.WriteLine("ProtoInterface could not be found within IS {0}", this.ErrorStringWithLineNumbers());
            }
        }
 internal void Initilize(SceneGraphNode baseDefinition, List <field> fields, List <connect> connections)
 {
     this.BaseDefinition = baseDefinition;
     this.Fields         = fields;
     this.Connections    = connections;
 }
Exemplo n.º 4
0
        public Matrix4 ApplyGeometricTransformations(RenderingContext rc, ComposedShader shader, SceneGraphNode context)
        {
            RefreshDefaultUniforms(shader);
            //RefreshMaterialUniforms();

            if (shader.IsTessellator)
            {
                RefreshTessUniforms(shader);
            }


            Matrix4 view = Matrix4.LookAt(new Vector3(4, 3, 3), // Camera is at (4,3,3), in World Space
                                          new Vector3(0, 0, 0), // and looks at the origin
                                          new Vector3(0, 1, 0)  // Head is up (set to 0,-1,0 to look upside-down)
                                          );

            Matrix4 model; // applied transformation hierarchy

            SceneGraphNode transform_context = context == null ? this : context;

            List <Transform> transformationHierarchy = transform_context
                                                       .AscendantByType <Transform>()
                                                       .Select(t => (Transform)t)
                                                       .Where(t => t.Hidden == false)
                                                       .ToList();

            Matrix4 modelview = Matrix4.Identity;// * rc.matricies.worldview;

            // using Def_Use/Figure02.1Hut.x3d Cone and Cylinder
            Vector3 x3dScale = new Vector3(0.06f, 0.06f, 0.06f); // scaling down to conform with X3D standard (note this was done manually and might need tweaking)

            //x3dScale = Vector3.One;

            Quaternion modelrotation      = Quaternion.Identity;
            Matrix4    modelLocalRotation = Matrix4.Identity;


            //if (rc.cam.OrbitLocalOrientation != Vector2.Zero)
            //{
            //    // Center of Rotation based on center of bounding box
            //    Quaternion qLocal = QuaternionExtensions.EulerToQuat(0, -rc.cam.OrbitLocalOrientation.X, -rc.cam.OrbitLocalOrientation.Y);
            //    Quaternion qAdjust = QuaternionExtensions.EulerToQuat(MathHelpers.PIOver2, 0.0f, 0.0f);

            //    Matrix4 mat4CenterOfRotation = Matrix4.CreateTranslation(centerOfRotation);
            //    Matrix4 origin = Matrix4.CreateTranslation(new Vector3(0, 0, 0));

            //    modelLocalRotation = mat4CenterOfRotation * Matrix4.CreateFromQuaternion(qLocal) * Matrix4.CreateFromQuaternion(qAdjust);
            //}

            //const float bbscale = 0.0329999961f;

            Vector3 centerOffset = Vector3.Zero;

            foreach (Transform transform in transformationHierarchy)
            {
                modelview = SceneEntity.ApplyX3DTransform(centerOffset,
                                                          Vector3.Zero,
                                                          transform.Scale,
                                                          Vector3.Zero,
                                                          transform.Translation, // * x3dScale,
                                                          modelview);

                //modelview *= Matrix4.CreateTranslation(transform.Translation * x3dScale);

                //modelrotation = new Quaternion(transform.Rotation.X, transform.Rotation.Y, transform.Rotation.Z, transform.Rotation.W);
                //modelrotations *= Matrix4.CreateFromQuaternion(modelrotation);

                //modelrotations *= MathHelpers.CreateRotation(ref modelrotation);
            }

            //Vector3 center = modelview.ExtractTranslation();
            //Vector3 centerOffsetVector = center + (bbox.Maximum - bbox.Minimum);
            //Matrix4 centerOffset = Matrix4.CreateTranslation(centerOffsetVector);



            model = modelview;

            Matrix4 cameraTransl = Matrix4.CreateTranslation(rc.cam.Position);

            Quaternion q = rc.cam.Orientation;

            Matrix4 cameraRot;

            cameraRot = Matrix4.CreateFromQuaternion(q); // cameraRot = MathHelpers.CreateRotation(ref q);


            Matrix4 MVP = ((modelLocalRotation * model) * cameraTransl) * cameraRot; // position and orient the Shape relative to the world and camera



            //shader.SetFieldValue("size", new Vector3(bbox.Width, bbox.Height, bbox.Depth) * bbscale);
            shader.SetFieldValue("modelview", ref MVP);                              //GL.UniformMatrix4(uniformModelview, false, ref rc.matricies.modelview);
            shader.SetFieldValue("projection", ref rc.matricies.projection);
            shader.SetFieldValue("camscale", rc.cam.Scale.X);                        //GL.Uniform1(uniformCameraScale, rc.cam.Scale.X);
            shader.SetFieldValue("X3DScale", rc.matricies.Scale);                    //GL.Uniform3(uniformX3DScale, rc.matricies.Scale);
            shader.SetFieldValue("coloringEnabled", this.coloring ? 1 : 0);          //GL.Uniform1(uniforms.a_coloringEnabled, 0);
            shader.SetFieldValue("texturingEnabled", this.texturingEnabled ? 1 : 0); //GL.Uniform1(uniforms.a_texturingEnabled, this.texturingEnabled ? 1 : 0);
            shader.SetFieldValue("lightingEnabled", 1);

            if (shader.IsBuiltIn == false)
            {
                shader.ApplyFieldsAsUniforms(rc);
            }

            return(MVP);
        }