public void TestContentDataURIs() { string dataUri; string[] uris; object resource; bool success; dataUri = "'data:text/plain\n#version 420 core \nlayout(location = 0) in vec3 position; '"; uris = X3DTypeConverters.GetMFString(dataUri); Assert.IsTrue(uris.Length == 1); success = SceneManager.FetchSingle(uris[0], out resource); Assert.IsTrue(success); Assert.IsTrue(resource is Stream); StreamReader reader = new StreamReader(resource as Stream); string dataTextPlain = reader.ReadToEnd(); string someTestShaderCodeSample = "#version 420 core \nlayout(location = 0) in vec3 position; "; Assert.AreEqual(dataTextPlain, someTestShaderCodeSample); //TODO: complete tests for data:uri as seen in https://developer.mozilla.org/en-US/docs/Web/HTTP/data_URIs }
public void TestMixedURIs() { string url; string[] uris; url = "\"c.jpg\" 'a.jpg' 'b.jpg' \"d.jpg\" 'e.jpg' \"f.jpg\" 'test-helloworld' " + "\"subfolder0\\file0.png\\\" " + "\"Figure14.2ElevationGridMountain.x3d\" " + "'http://www.web3d.org/x3d/content/examples/Vrml2.0Sourcebook/Chapter14-ElevationGrid/Figure14.2ElevationGridMountain.x3d' " + "\"http://www.web3d.org/x3d/content/examples/Vrml2.0Sourcebook/Chapter14-ElevationGrid/Figure14.2ElevationGridMountain.x3d\" " + "'subfolder1\\subfolder1-subfolder\\file1.ext'"; uris = X3DTypeConverters.GetMFString(url); Assert.IsTrue(uris.Length == 12); Assert.AreEqual(uris[0], "c.jpg"); Assert.AreEqual(uris[1], "a.jpg"); Assert.AreEqual(uris[2], "b.jpg"); Assert.AreEqual(uris[3], "d.jpg"); Assert.AreEqual(uris[4], "e.jpg"); Assert.AreEqual(uris[5], "f.jpg"); Assert.AreEqual(uris[6], "test-helloworld"); Assert.AreEqual(uris[7], "subfolder0\\file0.png\\"); Assert.AreEqual(uris[8], "Figure14.2ElevationGridMountain.x3d"); Assert.AreEqual(uris[9], "http://www.web3d.org/x3d/content/examples/Vrml2.0Sourcebook/Chapter14-ElevationGrid/Figure14.2ElevationGridMountain.x3d"); Assert.AreEqual(uris[10], "http://www.web3d.org/x3d/content/examples/Vrml2.0Sourcebook/Chapter14-ElevationGrid/Figure14.2ElevationGridMountain.x3d"); Assert.AreEqual(uris[11], "subfolder1\\subfolder1-subfolder\\file1.ext"); }
public void TestX3DTextMFString() { string text; string[] @strings; text = "\"Textnodeusing\" \"diffuseColorappearance\""; @strings = X3DTypeConverters.GetMFString(text); Assert.IsTrue(@strings.Length == 2); text = "\"SERIF\""; @strings = X3DTypeConverters.GetMFString(text); Assert.IsTrue(@strings.Length == 1); text = "\"Text node using\" \"diffuseColor appearance\""; @strings = X3DTypeConverters.GetMFString(text); Assert.IsTrue(@strings.Length == 2); text = "'Text node using' 'diffuseColor appearance'"; @strings = X3DTypeConverters.GetMFString(text); Assert.IsTrue(@strings.Length == 2); text = "'Text node using' 'diffuseColor \nappearance'"; @strings = X3DTypeConverters.GetMFString(text); Assert.IsTrue(@strings.Length == 2); text = "'Text node \n using' ' diffuseColor \nappearance'"; @strings = X3DTypeConverters.GetMFString(text); Assert.IsTrue(@strings.Length == 2); }
public void TestAbsoluteWebURIs() { string url; string[] uris; object resource; bool success; url = "\"http://www.web3d.org/x3d/content/examples/Basic/DistributedInteractiveSimulation/images/left.png\" \"http://www.web3d.org/x3d/content/examples/Basic/DistributedInteractiveSimulation/images/right.png\" \"http://www.web3d.org/x3d/content/examples/Basic/DistributedInteractiveSimulation/images/front.png\""; uris = X3DTypeConverters.GetMFString(url); Assert.IsTrue(uris.Length == 3); success = SceneManager.FetchSingle(uris[0], out resource); Assert.IsTrue(success); Assert.IsTrue(resource is Stream); success = SceneManager.FetchSingle(uris[1], out resource); Assert.IsTrue(success); Assert.IsTrue(resource is Stream); success = SceneManager.FetchSingle(uris[2], out resource); Assert.IsTrue(success); Assert.IsTrue(resource is Stream); }
public void TestURIWithBackupURI() { string url; string[] uris; object resource; bool success; url = "\"images/left.png\" \"http://www.web3d.org/x3d/content/examples/Basic/DistributedInteractiveSimulation/images/left.png\""; uris = X3DTypeConverters.GetMFString(url); Assert.IsTrue(uris.Length == 2); success = SceneManager.FetchSingle(uris[0], out resource); Assert.IsFalse(success); Assert.IsTrue(resource == null); // even though the relative address fails with uris[0] when looking on the file system // uris[1] should succeed in returning a new copy of the resource from a remote address. success = SceneManager.FetchSingle(uris[1], out resource); Assert.IsTrue(success); Assert.IsTrue(resource is Stream); }
public static bool Fetch(string url_mfstring, out object resource) { if (X3DTypeConverters.IsMFString(url_mfstring)) { string[] urls = X3DTypeConverters.GetMFString(url_mfstring); foreach (string url in urls) { if (FetchSingle(url, out resource)) { return(true); } } resource = null; return(false); } else { return(FetchSingle(url_mfstring, out resource)); } //resource = null; //return false; }
//[XmlIgnore] //public string ShaderSource; #region Rendering Methods public override void Load() { base.Load(); parentShape = GetParent <Shape>(); parentShader = GetParent <ComposedShader>(); string file; string[] mf_urls; if (!string.IsNullOrEmpty(ShaderSource)) { LinkShaderSource(ShaderSource); } else if (Urls != null) { file = Urls.FirstOrDefault(); if (!string.IsNullOrEmpty(file)) { _url = _url.TrimStart(); if (_url.StartsWith(X3DTypeConverters.DATA_TEXT_PLAIN)) { ShaderSource = _url.Remove(0, X3DTypeConverters.DATA_TEXT_PLAIN.Length).TrimStart(); LinkShaderSource(ShaderSource); } else { file = file.Replace("\"", ""); file = SceneManager.CurrentLocation + "\\" + file; if (X3DTypeConverters.IsMFString(file)) { object resource; mf_urls = X3DTypeConverters.GetMFString(file); foreach (string url in mf_urls) { if (SceneManager.FetchSingle(url, out resource)) { Stream s; s = (Stream)resource; StreamReader sr = new StreamReader(s); ShaderSource = sr.ReadToEnd(); s.Close(); break; } } } else { ShaderSource = File.ReadAllText(file); LinkShaderSource(ShaderSource); } } } } }
public void TestFileSystemURIs() { SceneManager.CurrentLocation = X3DExamplesDirectory; string url; string[] uris; object resource; bool success; // TEST MFString PARSING // uris formatted with double quotes url = "spectrum.jpg"; uris = X3DTypeConverters.GetMFString(url); Assert.IsTrue(uris.Length == 1); Assert.AreEqual(uris[0], "spectrum.jpg"); url = "\"spectrum.jpg\""; uris = X3DTypeConverters.GetMFString(url); Assert.IsTrue(uris.Length == 1); Assert.AreEqual(uris[0], "spectrum.jpg"); url = "Background\\texture\\earth.jpg"; uris = X3DTypeConverters.GetMFString(url); Assert.IsTrue(uris.Length == 1); Assert.AreEqual(uris[0], "Background\\texture\\earth.jpg"); url = "\"Background\\texture\\earth.jpg\""; uris = X3DTypeConverters.GetMFString(url); Assert.IsTrue(uris.Length == 1); Assert.AreEqual(uris[0], "Background\\texture\\earth.jpg"); // uris formatted with single quotes url = "'spectrum.jpg'"; uris = X3DTypeConverters.GetMFString(url); Assert.IsTrue(uris.Length == 1); Assert.AreEqual(uris[0], "spectrum.jpg"); url = "'Background\\texture\\earth.jpg'"; uris = X3DTypeConverters.GetMFString(url); Assert.IsTrue(uris.Length == 1); Assert.AreEqual(uris[0], "Background\\texture\\earth.jpg"); // TEST MFString URI fetching url = "spectrum.jpg"; success = SceneManager.FetchSingle(url, out resource); Assert.IsTrue(success); Assert.IsTrue(resource is Stream); url = "\"spectrum.jpg\""; success = SceneManager.FetchSingle(url, out resource); Assert.IsTrue(success); Assert.IsTrue(resource is Stream); url = "Background\\texture\\earth.jpg"; success = SceneManager.FetchSingle(url, out resource); Assert.IsTrue(success); Assert.IsTrue(resource is Stream); SceneManager.CurrentLocation = X3DExamplesDirectory + "Background\\"; url = "'texture\\generic\\BK.png' 'texture\\generic\\DN.png' 'texture\\generic\\FR.png' 'texture\\generic\\LF.png' 'texture\\generic\\RT.png' 'texture\\generic\\UP.png'"; uris = X3DTypeConverters.GetMFString(url); success = SceneManager.FetchSingle(uris[0], out resource); Assert.IsTrue(success); Assert.IsTrue(resource is Stream); success = SceneManager.FetchSingle(uris[1], out resource); Assert.IsTrue(success); Assert.IsTrue(resource is Stream); success = SceneManager.FetchSingle(uris[2], out resource); Assert.IsTrue(success); Assert.IsTrue(resource is Stream); success = SceneManager.FetchSingle(uris[3], out resource); Assert.IsTrue(success); Assert.IsTrue(resource is Stream); success = SceneManager.FetchSingle(uris[4], out resource); Assert.IsTrue(success); Assert.IsTrue(resource is Stream); success = SceneManager.FetchSingle(uris[5], out resource); Assert.IsTrue(success); Assert.IsTrue(resource is Stream); }
private bool GetTextureImageFromMFString2(string mfstring) { Rectangle imgRect; int[] textureMaxSize; int glTexWidth; int glTexHeight; string[] urls; object resource; bool actually_loaded_something; if (X3DTypeConverters.IsMFString(mfstring)) { actually_loaded_something = false; urls = X3DTypeConverters.GetMFString(mfstring); foreach (string url in urls) { if (SceneManager.FetchSingle(url, out resource)) { Stream s; s = (Stream)resource; this.image = new Bitmap(s); s.Close(); actually_loaded_something = true; break; } } if (!actually_loaded_something) { this.image = Properties.Resources.ErrorTexture; } } else { this.image = new Bitmap(mfstring); } if (this.image == null) { return(false); } /* Get the maximum texture size supported by OpenGL: */ textureMaxSize = new int[] { 0 }; GL.GetInteger(GetPName.MaxTextureSize, textureMaxSize); //gl.GetInteger(OpenGL.GL_MAX_TEXTURE_SIZE,textureMaxSize); /* Find the target width and height sizes, which is just the highest * posible power of two that'll fit into the image. */ glTexWidth = textureMaxSize[0]; glTexHeight = textureMaxSize[0]; for (int size = 1; size <= textureMaxSize[0]; size *= 2) { if (image.Width < size) { glTexWidth = size / 2; break; } if (image.Width == size) { glTexWidth = size; } } for (int size = 1; size <= textureMaxSize[0]; size *= 2) { if (image.Height < size) { glTexHeight = size / 2; break; } if (image.Height == size) { glTexHeight = size; } } if (image.Width != glTexWidth || image.Height != glTexHeight) { /* Scale the image according to OpenGL requirements */ Image newImage = image.GetThumbnailImage(glTexWidth, glTexHeight, null, IntPtr.Zero); image.Dispose(); image = (Bitmap)newImage; } //if(file.ToLower().EndsWith(".bmp")) { image.RotateFlip(RotateFlipType.RotateNoneFlipY); //TODO: figure out more efficient code /* Another way to rotate texture on draw() * gl.MatrixMode(OpenGL.GL_TEXTURE); * gl.LoadIdentity(); * gl.Scale(1.0f,-1.0f,1.0f); * gl.MatrixMode(OpenGL.GL_MODELVIEW); */ //} imgRect = new Rectangle(0, 0, image.Width, image.Height); pixelData = image.LockBits(imgRect, ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb); pTexImage = pixelData.Scan0; Width = image.Width; Height = image.Height; _type = InternalImageType.WindowsHandle; return(true); }
private bool GetTextureImageFromMFString(string mfstring) { Rectangle imgRect; int[] textureMaxSize; int glTexWidth; int glTexHeight; string[] urls; object resource; bool actually_loaded_something; actually_loaded_something = false; urls = X3DTypeConverters.GetMFString(mfstring); foreach (string url in urls) { if (SceneManager.FetchSingle(url, out resource)) { if (resource is Stream) { Stream s; s = (Stream)resource; this.image = new Bitmap(s); s.Close(); actually_loaded_something = true; } else { throw new Exception("Resource is of unknown type, consider returning file streams instead"); } break; } } if (!actually_loaded_something) { this.image = Properties.Resources.ErrorTexture; } if (this.image == null) { return(false); } var newSize = GetTextureGLMaxSize(image); Rescale(ref image, newSize); //if(file.ToLower().EndsWith(".bmp")) { image.RotateFlip(RotateFlipType.RotateNoneFlipY); //TODO: figure out more efficient code /* Another way to rotate texture on draw() * gl.MatrixMode(OpenGL.GL_TEXTURE); * gl.LoadIdentity(); * gl.Scale(1.0f,-1.0f,1.0f); * gl.MatrixMode(OpenGL.GL_MODELVIEW); */ //} imgRect = new Rectangle(0, 0, image.Width, image.Height); pixelData = image.LockBits(imgRect, ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb); pTexImage = pixelData.Scan0; Width = image.Width; Height = image.Height; _type = InternalImageType.WindowsHandle; return(true); }
public static bool GetTextureImageFromMFString(string mfstring, out Bitmap image, out int width, out int height, bool flipX = false, bool?rotCW = null) { Rectangle imgRect; int[] textureMaxSize; int glTexWidth; int glTexHeight; string[] urls; object resource; bool actually_loaded_something; actually_loaded_something = false; urls = X3DTypeConverters.GetMFString(mfstring); image = null; width = 0; height = 0; foreach (string url in urls) { if (Path.GetExtension(url).Contains("tga")) { Console.WriteLine("ImageTexture of type '{1}' can not be loaded using C# Bitmap. {0} \nError assett type not supported yet. Consider converting to jpg or png formats to continue", url, Path.GetExtension(url)); continue; } if (SceneManager.FetchSingle(url, out resource)) { if (resource is Stream) { Stream s; s = (Stream)resource; try { image = new Bitmap(s); s.Close(); actually_loaded_something = true; } catch { continue; } } else { throw new Exception("Resource is of unknown type, consider returning file streams instead"); } break; } } if (!actually_loaded_something) { image = Properties.Resources.ErrorTexture; } if (image == null) { return(false); } /* Get the maximum texture size supported by OpenGL: */ textureMaxSize = new int[] { 0 }; GL.GetInteger(GetPName.MaxTextureSize, textureMaxSize); //gl.GetInteger(OpenGL.GL_MAX_TEXTURE_SIZE,textureMaxSize); /* Find the target width and height sizes, which is just the highest * posible power of two that'll fit into the image. */ glTexWidth = textureMaxSize[0]; glTexHeight = textureMaxSize[0]; for (int size = 1; size <= textureMaxSize[0]; size *= 2) { if (image.Width < size) { glTexWidth = size / 2; break; } if (image.Width == size) { glTexWidth = size; } } for (int size = 1; size <= textureMaxSize[0]; size *= 2) { if (image.Height < size) { glTexHeight = size / 2; break; } if (image.Height == size) { glTexHeight = size; } } if (image.Width != glTexWidth || image.Height != glTexHeight) { /* Scale the image according to OpenGL requirements */ Image newImage = image.GetThumbnailImage(glTexWidth, glTexHeight, null, IntPtr.Zero); image.Dispose(); image = (Bitmap)newImage; } //image.RotateFlip(RotateFlipType.RotateNoneFlipY); //TODO: figure out more efficient code if (flipX) { image.RotateFlip(RotateFlipType.RotateNoneFlipX); } if (rotCW.HasValue) { if (rotCW.Value) { // Clockwise by 90 degrees image.RotateFlip(RotateFlipType.Rotate90FlipNone); } else { // Counterclockwise by -90 degrees image.RotateFlip(RotateFlipType.Rotate270FlipNone); } } /* Another way to rotate texture on draw() * gl.MatrixMode(OpenGL.GL_TEXTURE); * gl.LoadIdentity(); * gl.Scale(1.0f,-1.0f,1.0f); * gl.MatrixMode(OpenGL.GL_MODELVIEW); */ //} imgRect = new Rectangle(0, 0, image.Width, image.Height); width = image.Width; height = image.Height; return(true); }