Programmatically Adding Primitives

Feb 11, 2010 at 5:56 PM
Edited Feb 11, 2010 at 6:01 PM

I am having trouble with adding primitives to my scene programmatically. That is, the code seems to work, but I never see any primitive.

I am using the following setup:

 

   public override void OnInitialize()
        {
            _light = new OmniLight();
            _light.Position.X = 100;
            _light.Position.Y = 50;
            _light.Position.Z = -100;
            _light.Ambient = Colors.Red;
            _light.Diffuse = Colors.Purple;
            _light.Specular = Colors.Magenta;
            Scene.AddNode(_light);

            Camera.Target.X = 0;
            Camera.Target.Y = 0;
            Camera.Target.Z = 0;

            Camera.Position = new Coordinate(100, 50, -100);
            base.OnInitialize();
        }

        public override void OnLoadContent()
        {
            ContentManager.AssetsRoot = "3dVisualizer/Models";
            _ship = ContentManager.Load<Mesh>("teapot.ASE"); //<-- I can see the teapot just fine
            Scene.AddNode(_ship);

            Geometry g = new Geometry();
            Cylinder c = new Cylinder();
            c.Color = Colors.Red;
            c.TopRadius = 20;
            c.BottomRadius = 20;
            c.Size = 15;
            c.Segments = 16;
            Scene.AddNode(c);
            Cylinder = c;
            g.Children.Add(c);
            Scene.AddNode(g); //<-- I cannot see the cylinder

            base.OnLoadContent();
        }

 

I would be grateful for any help.

 

Coordinator
Feb 11, 2010 at 6:52 PM

Hi,

I've been getting reports about this from several, there seem to be a bug around this. The primitives was added last minute and wasn't tested properly other than in Xaml. I'll be putting it up as a bug and I'll see how fast I can get it fixed. I'm gone for a week now, and won't have time for any Balder work till I'm back. But then I have 2 full days of Balder work, and should be focusing in on bugs like this that has been reported.

Thanks for pointing it out, though!

 

Feb 11, 2010 at 7:15 PM

Thanks for your immediate answer. I guess I'll just model a cylinder.

Awesome work overall, by the way, congratulations!

Coordinator
Feb 11, 2010 at 7:44 PM

Thanks. 

Hope its not to inconvenient.

 

Feb 24, 2010 at 3:50 PM

I was wondering, is there is any news concerning this issue? I am asking because I can't find an entry in the issue tracking system.

Coordinator
Feb 24, 2010 at 4:20 PM

Hi,

it has in fact been resolved, sorry that I forgot about notifying this thread. But, I haven't put out a release for it. If you need it now, you could go get the Source in the Development branch over at GitHub. 

 

Coordinator
Feb 24, 2010 at 4:21 PM

Btw: We're not registering issues on Codeplex - we're registering them at GitHub. Sorry for the confusion of having 2 sites.

Feb 24, 2010 at 4:24 PM

Very nice, thanks! I'm heading over to GitHub now.

Feb 24, 2010 at 5:45 PM

The current Git code displays nothing and then throws an OutOfMemoryException when I try to run the above. I guess I'll have to wait for the next proper release.

Coordinator
Feb 24, 2010 at 6:49 PM

Sorry to hear that.

What if you open the SampleBrowser.sln and have a look the new Programatic sample for materials - it has Box, Cylinder and Ring as primitives in it. Do they generate the same exception?

Feb 24, 2010 at 7:34 PM

No, the as far as I can tell all the samples work. However, you do not create any primitives from code in any of the examples in the sample browser.

Coordinator
Feb 24, 2010 at 7:46 PM

There should be a sample under Programatic\Materials that creates them programatically through the event model - in the file Content.xaml.cs.

I'll investigate further and see if there is something I'm missing or have not tested. 

Feb 24, 2010 at 8:05 PM

I'm sorry, I must be missing something. The only sample in the materials category is called Teapot, and contains no primitives.

Feb 24, 2010 at 8:24 PM

Oops, I'm sorry. What I'm missing is actually referencing the Development tree instead of the main one.

Coordinator
Feb 24, 2010 at 8:46 PM

:)   No problem. 

 

If you go get the latest - right now - you'll get quite a performance boost, btw.. 
I'm in the middle of optimizations, and have had great progress the last couple of hours.