void Start()
    {
        obj1 = new Entity("objet #1");
        obj2 = new SubEntity("objet #2", 10, 20);

        print("objet nom: " + obj1.name);
        print("objet nom: " + obj2.name + " coord: (" + obj2.positionX + ", "+  obj2.positionY + ")");
    }
        private Dictionary<string, object> SerializeSirenSubEntity(SubEntity subEntityItem)
        {
            Dictionary<string, object> resultantSubEntity = new Dictionary<string, object>();
            Dictionary<string, object> entityProperties = new Dictionary<string, object>();

            if (subEntityItem.Class != null)
            {
                resultantSubEntity.Add("class", subEntityItem.Class);
            }

            if (subEntityItem.Title != null)
            {
                resultantSubEntity.Add("title", subEntityItem.Title);
            }

            resultantSubEntity.Add("rel", subEntityItem.Rel);

            System.Reflection.PropertyInfo[] properties = subEntityItem.GetType().GetProperties();

            // Any property that is not one of the "reserved" names
            foreach (System.Reflection.PropertyInfo prop in properties)
            {
                if (prop.GetValue(subEntityItem, null) != null)
                {
                    if (!ReservedWords.ListOfWords().Contains(prop.Name))
                    {
                        bool ignore = false;
                        foreach (var attrib in prop.CustomAttributes)
                        {
                            if (attrib.AttributeType.FullName == "WebApiContrib.Formatting.Siren.SirenIgnoreAttribute")
                            {
                                ignore = true;
                            }
                        }
                        if (!ignore)
                        {
                            entityProperties.Add(prop.Name, prop.GetValue(subEntityItem, null));
                        }
                    }
                }
            }

            if (entityProperties.Count > 0)
            {
                resultantSubEntity.Add("properties", entityProperties);
            }

            if (subEntityItem.Entities != null)
            {
                List<object> subEntities = new List<object>();
                foreach (object embeddedSirenSubEntityObject in subEntityItem.Entities)
                {
                    if (embeddedSirenSubEntityObject.GetType().IsSubclassOf(typeof(EmbeddedLink)) ||
                        embeddedSirenSubEntityObject.GetType() == typeof(EmbeddedLink))
                    {
                        subEntities.Add(this.SerializeSirenEmbeddedLink((EmbeddedLink)embeddedSirenSubEntityObject));
                    }

                    if (embeddedSirenSubEntityObject.GetType().IsSubclassOf(typeof(SubEntity)))
                    {
                        subEntities.Add(this.SerializeSirenSubEntity((SubEntity)embeddedSirenSubEntityObject));
                    }
                }

                resultantSubEntity.Add("entities", subEntities);
            }

            if (subEntityItem.Actions.Count > 0)
            {
                resultantSubEntity.Add("actions", subEntityItem.Actions);
            }

            if (subEntityItem.Links.Count > 0)
            {
                resultantSubEntity.Add("links", subEntityItem.Links);
            }

            return resultantSubEntity;
        }
            /// <summary>
            /// 
            /// </summary>
            /// <param name="ent"></param>
            /// <param name="position"></param>
            /// <param name="orientation"></param>
            /// <param name="scale"></param>
            /// <param name="color"></param>
            public void AddSubEntity(SubEntity ent, Vector3 position, Quaternion orientation, Vector3 scale, ColorEx color) {
                Debug.Assert(!mBuild);
                //Add this submesh to the queue
                QueuedMesh newMesh = new QueuedMesh();
                newMesh.Mesh = ent.SubMesh;
                newMesh.Postion = position;
                newMesh.Orientation = orientation;
                newMesh.Scale = scale;
                newMesh.Color = color;

                if (newMesh.Color != ColorEx.White) {
                    mRequireVertexColors = true;
                    //VertexElementType format = Root.Singleton.RenderSystem.Colo
                    throw new NotSupportedException("Please use ColorEx.White for now!");
                }

                mMeshQueue.Add(newMesh);
                //Increment the vertex/index count so the buffers will have room for this mesh
                vertexData.vertexCount += ent.SubMesh.vertexData.vertexCount;
                indexData.indexCount += ent.SubMesh.indexData.indexCount;
            }
 /// <summary>
 /// 
 /// </summary>
 /// <param name="ent"></param>
 /// <param name="position"></param>
 /// <param name="orientation"></param>
 /// <param name="scale"></param>
 public void AddSubEntity(SubEntity ent, Vector3 position, Quaternion orientation, Vector3 scale) {
     AddSubEntity(ent, position, orientation, scale, ColorEx.White);
 }
            /// <summary>
            /// 
            /// </summary>
            /// <param name="parent"></param>
            /// <param name="ent"></param>
            public SubBatch(BatchedGeometry parent, SubEntity ent) {
                mMeshType = ent.SubMesh;
                mParent = parent;
                mBuild = false;
                mRequireVertexColors = false;
                // Material must always exist
                Material origMat = (Material)MaterialManager.Instance.GetByName(ent.MaterialName);
                if (origMat != null) {
                    material = (Material)MaterialManager.Instance.GetByName(GetMaterialClone(origMat).Name);
                }
                else {
                    Tuple<Resource, bool> result = MaterialManager.Instance.CreateOrRetrieve("PagedGeometry_Batched_Material", "General");
                    if (result.First == null)
                        throw new Exception("BatchedGeometry failed to create a material for entity with invalid material.");

                    material = (Material)result.First;
                }

                //Setup vertex/index data structure
                vertexData = mMeshType.vertexData.Clone(false);
                indexData = mMeshType.indexData.Clone(false);

                //Remove blend weights from vertex format
                VertexElement blendIndices = vertexData.vertexDeclaration.FindElementBySemantic(VertexElementSemantic.BlendIndices);
                VertexElement blendWeights = vertexData.vertexDeclaration.FindElementBySemantic(VertexElementSemantic.BlendWeights);

                if (blendIndices != null && blendWeights != null) {
                    Debug.Assert(blendIndices.Source == blendWeights.Source, "Blend indices and weights should be in the same buffer");
                    Debug.Assert(blendIndices.Size + blendWeights.Size == vertexData.vertexBufferBinding.GetBuffer(blendIndices.Source).VertexSize,
                        "Blend indices and blend buffers should have buffer to themselves!");

                    //Remove the blend weights
                    vertexData.vertexBufferBinding.UnsetBinding(blendIndices.Source);
                    vertexData.vertexDeclaration.RemoveElement(VertexElementSemantic.BlendIndices);
                    vertexData.vertexDeclaration.RemoveElement(VertexElementSemantic.BlendWeights);
                }

                //Reset vertex/index count
                vertexData.vertexStart = 0;
                vertexData.vertexCount = 0;
                indexData.indexStart = 0;
                indexData.indexCount = 0;
            }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="ent"></param>
        /// <returns></returns>
        private string GetFormatString(SubEntity ent) {
            string str = string.Empty;

            str += ent.MaterialName + "|";
            str += ent.SubMesh.indexData.indexBuffer.Type + "|";

            List<VertexElement> elemList = ent.SubMesh.vertexData.vertexDeclaration.Elements;
            foreach (VertexElement element in elemList) {
                str += element.Source + "|";
                str += element.Semantic + "|";
                str += element.Type + "|";
            }

            return str;
        }
 public SubEntity CloneSubEntity(SubEntity subentity)
 {
     return(new SubEntity(subentity.bindingPointCategory, subentity.bindingPointIndex, new EntityLook(subentity.subEntityLook.bonesId, new List <ushort>(subentity.subEntityLook.skins),
                                                                                                      new List <int>(subentity.subEntityLook.indexedColors), new List <short>(subentity.subEntityLook.scales), subentity.subEntityLook.subentities))); // subentity.sublook.subentites not cloned
 }
Esempio n. 8
0
        protected void EnsureObjectsCreated()
        {
            ClearCreatedObjects();
            Texture prototypeTexture = null;

            if (useTextures)
            {
                prototypeMaterial = MaterialManager.Instance.Load("barrel.barrel");
                if (uniqueTextures)
                {
                    prototypeTexture = TextureManager.Instance.Load("blank.dds");
                }
            }
            else
            {
                prototypeMaterial = MaterialManager.Instance.Load("unit_box.unit_box");
            }
            prototypeMaterial.Compile();
            if (objectCount == 0)
            {
                return;
            }
            int materialCount = (animatedObjects ? 0 :
                                 (numObjectsSharingMaterial == 0 ? objectCount :
                                  (numObjectsSharingMaterial >= objectCount ? 1 :
                                   (objectCount + numObjectsSharingMaterial - 1) / numObjectsSharingMaterial)));

            materialCountLabel.Text = "Material Count: " + materialCount;
            if (whichObjects == WhichObjectsEnum.woPlane || whichObjects == WhichObjectsEnum.woRandom)
            {
                Mesh plane = meshes[(int)WhichObjectsEnum.woPlane];
                if (plane != null)
                {
                    plane.Unload();
                }
                // Create the plane
                float planeSide  = 1000f;
                int   planeUnits = Int32.Parse(planeUnitsTextBox.Text);
                plane = MeshManager.Instance.CreatePlane("testerPlane", new Plane(Vector3.UnitZ, Vector3.Zero), planeSide, planeSide, planeUnits, planeUnits, true,
                                                         1, planeSide / planeUnits, planeSide / planeUnits, Vector3.UnitY);
                meshes[(int)WhichObjectsEnum.woPlane] = plane;
            }
            // Create the new materials
            for (int i = 0; i < materialCount; i++)
            {
                Material mat = prototypeMaterial.Clone("mat" + i);
                Pass     p   = mat.GetTechnique(0).GetPass(0);
                if (!animatedObjects && uniqueTextures)
                {
                    Texture t       = prototypeTexture;
                    Texture texture = TextureManager.Instance.CreateManual("texture" + i, t.TextureType, t.Width, t.Height, t.NumMipMaps, t.Format, t.Usage);
                    textureList.Add(texture);
                    p.CreateTextureUnitState(texture.Name);
                }
                // Make the materials lovely shades of blue
                p.Ambient  = new ColorEx(1f, .2f, .2f, (1f / materialCount) * i);
                p.Diffuse  = new ColorEx(p.Ambient);
                p.Specular = new ColorEx(1f, 0f, 0f, 0f);
                materialList.Add(mat);
            }

            // Create the entities and scene nodes
            for (int i = 0; i < objectCount; i++)
            {
                Mesh     mesh = selectMesh();
                Material mat  = null;
                if (materialCount > 0)
                {
                    mat = materialList[i % materialCount];
                }
                Entity entity = scene.CreateEntity("entity" + i, mesh);
                if (animatedObjects)
                {
                    string[] visibleSubs = visibleSubMeshes[(int)whichObjects - (int)WhichObjectsEnum.woZombie];
                    for (int j = 0; j < entity.SubEntityCount; ++j)
                    {
                        SubEntity sub     = entity.GetSubEntity(j);
                        bool      visible = false;
                        foreach (string s in visibleSubs)
                        {
                            if (s == sub.SubMesh.Name)
                            {
                                visible = true;
                                break;
                            }
                        }
                        sub.IsVisible = visible;
                        if (visible)
                        {
                            totalVertexCount += sub.SubMesh.VertexData.vertexCount;
                        }
                    }
                }
                else
                {
                    if (mesh.SharedVertexData != null)
                    {
                        totalVertexCount += mesh.SharedVertexData.vertexCount;
                    }
                    else
                    {
                        for (int j = 0; j < mesh.SubMeshCount; j++)
                        {
                            SubMesh subMesh = mesh.GetSubMesh(j);
                            totalVertexCount += subMesh.VertexData.vertexCount;
                        }
                    }
                }
                if (animatedObjects && animateCheckBox.Checked)
                {
                    AnimationState currentAnimation = entity.GetAnimationState(GetAnimationName());
                    currentAnimation.IsEnabled = true;
                    if (!animationInitialized)
                    {
                        currentAnimationLength = entity.GetAnimationState(GetAnimationName()).Length;
                        animationInitialized   = true;
                    }
                }
                if (mat != null)
                {
                    entity.MaterialName = mat.Name;
                }
                entityList.Add(entity);
                SceneNode node = scene.RootSceneNode.CreateChildSceneNode();
                sceneNodeList.Add(node);
                node.AttachObject(entity);
                node.Position = new Vector3(randomCoord(), randomCoord(), randomCoord());
                if (randomSizes)
                {
                    node.ScaleFactor = Vector3.UnitScale * randomScale();
                }
                else if (randomScales)
                {
                    node.ScaleFactor = new Vector3(randomScale(), randomScale(), randomScale());
                }
                else
                {
                    node.ScaleFactor = Vector3.UnitScale * 1f;
                }
                if (randomOrientations)
                {
                    Vector3 axis = new Vector3((float)rand.NextDouble(), (float)rand.NextDouble(), (float)rand.NextDouble());
                    node.Orientation = Vector3.UnitY.GetRotationTo(axis.ToNormalized());
                }
                else
                {
                    node.Orientation = Quaternion.Identity;
                }
            }
        }
Esempio n. 9
0
 public ContextSubEntity(SubEntity subentity)
 {
     this.Category          = (SubEntityBindingPointCategoryEnum)subentity.bindingPointCategory;
     this.BindingPointIndex = subentity.bindingPointIndex;
     this.SubActorLook      = new ContextActorLook(subentity.subEntityLook);
 }
Esempio n. 10
0
 /// <summary>
 /// 构造函数
 /// </summary>
 public SubEntityWrapper(SubEntity entity)
 {
     m_subEntity = entity;
     m_subEntity.DescriptionChanged += SubEntityOnDescriptionChanged;
 }
Esempio n. 11
0
            public void selectComponent(string name)
            {
                // Restore old material to previously selected component
                if (curComponent != null)
                  curComponent.SetMaterial(restoreMat);

                if (string.IsNullOrEmpty(name))
                {
                  curComponent = null;
                  return;
                }

                // Set the new current component and add a wireframe highlight to indicated selection
                curComponent = mainStick.GetSubEntity(name);
                restoreMat = curComponent.GetMaterial();
                MaterialPtr newMat = MaterialManager.Singleton.Create("Highlight", "General");
                Pass highlight = newMat.GetTechnique(0).GetPass(0);
                highlight.LightingEnabled = false;
                highlight.PolygonMode = PolygonMode.PM_WIREFRAME;
                highlight = newMat.GetTechnique(0).CreatePass();
                highlight = curComponent.Technique.GetPass(0);

                curComponent.SetMaterial(newMat);

                Messenger<Material>.Broadcast("CurSelectedMaterial", restoreMat);
            }