Esempio n. 1
0
        public static void CreateEditNode(string key, Vector3 position, Quaternion orientation)
        {
            WorldEntity worldEntity = Engine.World.GetWorldEntity(key);
            SceneNode   sceneNode   = worldEntity.CreateSceneNode(position, orientation);

            if (sceneNode != null)
            {
                EditNode editNode    = new EditNode(key, worldEntity, sceneNode);
                ushort   numObjects  = sceneNode.NumAttachedObjects();
                ushort   numEntities = 0;

                for (ushort i = 0; i < numObjects; i++)
                {
                    Entity entity = sceneNode.GetAttachedObject(i) as Entity;

                    // if we haven't found an entity by now we need to make one ourselves
                    if (entity == null && i == numObjects - 1 && numEntities == 0)
                    {
                        entity = Engine.Graphics.SceneManager.CreateEntity("ball.mesh");
                        sceneNode.AttachObject(entity);
                    }

                    // setup special material scheme used in the editor only
                    if (entity != null)
                    {
                        for (uint j = 0; j < entity.NumSubEntities; j++)
                        {
                            Technique technique = entity.GetSubEntity(j).GetMaterial().CreateTechnique();
                            technique.SchemeName = "WireframeScheme";
                            Pass pass = technique.CreatePass();
                            pass.LightingEnabled = false;
                            TextureUnitState textureUnit = pass.CreateTextureUnitState();
                            textureUnit.SetColourOperationEx(LayerBlendOperationEx.LBX_SOURCE1, LayerBlendSource.LBS_MANUAL, LayerBlendSource.LBS_CURRENT,
                                                             new ColourValue(
                                                                 0.5f + Mogre.Math.RangeRandom(0, 0.5f),
                                                                 0.5f + Mogre.Math.RangeRandom(0, 0.5f),
                                                                 0.5f + Mogre.Math.RangeRandom(0, 0.5f)));
                        }

                        entity.UserObject = editNode;
                        numEntities++;
                    }
                }

                Editor.editNodes.Add(editNode);
            }
        }