示例#1
0
        // Init is called on startup.
        public override void Init()
        {
            // Set the clear color for the backbuffer to light green (intensities in R, G, B, A).
            RC.ClearColor = new float4(3f, 2f, 1f, 1.0f);

            // for(int i = 0; i <= a.Length; i++){

            _cubeTransform = new TransformComponent {
                Scale = new float3(2, 2, 2), Translation = new float3(0, 0, 0)
            };



            var cubeMaterial = new MaterialComponent
            {
                Diffuse = new MatChannelContainer {
                    Color = new float3(3, 0, 1)
                },
                Specular = new SpecularChannelContainer {
                    Color = float3.One, Shininess = 4
                }
            };
            var cubeMesh = SimpleMeshes.CreateCuboid(new float3(1, 1, 1));

            // Assemble the cube node containing the three components
            var cubeNode = new SceneNodeContainer();

            cubeNode.Components = new List <SceneComponentContainer>();
            cubeNode.Components.Add(_cubeTransform);
            cubeNode.Components.Add(cubeMaterial);
            cubeNode.Components.Add(cubeMesh);



            // Create a scene with a cube
            // The three components: one XForm, one Material and the Mesh3
            _cubeTransform1 = new TransformComponent {
                Scale = new float3(3, 6, 7), Translation = new float3(0, 3, 2)
            };
            var cubeMaterial1 = new MaterialComponent
            {
                Diffuse = new MatChannelContainer {
                    Color = new float3(0.5f, .8f, .5f)
                },
                Specular = new SpecularChannelContainer {
                    Color = float3.One, Shininess = 4
                }
            };
            var cubeMesh1 = SimpleMeshes.CreateCuboid(new float3(2, 3, 3));

            // Assemble the cube node containing the three components
            var cubeNode1 = new SceneNodeContainer();

            cubeNode1.Components = new List <SceneComponentContainer>();
            cubeNode1.Components.Add(_cubeTransform1);
            cubeNode1.Components.Add(cubeMaterial1);
            cubeNode1.Components.Add(cubeMesh1);



            // Create a scene with a cube
            // The three components: one XForm, one Material and the Mesh
            _cubeTransform2 = new TransformComponent {
                Scale = new float3(4, 4, 4), Translation = new float3(5, 4, 7)
            };
            cubeMaterial2 = new MaterialComponent
            {
                Diffuse = new MatChannelContainer {
                    Color = new float3(0, 1, 0)
                },
                Specular = new SpecularChannelContainer {
                    Color = float3.One, Shininess = 4
                }
            };
            var cubeMesh2 = SimpleMeshes.CreateCuboid(new float3(1, 1, 1));

            // Assemble the cube node containing the three components
            var cubeNode2 = new SceneNodeContainer();

            cubeNode2.Components = new List <SceneComponentContainer>();
            cubeNode2.Components.Add(_cubeTransform2);
            cubeNode2.Components.Add(cubeMaterial2);
            cubeNode2.Components.Add(cubeMesh2);


            // Create a scene with a cube
            // The three components: one XForm, one Material and the Mesh3
            _cubeTransform3 = new TransformComponent {
                Scale = new float3(3, 3, 1), Translation = new float3(3, 0, -5)
            };
            var cubeMaterial3 = new MaterialComponent
            {
                Diffuse = new MatChannelContainer {
                    Color = new float3(0.5f, .8f, .5f)
                },
                Specular = new SpecularChannelContainer {
                    Color = float3.One, Shininess = 4
                }
            };
            var cubeMesh3 = SimpleMeshes.CreateCuboid(new float3(1, 1, 1));

            // Assemble the cube node containing the three components
            var cubeNode3 = new SceneNodeContainer();

            cubeNode1.Components = new List <SceneComponentContainer>();
            cubeNode1.Components.Add(_cubeTransform3);
            cubeNode1.Components.Add(cubeMaterial3);
            cubeNode1.Components.Add(cubeMesh3);



            // Create the scene containing the cube as the only object
            _scene          = new SceneContainer();
            _scene.Children = new List <SceneNodeContainer>();
            _scene.Children.Add(cubeNode);
            _scene.Children.Add(cubeNode1);
            _scene.Children.Add(cubeNode2);
            _scene.Children.Add(cubeNode3);


            // Create a scene renderer holding the scene above
            _sceneRenderer = new SceneRenderer(_scene);



            // }
        }
示例#2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="AABBCalculator"/> class.
 /// </summary>
 /// <param name="snc">A single scene node to calculate an axis-aligned bounding box for.</param>
 public AABBCalculator(SceneNodeContainer snc)
 {
     _sncList = SceneVisitorHelpers.SingleRootEnumerable(snc);
 }
示例#3
0
        public override void Init()
        {
            // Set the clear color for the backbuffer to white (100% intentsity in all color channels R, G, B, A).
            RC.ClearColor = new float4(2f, 2f, 2.7f, 5);

            // Create scene with cubes
            // The three components: one XForm, one Shader and the Mesh
            _cubeTransform = new TransformComponent {
                Scale = new float3(1, 0.1f, 1), Translation = new float3(2, 0.7f, 0)
            };
            var cubeShader = new ShaderEffectComponent
            {
                Effect = SimpleMeshes.MakeShaderEffect(new float3(1, 4, 2), new float3(6, 4, 2), 3)
            };
            var cubeMesh  = SimpleMeshes.CreateCuboid(new float3(4, 5, 7));
            var cubeMesh1 = SimpleMeshes.CreateCuboid(new float3(3, 1, 15));
            var cubeMesh2 = SimpleMeshes.CreateCuboid(new float3(5, 7, 9));

            _cubeTransform1 = new TransformComponent {
                Scale = new float3(1.2f, 2.7f, 0.1f), Translation = new float3(10, 5, 5)
            };
            var cubeShader1 = new ShaderEffectComponent
            {
                Effect = SimpleMeshes.MakeShaderEffect(new float3(0.2f, 0.4f, 0.6f), new float3(1, 1, 1), 4)
            };

            _cubeTransform2 = new TransformComponent {
                Scale = new float3(0.5f, 0.5f, 0.5f), Translation = new float3(30, 14, 19)
            };
            var cubeShader2 = new ShaderEffectComponent
            {
                Effect = SimpleMeshes.MakeShaderEffect(new float3(2, 1, 20), new float3(1, 1, 1), 5)
            };

            // Assemble the cubes
            var cubeNode = new SceneNodeContainer();

            cubeNode.Components = new List <SceneComponentContainer>();
            cubeNode.Components.Add(_cubeTransform);
            cubeNode.Components.Add(cubeShader);
            cubeNode.Components.Add(cubeMesh);

            var cubeNode1 = new SceneNodeContainer();

            cubeNode1.Components = new List <SceneComponentContainer>();
            cubeNode1.Components.Add(_cubeTransform1);
            cubeNode1.Components.Add(cubeShader1);
            cubeNode1.Components.Add(cubeMesh1);

            var cubeNode2 = new SceneNodeContainer();

            cubeNode2.Components = new List <SceneComponentContainer>();
            cubeNode2.Components.Add(_cubeTransform2);
            cubeNode2.Components.Add(cubeShader2);
            cubeNode2.Components.Add(cubeMesh2);


            _scene          = new SceneContainer();
            _scene.Children = new List <SceneNodeContainer>();
            _scene.Children.Add(cubeNode);
            _scene.Children.Add(cubeNode1);
            _scene.Children.Add(cubeNode2);


            _sceneRenderer = new SceneRenderer(_scene);
        }
示例#4
0
        /// <summary>

        /// This method tries to make the best out of C4Ds seldom relationship between objects with
        /// multiple materials which can or can not be restricted to polygon selections and one or more UV sets.
        /// But there are unhandled cases:
        /// Multple UV tags are not supported. Overlapping polygon selections are probably handled differently.
        /// The awkward side effects when changing the tags' order in C4D are not reproduced.
        /// </summary>
        /// <param name="ob"></param>
        /// <param name="snc"></param>


        private void VisitObject(BaseObject ob, SceneNodeContainer snc)
        {
            Collection <TextureTag>           textureTags   = new Collection <TextureTag>();
            Dictionary <string, SelectionTag> selectionTags = new Dictionary <string, SelectionTag>();
            UVWTag      uvwTag    = null;
            CAWeightTag weightTag = null;

            // SCRATCH
            // var targetComponent = new TargetComponent {ExtraInfo = aStr, Radius = anInt};
            // snc.AddComponent(targetComponent);

            // Iterate over the object's tags
            for (BaseTag tag = ob.GetFirstTag(); tag != null; tag = tag.GetNext())
            {
                // GeneralTag
                if (1036156 == tag.GetTypeC4D())
                {
                    var    di    = tag.GetDataInstance();
                    int    anInt = di.GetInt32(10000);
                    string aStr  = di.GetString(10001);
                    Logger.Debug("Found a GeneralTag with TheInt=" + anInt + " and TheString = \"" + aStr + "\"");
                    // var targetComponent = new TargetComponent {ExtraInfo = aStr, Radius = anInt};
                    // snc.AddComponent(targetComponent);
                }

                // CAWeightTag - Save data to create the weight list later
                CAWeightTag wTag = tag as CAWeightTag;
                if (wTag != null)
                {
                    weightTag = wTag;
                    continue;
                }

                // TextureTag (Material - there might be more than one)
                TextureTag tex = tag as TextureTag;
                if (tex != null)
                {
                    textureTags.Add(tex);
                    continue;
                }
                // UVWTag - the texutre coordinates. We handle only one
                UVWTag uvw = tag as UVWTag;
                if (uvw != null)
                {
                    if (uvwTag == null)
                    {
                        uvwTag = uvw;
                    }
                    else
                    {
                        Logger.Error("Object " + ob.GetName() + " contains more than one uv-coordinates-tag. Cannot handle this. Only the first texture tag will be recognized.");
                    }
                    continue;
                }
                // Selection tag. Only recognize the polygon selections as they might be referenced in a TextureTag
                SelectionTag selection  = tag as SelectionTag;
                string       selTagName = tag.GetName();
                if (selection != null && selection.GetTypeC4D() == C4dApi.Tpolygonselection && !string.IsNullOrEmpty(selTagName))    // One Type and three TypeIDs - You C4D programmer guys really suck
                {
                    selectionTags[selTagName] = selection;
                }
                // XPresso Tags - TBD
                XPressoTag xPresso = tag as XPressoTag;
                if (xPresso != null)
                {
                    // Handle XPresso tag
                    continue;
                }
            }

            TextureTag lastUnselectedTag = null;
            Collection <KeyValuePair <SelectionTag, TextureTag> > texSelList = new Collection <KeyValuePair <SelectionTag, TextureTag> >(); // Abused KeyValuePair. Should have been Pair...

            // Now iterate over the textureTags
            foreach (TextureTag texture in textureTags)
            {
                string selRef = "";
                using (BaseContainer texData = texture.GetData())
                {
                    selRef = texData.GetString(C4dApi.TEXTURETAG_RESTRICTION);
                }
                if (string.IsNullOrEmpty(selRef))
                {
                    // This material is not restricted to any polygon selection
                    lastUnselectedTag = texture;
                }
                else
                {
                    SelectionTag sel;
                    if (selectionTags.TryGetValue(selRef, out sel))
                    {
                        texSelList.Add(new KeyValuePair <SelectionTag, TextureTag>(sel, texture));
                    }
                }
            }

            // At this point we have the last texture tag not restricted to a seletion. This will become the Material of this FuseeObjectContainer
            // no matter if this object contains geometry or not
            if (lastUnselectedTag != null)
            {
                AddComponent(snc, GetMaterial(lastUnselectedTag));
            }

            // Further processing only needs to take place if the object contains any geometry at all.
            PolygonObject polyOb = ob as PolygonObject;

            // Check whether the object contains an unpolygonized mesh
            if (polyOb == null)
            {
                polyOb = ob.GetCache(null) as PolygonObject;
            }

            if (polyOb != null)
            {
                float3[] normalOb = polyOb.CreatePhongNormals();

                // Initialize the polygon index set
                int           nPolys   = polyOb.GetPolygonCount();
                HashSet <int> polyInxs = new HashSet <int>();
                for (int i = 0; i < nPolys; i++)
                {
                    polyInxs.Add(i);
                }

                foreach (KeyValuePair <SelectionTag, TextureTag> texSelItem in texSelList)
                {
                    HashSet <int> polyInxsSubset = new HashSet <int>();
                    BaseSelect    bs             = texSelItem.Key.GetBaseSelect();
                    int           nSegments      = bs.GetSegments();
                    for (int iSeg = 0; iSeg < nSegments; iSeg++)
                    {
                        int from = bs.GetRangeA(iSeg);
                        int to   = bs.GetRangeB(iSeg);
                        for (int iSel = from; iSel <= to; iSel++)
                        {
                            polyInxs.Remove(iSel);
                            polyInxsSubset.Add(iSel);
                        }
                    }

                    // Now generate Polygons for this subset
                    if (polyInxsSubset.Count > 0)
                    {
                        if (snc.Children == null)
                        {
                            snc.Children = new List <SceneNodeContainer>();
                        }

                        SceneNodeContainer subSnc = new SceneNodeContainer();

                        AddComponent(subSnc, new TransformComponent()
                        {
                            Translation = new float3(0, 0, 0),
                            Rotation    = new float3(0, 0, 0),
                            Scale       = new float3(1, 1, 1)
                        });

                        AddComponent(subSnc, GetMaterial(texSelItem.Value));
                        subSnc.Name = snc.Name + "_" + texSelItem.Key.GetName();
                        AddComponent(subSnc, GetMesh(polyOb, normalOb, uvwTag, polyInxsSubset));
                        _weightManager.AddWeightData(subSnc, polyOb, weightTag, polyInxsSubset);

                        snc.Children.Add(subSnc);
                    }
                }

                // The remaining polygons directly go into the original mesh

                AddComponent(snc, GetMesh(polyOb, normalOb, uvwTag, polyInxs));
                _weightManager.AddWeightData(snc, polyOb, weightTag, polyInxs);
            }
            else if (ob.GetTypeC4D() == C4dApi.Olight)
            {
                using (BaseContainer lightData = ob.GetData())
                    // Just for debugging purposes
                    for (int i = 0, id = 0; -1 != (id = lightData.GetIndexId(i)); i++)
                    {
                        if (lightData.GetTypeC4D(id) == C4dApi.DA_LONG)
                        {
                            int iii = lightData.GetInt32(id);
                        }
                        if (lightData.GetTypeC4D(id) == C4dApi.DA_REAL)
                        {
                            double d = lightData.GetFloat(id);
                        }
                        else if (lightData.GetTypeC4D(id) == C4dApi.DA_VECTOR)
                        {
                            double3 v = lightData.GetVector(id);
                        }
                    }
                ;
            }
        }
示例#5
0
        private bool SaveTracks(BaseObject ob, SceneNodeContainer snc, bool slerpRotation)
        {
            var builder = new TrackBuilder();

            builder.LerpType = (slerpRotation) ? LerpType.Slerp : LerpType.Lerp;
            CTrack track = ob.GetFirstCTrack();

            // First occurence of animation tracks?
            if (track == null)
            {
                return(false);
            }

            while (track != null)
            {
                DescID    testID = track.GetDescriptionID();
                DescLevel lv1    = testID.GetAt(0);
                DescLevel lv2    = testID.GetAt(1);

                CCurve curve = track.GetCurve();
                if (curve != null)
                {
                    int keyCount = curve.GetKeyCount();

                    CKey     key = null;
                    BaseTime time;
                    for (int i = 0; i < keyCount; i++)
                    {
                        key  = curve.GetKey(i);
                        time = key.GetTime();

                        switch (lv1.id)
                        {
                        case 903:     // should be replaced with "ID_BASEOBJECT_REL_POSITION"
                            switch (lv2.id)
                            {
                            case 1000: builder.AddTranslationValue("x", (float)time.Get(), key.GetValue()); break;

                            case 1001: builder.AddTranslationValue("y", (float)time.Get(), key.GetValue()); break;

                            case 1002: builder.AddTranslationValue("z", (float)time.Get(), key.GetValue()); break;
                            }
                            break;

                        case 904:     // should be replaced with "ID_BASEOBJECT_REL_ROTATION"
                            switch (lv2.id)
                            {
                            case 1000: builder.AddRotationValue("x", (float)time.Get(), key.GetValue()); break;

                            case 1001: builder.AddRotationValue("y", (float)time.Get(), key.GetValue()); break;

                            case 1002: builder.AddRotationValue("z", (float)time.Get(), key.GetValue()); break;
                            }
                            break;

                        case 905:     // should be replaced with "ID_BASEOBJECT_REL_SCALE"
                            switch (lv2.id)
                            {
                            case 1000: builder.AddScaleValue("x", (float)time.Get(), key.GetValue()); break;

                            case 1001: builder.AddScaleValue("y", (float)time.Get(), key.GetValue()); break;

                            case 1002: builder.AddScaleValue("z", (float)time.Get(), key.GetValue()); break;
                            }
                            break;
                        }
                    }
                }
                track = track.GetNext();
            }

            builder.BuildTracks(snc, _tracks);

            if (_animationsPresent)
            {
                return(false);
            }
            return(true);
        }
示例#6
0
 /// <summary>
 /// Shortcut for <code>GetComponent&lt;WeightComponent&gt;(sncThis, inx);</code>. See <see cref="GetComponent{TComp}"/>.
 /// </summary>
 /// <param name="sncThis">This scene node container.</param>
 /// <param name="inx">specifies the n'th component if more than component of the given type exists.</param>
 /// <returns>A weight component if contained within this container.</returns>
 public static WeightComponent GetWeights(this SceneNodeContainer sncThis, int inx = 0)
 {
     return(GetComponent <WeightComponent>(sncThis, inx));
 }
示例#7
0
        /// <summary>
        /// Returns the global rotation matrix as the product of all rotations along the scene graph branch this SceneNodeContainer is a part of.
        /// </summary>
        public static float4x4 GetGlobalRotation(this SceneNodeContainer snc)
        {
            var transform = GetGlobalTransformation(snc);

            return(transform.RotationComponent());
        }
示例#8
0
        // Init is called on startup.
        public override void Init()
        {
            // Set the clear color for the backbuffer to white (100% intentsity in all color channels R, G, B, A).
            RC.ClearColor = new float4(1, 1, 0.5f, 0.3f);

            // Create a scene with a cube
            // The three components: one XForm, one Material and the Mesh

            //Würfel 1
            _cubeTransform1 = new TransformComponent {
                Scale = new float3(1, 1, 1), Translation = new float3(0, 0, 0), Rotation = new float3(0.3f, 1, 0)
            };
            // var cubeTransform = new TransformComponent { Scale = new float3(1, 1, 1), Translation = new float3(0, 0, 0), Rotation = new float3(0.3f,1,0) };
            var cubeMaterial1 = new MaterialComponent
            {
                Diffuse = new MatChannelContainer {
                    Color = new float3(1, 0.32f, 0.04f)
                },
                Specular = new SpecularChannelContainer {
                    Color = float3.One, Shininess = 4
                }
            };
            var cubeMesh1 = SimpleMeshes.CreateCuboid(new float3(30, 20, 20));


            //Würfel 2
            _cubeTransform2 = new TransformComponent {
                Scale = new float3(2, 2, 2), Rotation = new float3(0, 1, 0), Translation = new float3(0, 40, 40)
            };
            var cubeMaterial2 = new MaterialComponent
            {
                Diffuse = new MatChannelContainer {
                    Color = new float3(1, 0.1f, 0.04f)
                },
                Specular = new SpecularChannelContainer {
                    Color = float3.One, Shininess = 4
                }
            };
            var cubeMesh2 = SimpleMeshes.CreateCuboid(new float3(30, 20, 20));



            //Würfel 3
            _cubeTransform3 = new TransformComponent {
                Scale = new float3(0.5f, 0.5f, 0.5f), Translation = new float3(-80, 0, 0), Rotation = new float3(0, 0, 0)
            };
            var cubeMaterial3 = new MaterialComponent
            {
                Diffuse = new MatChannelContainer {
                    Color = new float3(1, 0.72f, 0.04f)
                },
                Specular = new SpecularChannelContainer {
                    Color = float3.One, Shininess = 4
                }
            };
            var cubeMesh3 = SimpleMeshes.CreateCuboid(new float3(30, 20, 20));



            // Assemble the cube node containing the three components Würfel 1
            var cubeNode1 = new SceneNodeContainer();

            cubeNode1.Components = new List <SceneComponentContainer>();
            cubeNode1.Components.Add(_cubeTransform1);
            cubeNode1.Components.Add(cubeMaterial1);
            cubeNode1.Components.Add(cubeMesh1);

            // Assemble the cube node containing the three components Würfel 2
            var cubeNode2 = new SceneNodeContainer();

            cubeNode2.Components = new List <SceneComponentContainer>();
            cubeNode2.Components.Add(_cubeTransform2);
            cubeNode2.Components.Add(cubeMaterial2);
            cubeNode2.Components.Add(cubeMesh2);

            // Assemble the cube node containing the three components Würfel 2
            var cubeNode3 = new SceneNodeContainer();

            cubeNode3.Components = new List <SceneComponentContainer>();
            cubeNode3.Components.Add(_cubeTransform3);
            cubeNode3.Components.Add(cubeMaterial3);
            cubeNode3.Components.Add(cubeMesh3);

            // Create the scene containing the cube as the only object
            _scene          = new SceneContainer();
            _scene.Children = new List <SceneNodeContainer>();
            _scene.Children.Add(cubeNode1);
            _scene.Children.Add(cubeNode2);
            _scene.Children.Add(cubeNode3);

            // Create a scene renderer holding the scene above
            _sceneRenderer = new SceneRenderer(_scene);
        }
示例#9
0
        // Init is called on startup.
        public override void Init()
        {
            // Set the clear color for the backbuffer to custom color (100% intentsity in all color channels R, G, B, A).
            RC.ClearColor = new float4(0.58f, 0, 0.7f, 1);

            // Create a scene with 3 cubes
            // The three components: one XForm, one Shader and the Mesh

            //Würfel Nr.1
            _cube1Transform = new TransformComponent {
                Scale = new float3(1, 1, 1), Translation = new float3(0, 0, 0)
            };                                                                                                         //Translation = Position im Raum
            var cube1Shader = new ShaderEffectComponent
            {
                Effect = SimpleMeshes.MakeShaderEffect(new float3(0.3f, 0.88f, 1), new float3(1, 1, 1), 4)
            };
            var cube1Mesh = SimpleMeshes.CreateCuboid(new float3(10, 10, 10));

            //Würfel Nr.2
            _cube2Transform = new TransformComponent {
                Scale = new float3(1, 1, 1), Translation = new float3(20, 0, 0)
            };
            var cube2Shader = new ShaderEffectComponent
            {
                Effect = SimpleMeshes.MakeShaderEffect(new float3(1, 0, 0.67f), new float3(1, 1, 1), 4)
            };
            var cube2Mesh = SimpleMeshes.CreateCuboid(new float3(12, 12, 12));

            //Würfel Nr.3
            _cube3Transform = new TransformComponent {
                Scale = new float3(1, 1, 1), Translation = new float3(-20, 5, 0)
            };
            cube3Shader = new ShaderEffectComponent
            {
                Effect = SimpleMeshes.MakeShaderEffect(new float3(0.8f, 0, 0.13f), new float3(1, 1, 1), 4)
            };
            var cube3Mesh = SimpleMeshes.CreateCuboid(new float3(10, 10, 10));

            // Assemble the cube node containing the three components
            var cube1Node = new SceneNodeContainer();

            cube1Node.Components = new List <SceneComponentContainer>();
            cube1Node.Components.Add(_cube1Transform);
            cube1Node.Components.Add(cube1Shader);
            cube1Node.Components.Add(cube1Mesh);

            var cube2Node = new SceneNodeContainer();

            cube2Node.Components = new List <SceneComponentContainer>();
            cube2Node.Components.Add(_cube2Transform);
            cube2Node.Components.Add(cube2Shader);
            cube2Node.Components.Add(cube2Mesh);

            var cube3Node = new SceneNodeContainer();

            cube3Node.Components = new List <SceneComponentContainer>();
            cube3Node.Components.Add(_cube3Transform);
            cube3Node.Components.Add(cube3Shader);
            cube3Node.Components.Add(cube3Mesh);

            // Create the scene containing the cube as the only object
            _scene          = new SceneContainer();
            _scene.Children = new List <SceneNodeContainer>();
            _scene.Children.Add(cube1Node);
            _scene.Children.Add(cube2Node);
            _scene.Children.Add(cube3Node);

            // Create a scene renderer holding the scene above
            _sceneRenderer = new SceneRenderer(_scene);
        }
示例#10
0
        // Init is called on startup.
        public override void Init()
        {
            // Set the clear color for the backbuffer to light green (intensities in R, G, B, A).
            RC.ClearColor = new float4(0.5f, 0.5f, 0.8f, 1.0f);

            //Creat a Scene with a Cube
            //The three components: one XForm, one Shader and the Mesh
            _cubeTransform = new TransformComponent {
                Scale = new float3(1, 1, 1), Translation = new float3(0, 0, 0)
            };
            var cubeShader = new ShaderEffectComponent
            {
                Effect = SimpleMeshes.MakeShaderEffect(new float3(1, 1, 0), new float3(1, 1, 1), 4)
            };
            var cubeMesh = SimpleMeshes.CreateCuboid(new float3(10, 10, 10));

            //___________
            _cubeTransform1 = new TransformComponent {
                Scale = new float3(1, 1, 1), Translation = new float3(-30, 0, 50)
            };
            var cubeShader1 = new ShaderEffectComponent
            {
                Effect = SimpleMeshes.MakeShaderEffect(new float3(0, 1, 0), new float3(1, 1, 1), 4)
            };
            var cubeMesh1 = SimpleMeshes.CreateCuboid(new float3(10, 10, 10));

            //___________
            _cubeTransform2 = new TransformComponent {
                Scale = new float3(1, 1, 1), Translation = new float3(30, 0, 50)
            };
            var cubeShader2 = new ShaderEffectComponent
            {
                Effect = SimpleMeshes.MakeShaderEffect(new float3(0, 0, 1), new float3(1, 1, 1), 4)
            };
            var cubeMesh2 = SimpleMeshes.CreateCuboid(new float3(10, 10, 10));



            //Assemble the cube node containing in the three components
            var cubeNode = new SceneNodeContainer();

            cubeNode.Components = new List <SceneComponentContainer>();
            cubeNode.Components.Add(_cubeTransform);
            cubeNode.Components.Add(cubeShader);
            cubeNode.Components.Add(cubeMesh);

            var cubeNode1 = new SceneNodeContainer();

            cubeNode1.Components = new List <SceneComponentContainer>();
            cubeNode1.Components.Add(_cubeTransform1);
            cubeNode1.Components.Add(cubeShader1);
            cubeNode1.Components.Add(cubeMesh1);

            var cubeNode2 = new SceneNodeContainer();

            cubeNode2.Components = new List <SceneComponentContainer>();
            cubeNode2.Components.Add(_cubeTransform2);
            cubeNode2.Components.Add(cubeShader2);
            cubeNode2.Components.Add(cubeMesh2);

            //Create the Scene containing the cube als the only object
            _scene          = new SceneContainer();
            _scene.Children = new List <SceneNodeContainer>();
            _scene.Children.Add(cubeNode);
            _scene.Children.Add(cubeNode1);
            _scene.Children.Add(cubeNode2);

            //Create a scene renderer holding the scene above
            _scenerenderer = new SceneRenderer(_scene);
        }
示例#11
0
        private SceneContainer CreateGui()
        {
            var   canvasScaleFactor = _initWidth / _canvasWidth;
            float textSize          = 2;
            float borderScaleFactor = 1;

            if (_canvasRenderMode == CanvasRenderMode.SCREEN)
            {
                textSize         *= canvasScaleFactor;
                borderScaleFactor = canvasScaleFactor;
            }

            var btnFuseeLogo = new GUIButton
            {
                Name = "Canvas_Button"
            };

            btnFuseeLogo.OnMouseEnter += BtnLogoEnter;
            btnFuseeLogo.OnMouseExit  += BtnLogoExit;
            btnFuseeLogo.OnMouseDown  += BtnLogoDown;

            var guiFuseeLogo = new Texture(AssetStorage.Get <ImageData>("FuseeText.png"));
            var fuseeLogo    = new TextureNodeContainer(
                "fuseeLogo",
                UIHelper.VsTex,
                UIHelper.PsTex,
                guiFuseeLogo,
                UIElementPosition.GetAnchors(AnchorPos.TOP_TOP_LEFT),
                UIElementPosition.CalcOffsets(AnchorPos.TOP_TOP_LEFT, new float2(0, _canvasHeight - 0.5f), _canvasHeight, _canvasWidth, new float2(1.75f, 0.5f)));

            fuseeLogo.AddComponent(btnFuseeLogo);

            var markModelContainer = new SceneNodeContainer
            {
                Name = "MarkModelContainer",
            };

            var canvas = new CanvasNodeContainer(
                "Canvas",
                _canvasRenderMode,
                new MinMaxRect
            {
                Min = new float2(-_canvasWidth / 2f, -_canvasHeight / 2f),
                Max = new float2(_canvasWidth / 2f, _canvasHeight / 2f)
            }
                )
            {
                Children = new ChildList()
                {
                    fuseeLogo, markModelContainer
                }
            };

            for (var i = 0; i < _uiInput.Count; i++)
            {
                var item = _uiInput[i];
                if (item.AnnotationKind != UIHelper.AnnotationKind.CONFIRMED)
                {
                    UIHelper.CreateAndAddCircleAnnotationAndLine(markModelContainer, item.AnnotationKind, item.Size, _uiInput[i].AnnotationCanvasPos, textSize, borderScaleFactor,
                                                                 "#" + i + " " + item.SegmentationClass + ", " + item.Probability.ToString(CultureInfo.GetCultureInfo("en-gb")));
                }
                else
                {
                    UIHelper.CreateAndAddCircleAnnotationAndLine(markModelContainer, item.AnnotationKind, item.Size, _uiInput[i].AnnotationCanvasPos, textSize, borderScaleFactor,
                                                                 "#" + i + " " + item.SegmentationClass);
                }
            }

            var canvasProjComp = new ProjectionComponent(_canvasRenderMode == CanvasRenderMode.SCREEN ? ProjectionMethod.ORTHOGRAPHIC : ProjectionMethod.PERSPECTIVE, ZNear, ZFar, _fovy);

            canvas.Components.Insert(0, canvasProjComp);
            AddResizeDelegate(delegate { canvasProjComp.Resize(Width, Height); });

            return(new SceneContainer
            {
                Children = new List <SceneNodeContainer>
                {
                    //Add canvas.
                    canvas
                }
            });
        }
示例#12
0
        // Init is called on startup.
        public override void Init()
        {
            var outlineOne = new PolyBoundary //CCW!!
            {
                Points = new List <float3>
                {
                    new float3(1, 0, 0),
                    new float3(1.25f, 0.5f, 0.5f),
                    new float3(1, 1, 1),
                    new float3(0, 1, 1),
                    new float3(-0.25f, 0.5f, 0.5f),
                    new float3(0, 0, 0)
                },
                IsOuter = true
            };

            var outlineOneHole = new PolyBoundary //CW!!
            {
                Points = new List <float3>
                {
                    new float3(0.75f, 0.25f, 0.25f),
                    new float3(0.25f, 0.25f, 0.25f),
                    new float3(0.25f, 0.75f, 0.75f),
                    new float3(0.75f, 0.75f, 0.75f)
                },
                IsOuter = false
            };

            var outlineTwo = new PolyBoundary //CCW!!
            {
                Points = new List <float3>
                {
                    new float3(1, 0, 0),
                    new float3(1, 0.707f, 0.707f),
                    new float3(0, 0.707f, 0.707f),
                    new float3(0, 0, 0)
                },
                IsOuter = true
            };

            var outlineThree = new PolyBoundary //CCW!!
            {
                Points = new List <float3>
                {
                    new float3(0, 0, 0),
                    new float3(1, 0, 1),
                    new float3(0, 0.5f, 0.5f)
                },
                IsOuter = true
            };

            var geomOutlinesOne = new List <PolyBoundary> {
                outlineOne, outlineOneHole
            };
            var geomOne = new Geometry(geomOutlinesOne);

            geomOne.Extrude2DPolygon(0.5f, true);
            geomOne.Triangulate();
            var meshOne = new JometriMesh(geomOne);

            var geomCubeOutlines = new List <PolyBoundary> {
                outlineTwo
            };
            var geomCube = new Geometry(geomCubeOutlines);

            geomCube.Extrude2DPolygon(1, false);
            //geomCube.Extrude2DPolygon(1, true);
            geomCube.Triangulate();
            var cube = new JometriMesh(geomCube);

            var geomTriangleOutlines = new List <PolyBoundary> {
                outlineThree
            };
            var geomTri = new Geometry(geomTriangleOutlines);

            geomTri.Triangulate();
            var triangle = new JometriMesh(geomTri);

            ////////////////// Fill SceneNodeContainer ////////////////////////////////
            var parentNode = new SceneNodeContainer
            {
                Components = new List <SceneComponentContainer>(),
                Children   = new ChildList()
            };

            var parentTrans = new TransformComponent
            {
                Rotation    = float3.Zero,
                Scale       = float3.One,
                Translation = new float3(0, 0, 0)
            };

            parentNode.Components.Add(parentTrans);

            var sceneNodeCOne = new SceneNodeContainer {
                Components = new List <SceneComponentContainer>()
            };


            var meshCOne = new Mesh
            {
                Vertices  = meshOne.Vertices,
                Triangles = meshOne.Triangles,
                Normals   = meshOne.Normals,
            };

            var tranC = new TransformComponent
            {
                Rotation    = float3.Zero,
                Scale       = float3.One,
                Translation = new float3(0, 0, 0)
            };

            sceneNodeCOne.Components.Add(tranC);
            sceneNodeCOne.Components.Add(meshCOne);
            ///////////////////////////////////////////////////////////
            var sceneNodeCCube = new SceneNodeContainer {
                Components = new List <SceneComponentContainer>()
            };

            var meshCCube = new Mesh
            {
                Vertices  = cube.Vertices,
                Triangles = cube.Triangles,
                Normals   = cube.Normals,
            };
            var tranCube = new TransformComponent
            {
                Rotation    = float3.Zero,
                Scale       = float3.One,
                Translation = new float3(-2, -1, 0)
            };

            sceneNodeCCube.Components.Add(tranCube);
            sceneNodeCCube.Components.Add(meshCCube);
            //////////////////////////////////////////////////////////////////
            var sceneNodeCTri = new SceneNodeContainer {
                Components = new List <SceneComponentContainer>()
            };

            var meshCTri = new Mesh
            {
                Vertices  = triangle.Vertices,
                Triangles = triangle.Triangles,
                Normals   = triangle.Normals,
            };
            var tranTri = new TransformComponent
            {
                Rotation    = float3.Zero,
                Scale       = float3.One,
                Translation = new float3(1.5f, -1, 0)
            };

            sceneNodeCTri.Components.Add(tranTri);
            sceneNodeCTri.Components.Add(meshCTri);
            //////////////////////////////////////////////////////////////////

            parentNode.Children.Add(sceneNodeCTri);
            parentNode.Children.Add(sceneNodeCOne);
            parentNode.Children.Add(sceneNodeCCube);
            var sc = new SceneContainer {
                Children = new List <SceneNodeContainer> {
                    parentNode
                }
            };

            var projComp = new ProjectionComponent(ProjectionMethod.PERSPECTIVE, 1, 5000, M.PiOver4);

            AddResizeDelegate(delegate { projComp.Resize(Width, Height); });
            sc.Children[0].Components.Insert(0, projComp);

            _renderer = new SceneRenderer(sc);

            // Set the clear color for the back buffer to white (100% intensity in all color channels R, G, B, A).
            RC.ClearColor = new float4(0, 1, 1, 1);
        }
示例#13
0
 public static LightComponent GetLight(this SceneNodeContainer sncThis, int inx = 0)
 {
     return((LightComponent)GetComponent <LightComponent>(sncThis, inx));
 }
示例#14
0
 public static int GetIndexOf <TComp>(this SceneNodeContainer sncThis, int inx = 0)
     where TComp : SceneComponentContainer
 {
     return(GetIndexOf(sncThis, typeof(TComp), inx));
 }
示例#15
0
 /// <summary>
 /// Shortcut for <code>GetComponent&lt;Mesh&gt;(sncThis, inx);</code>. See <see cref="GetComponent{TComp}"/>.
 /// </summary>
 /// <param name="sncThis">This scene node container.</param>
 /// <param name="inx">specifies the n'th component if more than component of the given type exists.</param>
 /// <returns>A mesh if contained within this container.</returns>
 public static Mesh GetMesh(this SceneNodeContainer sncThis, int inx = 0)
 {
     return(GetComponent <Mesh>(sncThis, inx));
 }
示例#16
0
 private TransformComponent tc(SceneNodeContainer snc)
 {
     return(snc.GetComponent <TransformComponent>());
 }
示例#17
0
 /// <summary>
 /// Shortcut for <code>GetComponent&lt;MaterialComponent&gt;(sncThis, inx);</code>. See <see cref="GetComponent{TComp}"/>.
 /// </summary>
 /// <param name="sncThis">This scene node container.</param>
 /// <param name="inx">specifies the n'th component if more than component of the given type exists.</param>
 /// <returns>A material if contained within this container.</returns>
 public static MaterialComponent GetMaterial(this SceneNodeContainer sncThis, int inx = 0)
 {
     return(GetComponent <MaterialComponent>(sncThis, inx));
 }
        // Init is called on startup.
        public override void Init()
        {
            // Set the clear color for the backbuffer  (intensities in R, G, B, A).
            RC.ClearColor = new float4(0.5f, 0.2f, 1.0f, 1.0f);

            // Create a scene with a cube
            // The three components: one XForm, one Material and the Mesh
            _cubeTransform = new TransformComponent {
                Scale       = new float3(1, 1, 1),
                Translation = new float3(-20, 0, 0),
                Rotation    = new float3(0, 0, 0)
            };

            _cubeTransform2 = new TransformComponent {
                Scale       = new float3(1, 1, 1),
                Translation = new float3(20, 0, 0),
                Rotation    = new float3(0, 0, 0)
            };

            _cubeTransform3 = new TransformComponent {
                Scale       = new float3(0.4f, 0.4f, 0.4f),
                Translation = new float3(0, 0, 0),
                Rotation    = new float3(0, 0, 0)
            };


            _cubeShader = new ShaderEffectComponent
            {
                Effect = SimpleMeshes.MakeShaderEffect(new float3(0, 0, 1), new float3(1, 1, 1), 4)
            };
            var cubeMesh = SimpleMeshes.CreateCuboid(new float3(10, 10, 10));

            // Assemble the cube node containing the three components
            var cubeNode = new SceneNodeContainer();

            cubeNode.Components = new List <SceneComponentContainer>();
            cubeNode.Components.Add(_cubeTransform);
            cubeNode.Components.Add(_cubeShader);
            cubeNode.Components.Add(cubeMesh);

            var cubeNode2 = new SceneNodeContainer();

            cubeNode2.Components = new List <SceneComponentContainer>();
            cubeNode2.Components.Add(_cubeTransform2);
            cubeNode2.Components.Add(_cubeShader);
            cubeNode2.Components.Add(cubeMesh);


            var cubeNode3 = new SceneNodeContainer();

            cubeNode3.Components = new List <SceneComponentContainer>();
            cubeNode3.Components.Add(_cubeTransform3);
            cubeNode3.Components.Add(_cubeShader);
            cubeNode3.Components.Add(cubeMesh);


            // Create the scene containing the cube as the only object
            _scene          = new SceneContainer();
            _scene.Children = new List <SceneNodeContainer>();
            _scene.Children.Add(cubeNode);
            _scene.Children.Add(cubeNode2);
            _scene.Children.Add(cubeNode3);

            // Create a scene renderer holding the scene above
            _sceneRenderer = new SceneRenderer(_scene);
        }
示例#19
0
 /// <summary>
 /// Shortcut for <code>GetComponent&lt;TransformComponent&gt;(sncThis, inx);</code>. See <see cref="GetComponent{TComp}"/>.
 /// </summary>
 /// <param name="sncThis">This scene node container.</param>
 /// <param name="inx">specifies the n'th component if more than component of the given type exists.</param>
 /// <returns>A transform if contained within this container.</returns>
 public static TransformComponent GetTransform(this SceneNodeContainer sncThis, int inx = 0)
 {
     return(GetComponent <TransformComponent>(sncThis, inx));
 }
示例#20
0
 /// <summary>
 /// Finds all nodes containing one or more components matching a given search predicate within a tree of nodes.
 /// </summary>
 /// <param name="root">The root node where to start the search.</param>
 /// <param name="match">The search predicate. Typically specified as a Lambda expression.</param>
 /// <returns>All nodes containing matching components.</returns>
 public static IEnumerable <SceneNodeContainer> FindNodesWhereComponent(this SceneNodeContainer root, Predicate <SceneComponentContainer> match)
 {
     return(new SceneNodeWhereComponentEnumerable <SceneNodeContainer, SceneComponentContainer> {
         _match = match, _rootList = SceneVisitorHelpers.SingleRootEnumerator(root)
     });
 }
示例#21
0
        /// <summary>
        /// Returns the global scale as the product of all scaling along the scene graph branch this SceneNodeContainer is a part of.
        /// </summary>
        public static float3 GetGlobalScale(this SceneNodeContainer snc)
        {
            var transform = GetGlobalTransformation(snc);

            return(transform.Scale());
        }
示例#22
0
 /// <summary>
 /// Finds all nodes of a certain type containing one or more components matching the specified type and a given search predicate within a tree of nodes.
 /// </summary>
 /// <typeparam name="TNode">The type of the nodes to search in.</typeparam>
 /// <typeparam name="TComponent">The type of the components to look for.</typeparam>
 /// <param name="root">The root node where to start the search.</param>
 /// <param name="match">The search predicate. Typically specified as a Lambda expression.</param>
 /// <returns>
 /// All nodes of the specified type containing components matching both, type and predicate.
 /// </returns>
 public static IEnumerable <TNode> FindNodesWhereComponent <TNode, TComponent>(this SceneNodeContainer root, Predicate <TComponent> match)
     where TNode : SceneNodeContainer
     where TComponent : SceneComponentContainer
 {
     return(new SceneNodeWhereComponentEnumerable <TNode, TComponent> {
         _match = match, _rootList = SceneVisitorHelpers.SingleRootEnumerator(root)
     });
 }
示例#23
0
        private List <SceneNodeContainer> FuseefyOb(BaseObject ob)
        {
            bool isAnimRoot = false;

            if (ob == null)
            {
                return(null);
            }

            List <SceneNodeContainer> ret = new List <SceneNodeContainer>();

            do
            {
                SceneNodeContainer snc = new SceneNodeContainer();


                snc.Name = ob.GetName();
                float3 rotC4d = (float3)ob.GetRelRot();
                AddComponent(snc, new TransformComponent
                {
                    Translation = (float3)ob.GetRelPos(),
                    Rotation    = new float3(-rotC4d.y, -rotC4d.x, -rotC4d.z),
                    Scale       = (float3)ob.GetRelScale()
                });

                // See if this is a joint - if so, store it for later reference and also pass the information on
                // to SaveTracks to make it Slerp the rotations (instead of lerp)
                bool isJoint          = _weightManager.CheckOnJoint(ob, snc);
                bool hasQuaternionTag = CheckOnQuaternionTag(ob);


                // Search for unpolygonized objects holding the animationtracks
                if (SaveTracks(ob, snc, isJoint || hasQuaternionTag))
                {
                    _animationsPresent = true;
                    isAnimRoot         = true;
                }


                VisitObject(ob, snc);


                // Hope the hierarchy of polygonized objects is the same as the normal one
                var childList = FuseefyOb(ob.GetDown());
                if (childList != null)
                {
                    if (snc.Children == null)
                    {
                        snc.Children = childList;
                    }
                    else
                    {
                        snc.Children.AddRange(childList);
                    }
                }

                if (isAnimRoot)
                {
                    AnimationComponent ac = new AnimationComponent();
                    ac.AnimationTracks = new List <AnimationTrackContainer>(_tracks);
                    snc.AddComponent(ac);
                    _animationsPresent = false;
                    _tracks.Clear();
                }
                ret.Add(snc);
                ob = ob.GetNext();
            } while (ob != null);
            return(ret);
        }
示例#24
0
 /// <summary>
 /// Finds nodes of a certain type and matching the given search predicate within a tree of nodes.
 /// </summary>
 /// <typeparam name="TNode">The type of nodes to find.</typeparam>
 /// <param name="root">The root node where to start the search.</param>
 /// <param name="match">The search predicate. Typically specified as a Lambda expression.</param>
 /// <returns>All nodes of the specified type matching the predicate.</returns>
 public static IEnumerable <TNode> FindNodes <TNode>(this SceneNodeContainer root, Predicate <TNode> match) where TNode : SceneNodeContainer
 {
     return(new SceneNodeEnumerable <TNode> {
         _match = match, _rootList = SceneVisitorHelpers.SingleRootEnumerator(root)
     });
 }
示例#25
0
 /// <summary>
 /// Performs a <see cref="Viserator{TItem,TState}"/> action on the specified tree.
 /// </summary>
 /// <typeparam name="TViserator">The type of the viserator.</typeparam>
 /// <typeparam name="TResult">The type of the elements resulting from the Viserate traversal.</typeparam>
 /// <param name="root">The root where to start the traversal.</param>
 /// <returns>All items yielded from within the traversal (see <see cref="ViseratorBase{TItem}.YieldItem"/>).</returns>
 public static IEnumerable <TResult> Viserate <TViserator, TResult>(this SceneNodeContainer root) where TViserator : ViseratorBase <TResult>, new()
 {
     return(new ViseratorEnumerable <TViserator, TResult> {
         _rootList = SceneVisitorHelpers.SingleRootEnumerator(root)
     });
 }
示例#26
0
 /// <summary>
 /// Finds the components with the specified type in the children of this scene node container.
 /// </summary>
 /// <typeparam name="TComp">The type of the components to look for.</typeparam>
 /// <param name="sncThis">This scene node container.</param>
 /// <returns>A List of compontetns of the specified type, if contained within the given container.</returns>
 public static IEnumerable <TComp> GetComponentsInChildren <TComp>(this SceneNodeContainer sncThis)
     where TComp : SceneComponentContainer
 {
     return(GetComponentsInChildren(sncThis, typeof(TComp)).Cast <TComp>());
 }
示例#27
0
        private void InteractionHandler()
        {
            //Add new Geometry
            if (Keyboard.GetKey(KeyCodes.D1) && _keyTimeout < 0)
            {
                _keyTimeout = 1;
                var geometry = CreatePrimitiveGeometry.CreateCuboidGeometry(1, 1, 1);
                AddGeometryToSceneNode(geometry, new float3(0, 0, 0));
            }
            if (Keyboard.GetKey(KeyCodes.D2) && _keyTimeout < 0)
            {
                _keyTimeout = 1;
                var geometry = CreatePrimitiveGeometry.CreatePyramidGeometry(1, 1, 1);
                AddGeometryToSceneNode(geometry, new float3(0, 0, 0));
            }
            if (Keyboard.GetKey(KeyCodes.D3) && _keyTimeout < 0)
            {
                _keyTimeout = 1;
                var geometry = CreatePrimitiveGeometry.CreateConeGeometry(1, 1, 15);
                AddGeometryToSceneNode(geometry, new float3(0, 0, 0));
            }
            if (Keyboard.GetKey(KeyCodes.D4) && _keyTimeout < 0)
            {
                _keyTimeout = 1;
                var geometry = CreatePrimitiveGeometry.CreateSpehreGeometry(1, 30, 15);
                AddGeometryToSceneNode(geometry, new float3(0, 0, 0));
            }
            _keyTimeout -= DeltaTime;

            //following actions are only allowed if something is selected
            if (_selectedNode == null)
            {
                return;
            }

            //Translate Geometry
            if (Keyboard.GetKey(KeyCodes.G))
            {
                _isTranslating = true;
            }
            if (_isTranslating)
            {
                var worldPos = new float3(Mouse.Velocity.x * .0001f, Mouse.Velocity.y * -.0001f, Mouse.WheelVel * .001f);
                _selectedNode.GetTransform().Translation += worldPos.xyz;

                if (Mouse.LeftButton)
                {
                    _isTranslating = false;
                }
            }

            //Scaling Geometry
            if (Keyboard.GetKey(KeyCodes.S))
            {
                _isScaling = true;
            }
            if (_isScaling)
            {
                _selectedNode.GetTransform().Scale += new float3(Mouse.Velocity.y, Mouse.Velocity.y, Mouse.Velocity.y) * .0001f;
                if (Mouse.LeftButton)
                {
                    _isScaling = false;
                }
            }

            //DeleteGeom
            if (Keyboard.GetKey(KeyCodes.Delete) && _keyTimeout < 0)
            {
                _keyTimeout = 1;
                int currentGeometryIndex = _parentNode.Children.IndexOf(_selectedNode);
                _activeGeometrys.Remove(currentGeometryIndex);

                var zwerg = new Dictionary <int, Geometry>();
                foreach (var key in _activeGeometrys.Keys)
                {
                    if (key > currentGeometryIndex)
                    {
                        var test = _activeGeometrys[key];
                        zwerg.Add(key - 1, test);
                    }
                    else
                    {
                        zwerg.Add(key, _activeGeometrys[key]);
                    }
                }

                _activeGeometrys.Clear();
                foreach (var item in zwerg)
                {
                    _activeGeometrys.Add(item.Key, item.Value);
                }

                _parentNode.Children.RemoveAt(currentGeometryIndex);
                _selectedNode = null;
                _currentPick  = null;
            }

            //Insert
            if (Keyboard.GetKey(KeyCodes.I) && _keyTimeout < 0)
            {
                _keyTimeout = .25f;
                var currentGeometryIndex    = _parentNode.Children.IndexOf(_selectedNode);
                var currentSelection        = _parentNode.Children[currentGeometryIndex];
                var currentSelectedGeometry = _activeGeometrys[currentGeometryIndex];

                currentSelectedGeometry.InsetFace(rng.Next(4, currentSelectedGeometry.GetAllFaces().Count()), .5f);
                var copy = currentSelectedGeometry.CloneGeometry();
                _activeGeometrys[currentGeometryIndex] = copy;
                currentSelectedGeometry.Triangulate();

                var geometryMesh  = new JometriMesh(currentSelectedGeometry);
                var meshComponent = new Mesh
                {
                    Vertices  = geometryMesh.Vertices,
                    Triangles = geometryMesh.Triangles,
                    Normals   = geometryMesh.Normals,
                };
                currentSelection.Components[2] = meshComponent;
            }

            //Extrude
            if (Keyboard.GetKey(KeyCodes.E) && _keyTimeout < 0)
            {
                _keyTimeout = .25f;
                var currentGeometryIndex    = _parentNode.Children.IndexOf(_selectedNode);
                var currentSelection        = _parentNode.Children[currentGeometryIndex];
                var currentSelectedGeometry = _activeGeometrys[currentGeometryIndex];

                currentSelectedGeometry.ExtrudeFace(rng.Next(4, currentSelectedGeometry.GetAllFaces().Count()), 1);
                var copy = currentSelectedGeometry.CloneGeometry();
                _activeGeometrys[currentGeometryIndex] = copy;
                currentSelectedGeometry.Triangulate();

                var geometryMesh  = new JometriMesh(currentSelectedGeometry);
                var meshComponent = new Mesh
                {
                    Vertices  = geometryMesh.Vertices,
                    Triangles = geometryMesh.Triangles,
                    Normals   = geometryMesh.Normals,
                };
                currentSelection.Components[2] = meshComponent;
            }

            //Add Catmull-Clark
            if (Keyboard.GetKey(KeyCodes.C) && _keyTimeout < 0)
            {
                _keyTimeout = .25f;
                var currentGeometryIndex    = _parentNode.Children.IndexOf(_selectedNode);
                var currentSelection        = _parentNode.Children[currentGeometryIndex];
                var currentSelectedGeometry = _activeGeometrys[currentGeometryIndex];

                currentSelectedGeometry = SubdivisionSurface.CatmullClarkSubdivision(currentSelectedGeometry);
                var copy = currentSelectedGeometry.CloneGeometry();
                _activeGeometrys[currentGeometryIndex] = copy;
                currentSelectedGeometry.Triangulate();

                var geometryMesh  = new JometriMesh(currentSelectedGeometry);
                var meshComponent = new Mesh
                {
                    Vertices  = geometryMesh.Vertices,
                    Triangles = geometryMesh.Triangles,
                    Normals   = geometryMesh.Normals,
                };
                currentSelection.Components[2] = meshComponent;
            }
        }
示例#28
0
 /// <summary>
 /// Finds the component with the specified type in this scene node container.
 /// </summary>
 /// <typeparam name="TComp">The type of the component to look for.</typeparam>
 /// <param name="sncThis">This scene node container.</param>
 /// <param name="inx">specifies the n'th component if more than component of the given type exists.</param>
 /// <returns>A component of the specified type, if contained within this container, null otherwise.</returns>
 public static TComp GetComponent <TComp>(this SceneNodeContainer sncThis, int inx = 0)
     where TComp : SceneComponentContainer
 {
     return((TComp)GetComponent(sncThis, typeof(TComp), inx));
 }
示例#29
0
        // RenderAFrame is called once a frame
        public override void RenderAFrame()
        {
            // Clear the backbuffer
            RC.Clear(ClearFlags.Color | ClearFlags.Depth);

            // Mouse and keyboard movement
            if (Keyboard.LeftRightAxis != 0 || Keyboard.UpDownAxis != 0)
            {
                _keys = true;
            }

            var curDamp = (float)System.Math.Exp(-Damping * DeltaTime);

            // Zoom & Roll
            if (Touch.TwoPoint)
            {
                if (!_twoTouchRepeated)
                {
                    _twoTouchRepeated = true;
                    _angleRollInit    = Touch.TwoPointAngle - _angleRoll;
                    _offsetInit       = Touch.TwoPointMidPoint - _offset;
                }
                _zoomVel   = Touch.TwoPointDistanceVel * -0.01f;
                _angleRoll = Touch.TwoPointAngle - _angleRollInit;
                _offset    = Touch.TwoPointMidPoint - _offsetInit;
            }
            else
            {
                _twoTouchRepeated = false;
                _zoomVel          = Mouse.WheelVel * -0.5f;
                _angleRoll       *= curDamp * 0.8f;
                _offset          *= curDamp * 0.8f;
            }

            // UpDown / LeftRight rotation
            if (Mouse.LeftButton)
            {
                _keys         = false;
                _angleVelHorz = -RotationSpeed * Mouse.XVel * 0.000002f;
                _angleVelVert = -RotationSpeed * Mouse.YVel * 0.000002f;
            }
            else if (Touch.GetTouchActive(TouchPoints.Touchpoint_0) && !Touch.TwoPoint)
            {
                _keys = false;
                float2 touchVel;
                touchVel      = Touch.GetVelocity(TouchPoints.Touchpoint_0);
                _angleVelHorz = -RotationSpeed * touchVel.x * 0.000002f;
                _angleVelVert = -RotationSpeed * touchVel.y * 0.000002f;
            }
            else
            {
                if (_keys)
                {
                    _angleVelHorz = -RotationSpeed * Keyboard.LeftRightAxis * 0.002f;
                    _angleVelVert = -RotationSpeed * Keyboard.UpDownAxis * 0.002f;
                }
                else
                {
                    _angleVelHorz *= curDamp;
                    _angleVelVert *= curDamp;
                }
            }

            float wuggyYawSpeed = Keyboard.WSAxis * Keyboard.ADAxis * 0.03f;
            float wuggySpeed    = Keyboard.WSAxis * -10;

            // Wuggy XForm
            float wuggyYaw = _wuggyTransform.Rotation.y;

            wuggyYaw += wuggyYawSpeed;
            wuggyYaw  = NormRot(wuggyYaw);
            float3 wuggyPos = _wuggyTransform.Translation;

            wuggyPos += new float3((float)Sin(wuggyYaw), 0, (float)Cos(wuggyYaw)) * wuggySpeed;
            _wuggyTransform.Rotation    = new float3(0, wuggyYaw, 0);
            _wuggyTransform.Translation = wuggyPos;

            // Wuggy Wheels
            _wgyWheelBigR.Rotation  += new float3(wuggySpeed * 0.008f, 0, 0);
            _wgyWheelBigL.Rotation  += new float3(wuggySpeed * 0.008f, 0, 0);
            _wgyWheelSmallR.Rotation = new float3(_wgyWheelSmallR.Rotation.x + wuggySpeed * 0.016f, -Keyboard.ADAxis * 0.3f, 0);
            _wgyWheelSmallL.Rotation = new float3(_wgyWheelSmallR.Rotation.x + wuggySpeed * 0.016f, -Keyboard.ADAxis * 0.3f, 0);

            // SCRATCH:
            // _guiSubText.Text = target.Name + " " + target.GetComponent<TargetComponent>().ExtraInfo;
            SceneNodeContainer target = GetClosest();
            float camYaw = 0;

            if (target != null)
            {
                float3 delta = target.GetTransform().Translation - _wuggyTransform.Translation;
                camYaw = (float)Atan2(-delta.x, -delta.z) - _wuggyTransform.Rotation.y;
            }

            camYaw = NormRot(camYaw);
            float deltaAngle = camYaw - _wgyNeckHi.Rotation.y;

            if (deltaAngle > M.Pi)
            {
                deltaAngle = deltaAngle - M.TwoPi;
            }
            if (deltaAngle < -M.Pi)
            {
                deltaAngle = deltaAngle + M.TwoPi;
            }
            ;
            var newYaw = _wgyNeckHi.Rotation.y + (float)M.Clamp(deltaAngle, -0.06, 0.06);

            newYaw = NormRot(newYaw);
            _wgyNeckHi.Rotation = new float3(0, newYaw, 0);


            _zoom += _zoomVel;
            // Limit zoom
            if (_zoom < 80)
            {
                _zoom = 80;
            }
            if (_zoom > 2000)
            {
                _zoom = 2000;
            }

            _angleHorz += _angleVelHorz;
            // Wrap-around to keep _angleHorz between -PI and + PI
            _angleHorz = M.MinAngle(_angleHorz);

            _angleVert += _angleVelVert;
            // Limit pitch to the range between [-PI/2, + PI/2]
            _angleVert = M.Clamp(_angleVert, -M.PiOver2, M.PiOver2);

            // Wrap-around to keep _angleRoll between -PI and + PI
            _angleRoll = M.MinAngle(_angleRoll);


            // Create the camera matrix and set it as the current ModelView transformation
            var mtxRot = float4x4.CreateRotationZ(_angleRoll) * float4x4.CreateRotationX(_angleVert) * float4x4.CreateRotationY(_angleHorz);
            var mtxCam = float4x4.LookAt(0, 20, -_zoom, 0, 0, 0, 0, 1, 0);

            _renderer.View = mtxCam * mtxRot * _sceneScale;
            var mtxOffset = float4x4.CreateTranslation(2 * _offset.x / Width, -2 * _offset.y / Height, 0);

            RC.Projection = mtxOffset * _projection;


            _renderer.Traverse(_scene.Children);

            // Swap buffers: Show the contents of the backbuffer (containing the currently rerndered farame) on the front buffer.
            Present();
        }
示例#30
0
        public override void Init()
        {
            // Set the clear color for the backbuffer to light green (intensities in R, G, B, A).
            RC.ClearColor  = new float4(0f, 1f, 2f, 1f);
            _cubeTransform = new TransformComponent {
                Scale = new float3(1, 1, 1), Translation = new float3(0, 0, 0)
            };

            var cubeShader = new ShaderEffectComponent
            {
                Effect = SimpleMeshes.MakeShaderEffect(ColorUint.Tofloat3(ColorUint.Beige), new float3(1, 1, 1), 4)
            };
            var cubeMesh = SimpleMeshes.CreateCuboid(new float3(10, 10, 10));


            // Assemble the cube node containing the three components
            var cubeNode = new SceneNodeContainer();

            cubeNode.Components = new List <SceneComponentContainer>();
            cubeNode.Components.Add(_cubeTransform);
            cubeNode.Components.Add(cubeShader);
            cubeNode.Components.Add(cubeMesh);

//CUBE2_________________________________________________________________________

            _cube2Transform = new TransformComponent {
                Scale = new float3(3, 3, 1), Translation = new float3(30, 0, 30), Rotation = new float3(0.1f, 0.5f, 0)
            };
            _cube2Shader = new ShaderEffectComponent
            {
                Effect = SimpleMeshes.MakeShaderEffect(ColorUint.Tofloat3(ColorUint.DarkRed), new float3(1, 1, 1), 4)
            };
            var cubeMesh2 = SimpleMeshes.CreateCuboid(new float3(5, 5, 5));

            // Assemble the cube node containing the three components
            var cubeNode2 = new SceneNodeContainer();

            cubeNode2.Components = new List <SceneComponentContainer>();
            cubeNode2.Components.Add(_cube2Transform);
            cubeNode2.Components.Add(_cube2Shader);
            cubeNode2.Components.Add(cubeMesh2);



//CUBE3_______________________________________________________________________________
            _cube3Transform = new TransformComponent {
                Scale = new float3(1, 1, 1), Translation = new float3(15, 0, -10), Rotation = new float3(-0.1f, -0.5f, 0)
            };
            _cube3Shader = new ShaderEffectComponent
            {
                Effect = SimpleMeshes.MakeShaderEffect(ColorUint.Tofloat3(ColorUint.MediumSeaGreen), new float3(1, 2, 1), 4)
            };
            var cubeMesh3 = SimpleMeshes.CreateCuboid(new float3(2, 3, 1));

            // Assemble the cube node containing the three components
            var cubeNode3 = new SceneNodeContainer();

            cubeNode3.Components = new List <SceneComponentContainer>();
            cubeNode3.Components.Add(_cube3Transform);
            cubeNode3.Components.Add(_cube3Shader);
            cubeNode3.Components.Add(cubeMesh3);

            // Create the scene containing the cube as the only object
            _scene          = new SceneContainer();
            _scene.Children = new List <SceneNodeContainer>();
            _scene.Children.Add(cubeNode);
            _scene.Children.Add(cubeNode2);
            _scene.Children.Add(cubeNode3);



            // Create a scene renderer holding the scene above
            _sceneRenderer = new SceneRenderer(_scene);
        }