示例#1
0
    public bool AddTypeElement(XElement elemtype)
    {
        _normalTexture = new NormalContent();
        _normalTexture.ExternalStorage = storeContainer.shapeStore;
        if (!_normalTexture.AddTypeElement(elemtype))
            _normalTexture = null;

        _matTexture = new TextureContent();
        _matTexture.ExternalStorage = storeContainer.materialStore;
        if (!_matTexture.AddTypeElement(elemtype))
            _matTexture = null;

        return _normalTexture != null && _matTexture != null;
    }
示例#2
0
    public bool AddTypeElement(XElement elemtype)
    {
        _normalTexture = new NormalContent();
        _normalTexture.ExternalStorage = storeContainer.shapeStore;
        if (!_normalTexture.AddTypeElement(elemtype))
        {
            _normalTexture = null;
        }

        _matTexture = new TextureContent();
        _matTexture.ExternalStorage = storeContainer.materialStore;
        if (!_matTexture.AddTypeElement(elemtype))
        {
            _matTexture = null;
        }

        return(_normalTexture != null && _matTexture != null);
    }
示例#3
0
    public bool AddTypeElement(System.Xml.Linq.XElement elemtype)
    {
        XAttribute fileAtt = elemtype.Attribute("file");

        if (fileAtt == null)
        {
            //Add error message here
            return(false);
        }


        if (storeContainer.shapeStore != null &&
            (elemtype.Attribute("normal") != null ||
             elemtype.Attribute("occlusion") != null ||
             elemtype.Attribute("alpha") != null
            ))
        {
            _normalTexture = new NormalContent();
            _normalTexture.ExternalStorage = storeContainer.shapeStore;
            if (!_normalTexture.AddTypeElement(elemtype))
            {
                _normalTexture = null;
            }
        }

        if (storeContainer.specialStore != null &&
            (elemtype.Attribute("metallic") != null ||
             elemtype.Attribute("illumination") != null
            ))
        {
            _specialTexture = new SpecialMapContent();
            _specialTexture.ExternalStorage = storeContainer.specialStore;
            if (!_specialTexture.AddTypeElement(elemtype))
            {
                _specialTexture = null;
            }
        }

        if (storeContainer.materialStore != null &&
            (elemtype.Attribute("pattern") != null ||
             elemtype.Attribute("specular") != null
            ))
        {
            _matTexture = new TextureContent();
            _matTexture.ExternalStorage = storeContainer.materialStore;
            if (!_matTexture.AddTypeElement(elemtype))
            {
                _matTexture = null;
            }
        }


        if (fileAtt.Value == "NONE")
        {
            //This means we don't want to actually store a mesh,
            //but still want to use the category.
            MeshData = new Dictionary <MeshLayer, CPUMesh>();
        }
        else
        {
            string filePath = Path.Combine(Path.GetDirectoryName(new Uri(elemtype.BaseUri).LocalPath), fileAtt.Value);
            filePath = Path.GetFullPath(filePath);

            //	Load the OBJ in
            var lStream  = new FileStream(filePath, FileMode.Open);
            var lOBJData = OBJLoader.LoadOBJ(lStream);
            lStream.Close();
            MeshData = new Dictionary <MeshLayer, CPUMesh>();
            Mesh tempMesh = new Mesh();
            foreach (MeshLayer layer in Enum.GetValues(typeof(MeshLayer)))
            {
                MeshLayer translatedLayer;
                if (layer == MeshLayer.GrowthCutout1 ||
                    layer == MeshLayer.GrowthCutout2 ||
                    layer == MeshLayer.GrowthCutout3)
                {
                    translatedLayer = MeshLayer.GrowthCutout;
                }
                else if (layer == MeshLayer.GrowthMaterial1 ||
                         layer == MeshLayer.GrowthMaterial2 ||
                         layer == MeshLayer.GrowthMaterial3)
                {
                    translatedLayer = MeshLayer.GrowthMaterial;
                }
                else if (layer == MeshLayer.GrowthTransparent1 ||
                         layer == MeshLayer.GrowthTransparent2 ||
                         layer == MeshLayer.GrowthTransparent3)
                {
                    translatedLayer = MeshLayer.GrowthTransparent;
                }
                else
                {
                    translatedLayer = layer;
                }
                tempMesh.LoadOBJ(lOBJData, (layer.ToString()));
                if (tempMesh == null || tempMesh.vertexCount == 0)
                {
                    continue;
                }
                tempMesh.name = filePath + "." + layer.ToString();
                if (translatedLayer == MeshLayer.GrowthCutout ||
                    translatedLayer == MeshLayer.GrowthMaterial ||
                    translatedLayer == MeshLayer.GrowthTransparent)
                {
                    for (int i = (int)translatedLayer; i < (int)translatedLayer + 4; i++)
                    {
                        //This is because the tree growths can be in any order
                        //So we just copy the un-numbered one onto the rest.
                        MeshData[(MeshLayer)i] = new CPUMesh(tempMesh);
                    }
                }
                else
                {
                    MeshData[layer] = new CPUMesh(tempMesh);
                }
                tempMesh.Clear();
            }
            lStream  = null;
            lOBJData = null;
        }

        XAttribute rotAtt = elemtype.Attribute("rotation");

        if (rotAtt == null)
        {
            rotationType = RotationType.None;
        }
        else
        {
            try
            {
                rotationType = (RotationType)Enum.Parse(typeof(RotationType), rotAtt.Value);
            }
            catch
            {
                rotationType = RotationType.None;
                Debug.Log("Unknown rotation value: " + rotAtt.Value);
            }
        }
        return(true);
    }
示例#4
0
    public bool AddTypeElement(System.Xml.Linq.XElement elemtype)
    {
        XAttribute fileAtt = elemtype.Attribute("file");
        if (fileAtt == null)
        {
            //Add error message here
            return false;
        }

        if ((elemtype.Attribute("normal") != null
            || elemtype.Attribute("occlusion") != null
            || elemtype.Attribute("alpha") != null
            || elemtype.Attribute("pattern") != null
            ))
        {
            _normalTexture = new NormalContent();
            _normalTexture.ExternalStorage = storeContainer.shapeStore;
            if (!_normalTexture.AddTypeElement(elemtype))
                _normalTexture = null;
        }

        if ((elemtype.Attribute("metallic") != null
            || elemtype.Attribute("illumination") != null
            ))
        {
            _specialTexture = new SpecialMapContent();
            _specialTexture.ExternalStorage = storeContainer.specialStore;
            if (!_specialTexture.AddTypeElement(elemtype))
                _specialTexture = null;
        }

        if ((elemtype.Attribute("pattern") != null
            || elemtype.Attribute("specular") != null
            ))
        {
            _matTexture = new TextureContent();
            _matTexture.ExternalStorage = storeContainer.materialStore;
            if (!_matTexture.AddTypeElement(elemtype))
                _matTexture = null;
        }

        if (fileAtt.Value == "NONE")
        {
            //This means we don't want to actually store a mesh,
            //but still want to use the category.
            MeshData = new Dictionary<MeshLayer, CPUMesh>();
        }
        else
        {
            string filePath = Path.Combine(Path.GetDirectoryName(new Uri(elemtype.BaseUri).LocalPath), fileAtt.Value);
            filePath = Path.GetFullPath(filePath);

            //	Load the OBJ in
            if (!File.Exists(filePath))
                return false;
            var lStream = new FileStream(filePath, FileMode.Open);
            var lOBJData = OBJLoader.LoadOBJ(lStream);
            lStream.Close();
            MeshData = new Dictionary<MeshLayer, CPUMesh>();
            Mesh tempMesh = new Mesh();
            foreach(MeshLayer layer in Enum.GetValues(typeof(MeshLayer)))
            {
                MeshLayer translatedLayer;
                if (layer == MeshLayer.GrowthCutout1
                    || layer == MeshLayer.GrowthCutout2
                    || layer == MeshLayer.GrowthCutout3)
                    translatedLayer = MeshLayer.GrowthCutout;
                else if (layer == MeshLayer.GrowthMaterial1
                    || layer == MeshLayer.GrowthMaterial2
                    || layer == MeshLayer.GrowthMaterial3)
                    translatedLayer = MeshLayer.GrowthMaterial;
                else if (layer == MeshLayer.GrowthTransparent1
                    || layer == MeshLayer.GrowthTransparent2
                    || layer == MeshLayer.GrowthTransparent3)
                    translatedLayer = MeshLayer.GrowthTransparent;
                else translatedLayer = layer;
                tempMesh.LoadOBJ(lOBJData, (layer.ToString()));
                if (tempMesh == null || tempMesh.vertexCount == 0)
                    continue;
                tempMesh.name = filePath + "." + layer.ToString();
                if(translatedLayer == MeshLayer.GrowthCutout
                    || translatedLayer == MeshLayer.GrowthMaterial
                    || translatedLayer == MeshLayer.GrowthTransparent)
                {
                    for(int i = (int)translatedLayer; i < (int)translatedLayer + 4; i++)
                    {
                        //This is because the tree growths can be in any order
                        //So we just copy the un-numbered one onto the rest.
                        MeshData[(MeshLayer)i] = new CPUMesh(tempMesh);
                    }
                }
                else MeshData[layer] = new CPUMesh(tempMesh);
                tempMesh.Clear();
            }
            lStream = null;
            lOBJData = null;
        }

        XAttribute rotAtt = elemtype.Attribute("rotation");
        if (rotAtt == null)
            rotationType = RotationType.None;
        else
        {
            try
            {
                rotationType = (RotationType)Enum.Parse(typeof(RotationType), rotAtt.Value);
            }
            catch
            {
                rotationType = RotationType.None;
                Debug.Log("Unknown rotation value: " + rotAtt.Value);
            }
        }
        UniqueIndex = num_created;
        num_created++;
        return true;
    }