Manipulating IMML using Plugins

Added by Joshua Nair over 1 year ago

What's the best method to use to manipulate IMML using plug-ins

For example, if i want to create a light as well as a primitive?

It seems that not all methods work, this is what we've found to work.

Our current Method:

//Create a primitive
VastPark.Imml.Scene.Controls.Primitive p = VastPark.Imml.ImmlElementFactory.CreatePrimitive();
p.Type = PrimitiveType.Box;
p.Name = "testprim"+primCount.ToString();
// what is p.Position?
p.WorldPosition = new SlimDX.Vector3(primCount, 1, 1);
p.Size = new SlimDX.Vector3(1, 1, 1);
p.Complexity = PrimitiveComplexity.Medium;
//light: create a light element
Light l = new Light();
l.Name = "Light" + primCount.ToString();
l.InnerCone = 0.1745329f;
l.OuterCone = 1.745329f;
l.Range = 20;
l.Type = LightType.Point;
l.CastShadows = true;
l.Enabled = true;
l.Diffuse = new RGB(0, 0, 255);
l.Specular = new RGB(0, 0, 255);
//l.WorldPosition = new SlimDX.Vector3(primCount, 2.5f, 1);
l.Position = new SlimDX.Vector3(0, 1.5f, 0);
// add the light element into the Primitive element
p.Elements.Add(l); //light
//load the primitive into the park. 
p.SetParkEngine(_ParkEngine);
_ParkEngine.RenderEngine.Load(p); // <--- this works

Are there other alternatives?

- Josh and Subeesh from Singapore


Replies (1)

RE: Manipulating IMML using Plugins - Added by Craig Presti over 1 year ago

While you can manually load the elements into the engines as you've shown, its simpler and more efficient to load them into the context:

var p = ImmlElementFactory.CreatePrimitive();
p.Position = new Vector3(1,1,1)
//etc

_ParkEngine.Context.Add(p)

The benefit of this is that the system will pick up on the change to the context (the IMML document) and automatically watch that element for state changes (network, transform, triggers, etc).

In your approach, there aren't any listeners setup automatically internally in the renderengine, so if you were later to do something like:

p.Position = new Vector3(1,2,3)

The primitive would still remain at position 1,1,1

(1-1/1)