/// <summary> /// Create a GLTFExporter that exports out a transform /// </summary> /// <param name="rootTransforms">Root transform of object to export</param> public GLTFSceneExporter(Transform[] rootTransforms) { _rootTransforms = rootTransforms; _root = new GLTFRoot { Accessors = new List <Accessor>(), Asset = new Asset { Version = "2.0" }, Buffers = new List <GLTF.Schema.Buffer>(), BufferViews = new List <BufferView>(), Images = new List <Image>(), Materials = new List <GLTF.Schema.Material>(), Meshes = new List <GLTF.Schema.Mesh>(), Nodes = new List <Node>(), Samplers = new List <Sampler>(), Scenes = new List <Scene>(), Textures = new List <GLTF.Schema.Texture>(), }; _images = new List <Texture2D>(); _materials = new List <UnityEngine.Material>(); _textures = new List <UnityEngine.Texture>(); _buffer = new GLTF.Schema.Buffer(); _bufferId = new BufferId { Id = _root.Buffers.Count, Root = _root }; _root.Buffers.Add(_buffer); }
public static AccessorId WriteAccessor(this GLTFRoot root, BufferId bufferId, Matrix4x4[] arr, BufferViewId bufferViewId = null, BinaryWriter writer = null) { var count = arr.Length; if (count == 0) { MyLog.LogError("Accessors can not have a count of 0."); } var accessor = new Accessor(); accessor.ComponentType = GLTFComponentType.Float; accessor.Count = count; accessor.Type = GLTFAccessorAttributeType.MAT4; var byteOffset = writer.BaseStream.Position; foreach (var vec in arr) { writer.Write(vec.m00); writer.Write(vec.m10); writer.Write(vec.m20); writer.Write(vec.m30); writer.Write(vec.m01); writer.Write(vec.m11); writer.Write(vec.m21); writer.Write(vec.m31); writer.Write(vec.m02); writer.Write(vec.m12); writer.Write(vec.m22); writer.Write(vec.m32); writer.Write(vec.m03); writer.Write(vec.m13); writer.Write(vec.m23); writer.Write(vec.m33); } var byteLength = writer.BaseStream.Position - byteOffset; if (bufferViewId != null) { accessor.BufferView = bufferViewId; accessor.ByteOffset = (int)byteOffset; } else { accessor.BufferView = root.WriteBufferView(bufferId, (int)byteOffset, (int)byteLength); } var id = new AccessorId { Id = root.Accessors.Count, Root = root }; root.Accessors.Add(accessor); return(id); }
public async Task TestReadFromStream() { var options = new FileBufferOptions(100, 10); await using var buffers = new FileBuffers(options); using var memStream = new MemoryStream(); var data = new byte[150]; for (byte i = 0; i < data.Length; i++) { data[i] = i; } memStream.Write(data, 0, data.Length); var id = new BufferId(Guid.NewGuid(), "*"); await using var buffer = await buffers.AddForMememoryStream(id, memStream).NoSync(); var page = UseAndReturn.That(await buffer.GetPageAsync(0).ConfigureAwait(false)); AssertEqual(1, page.Data[1]); AssertEqual(100, page.Data.Length); await page.DisposeAsync().NoSync(); AssertEqual(1, buffers.Pool.Count); page = UseAndReturn.That(await buffer.GetPageAsync(0).ConfigureAwait(false)); AssertEqual(0L, page.Data.Number); AssertEqual(1, buffer.NumberOfBufferedPages); await page.DisposeAsync().NoSync(); }
protected override void Init() { base.Init(); this._root = new GLTFRoot { Accessors = new List <Accessor>(), Asset = new Asset { Version = "2.0", Generator = "paper", Extensions = new Dictionary <string, IExtension>(), }, Buffers = new List <GLTF.Schema.Buffer>(), BufferViews = new List <BufferView>(), Meshes = new List <GLTF.Schema.Mesh>() }; _root.Asset.Extensions.Add(CoordinateSystemExtensionFactory.EXTENSION_NAME, new CoordinateSystemExtension(CoordinateSystem.leftHand.ToString(), 1.0f)); _buffer = new GLTF.Schema.Buffer(); _bufferId = new BufferId { Id = _root.Buffers.Count, Root = _root }; _root.Buffers.Add(_buffer); }
public Viewport(SourceFile destination, TextSpan region, TextSpan outerRegion, BufferId bufferId) { Region = region; BufferId = bufferId; OuterRegion = outerRegion; Destination = destination ?? throw new ArgumentNullException(nameof(destination)); }
protected override void Init() { base.Init(); this._root = new GLTFRoot { Accessors = new List <Accessor>(), Asset = new Asset { Version = "2.0", Generator = "paper", }, Buffers = new List <GLTF.Schema.Buffer>(), BufferViews = new List <BufferView>(), Animations = new List <GLTF.Schema.Animation>(), }; _buffer = new GLTF.Schema.Buffer(); _bufferId = new BufferId { Id = _root.Buffers.Count, Root = _root }; _root.Buffers.Add(_buffer); }
public static Buffer CreateBuffer(string content, BufferId id) { MarkupTestFile.GetPosition(content, out var output, out var position); return(new Buffer( id, output, position ?? 0)); }
public static File GetFileFromBufferId(this Workspace workspace, BufferId bufferId) { if (bufferId == null) { throw new ArgumentNullException(nameof(bufferId)); } return(workspace.Files.FirstOrDefault(f => f.Name == bufferId.FileName)); }
public static Workspace AddBuffer( this Workspace workspace, string id, string text) => new Workspace( workspace.Usings, workspace.Files, workspace.Buffers.Concat(new[] { new Buffer(BufferId.Parse(id), text) }).ToArray(), workspace.WorkspaceType, workspace.IncludeInstrumentation);
public void BufferIds_have_the_same_hash_codes_only_if_they_have_the_same_file_and_region_names( string input1, string input2, bool expectedToBeEqual) { var bufferId1 = BufferId.Parse(input1); var bufferId2 = BufferId.Parse(input2); bufferId1.GetHashCode().Equals(bufferId2.GetHashCode()).Should().Be(expectedToBeEqual); }
public void BufferId_Parse_sets_file_name_and_region_name_correctly( string input, string expectedFileName, string expectedRegionName) { var bufferId = BufferId.Parse(input); bufferId.FileName.Should().Be(expectedFileName); bufferId.RegionName.Should().Be(expectedRegionName); }
public static async Task <IReadOnlyCollection <SerializableDiagnostic> > ExtractSerializableDiagnosticsFromDocument( BufferId bufferId, Budget budget, Document selectedDocument, Workspace workspace) { var semanticModel = await selectedDocument.GetSemanticModelAsync(); return(ExtractSerializableDiagnosticsFromSemanticModel(bufferId, budget, semanticModel, workspace)); }
public static IReadOnlyCollection <SerializableDiagnostic> ExtractSerializableDiagnosticsFromSemanticModel( BufferId bufferId, Budget budget, SemanticModel semanticModel, Workspace workspace) { var diagnostics = workspace.MapDiagnostics(bufferId, semanticModel.GetDiagnostics().ToArray(), budget); return(diagnostics.DiagnosticsInActiveBuffer); }
public static int GetAbsolutePositionForGetBufferWithSpecifiedIdOrSingleBufferIfThereIsOnlyOne( this Workspace workspace, BufferId bufferId = null) { // TODO: (GetAbsolutePositionForGetBufferWithSpecifiedIdOrSingleBufferIfThereIsOnlyOne) this concept should go away var buffer = workspace.GetBufferWithSpecifiedIdOrSingleBufferIfThereIsOnlyOne(bufferId); return(buffer.AbsolutePosition); }
public static SerializableDiagnostic ToSerializableDiagnostic( this Diagnostic diagnostic, string message = null, BufferId bufferId = null) { var diagnosticMessage = diagnostic.GetMessage(); var startPosition = diagnostic.Location.GetLineSpan().Span.Start; var diagnosticFilePath = diagnostic?.Location.SourceTree?.FilePath ?? bufferId?.FileName // F# doesn't have a source tree ?? diagnostic?.Location.GetLineSpan().Path; var location = diagnostic.Location != null ? $"{diagnosticFilePath}({startPosition.Line + 1},{startPosition.Character + 1}): {GetMessagePrefix()}" : null; return(new SerializableDiagnostic(diagnostic.Location?.SourceSpan.Start ?? throw new ArgumentException(nameof(diagnostic.Location)), diagnostic.Location.SourceSpan.End, message ?? diagnosticMessage, diagnostic.ConvertSeverity(), diagnostic.Descriptor.Id, bufferId, location)); string GetMessagePrefix() { string prefix; switch (diagnostic.Severity) { case RoslynDiagnosticSeverity.Hidden: prefix = "hidden"; break; case RoslynDiagnosticSeverity.Info: prefix = "info"; break; case RoslynDiagnosticSeverity.Warning: prefix = "warning"; break; case RoslynDiagnosticSeverity.Error: prefix = "error"; break; default: return(null); } return($"{prefix} {diagnostic.Id}"); } }
public void TestBufferId() { var g = Guid.NewGuid(); var b1 = new BufferId(g, "x"); var b2 = new BufferId(g, "y"); var b3 = new BufferId(Guid.NewGuid(), "x"); AssertEqual(b1, b2); AssertEqual(b1.GetHashCode(), b2.GetHashCode()); AssertEqual(false, b1.Equals(b3)); }
public void When_ActiveBufferId_is_not_specified_and_there_is_only_one_buffer_then_it_returns_that_buffers_id() { var request = new WorkspaceRequest( new Workspace( buffers: new[] { new Buffer("the.only.buffer.cs", "its content", 123) }), requestId: "TestRun"); request.ActiveBufferId.Should().Be(BufferId.Parse("the.only.buffer.cs")); }
internal static (int line, int column, int absolutePosition) GetTextLocation( this Workspace workspace, BufferId bufferId) { var file = workspace.GetFileFromBufferId(bufferId); var absolutePosition = GetAbsolutePositionForGetBufferWithSpecifiedIdOrSingleBufferIfThereIsOnlyOne(workspace, bufferId); var src = SourceText.From(file.Text); var line = src.Lines.GetLineFromPosition(absolutePosition); return(line : line.LineNumber, column : absolutePosition - line.Start, absolutePosition); }
public void When_there_is_only_one_buffer_and_it_has_an_id_that_does_not_match_then_GetAbsolutePosition_returns_its_position () { var workspace = new Workspace( buffers: new[] { new Buffer(BufferId.Parse("nonexistent.cs"), "content", 123) }); workspace.GetAbsolutePositionForGetBufferWithSpecifiedIdOrSingleBufferIfThereIsOnlyOne().Should().Be(123); }
public async Task Response_with_multi_buffer_using_relative_paths_workspace() { #region bufferSources const string program = @"using System; using System.Linq; namespace FibonacciTest { public class Program { public static void Main() { foreach (var i in FibonacciGenerator.Fibonacci().Take(20)) { Console.WriteLine(i); } } } }"; const string generator = @"using System.Collections.Generic; namespace FibonacciTest { public static class FibonacciGenerator { public static IEnumerable<int> Fibonacci() { int current = 1, next = 1; while (true) { yield return current; next = current + (current = next); } } } }"; #endregion var server = GetCodeRunner(); var workspace = new Workspace(workspaceType: "console", buffers: new[] { new Buffer("Program.cs", program, 0), new Buffer("generators/FibonacciGenerator.cs", generator, 0) }); var result = await server.Run(new WorkspaceRequest(workspace, BufferId.Parse("Program.cs"))); result.Succeeded.Should().BeTrue(); result.Output.Count.Should().Be(21); result.Output.Should().BeEquivalentTo("1", "1", "2", "3", "5", "8", "13", "21", "34", "55", "89", "144", "233", "377", "610", "987", "1597", "2584", "4181", "6765", ""); }
public static async Task Main() { await using var buffers = new FileBuffers(new FileBufferOptions()); var id = new BufferId(Guid.NewGuid(), "*"); var buffer = await buffers.AddForFile(id, "d:\\temp\\2.abc").NoSync(); for (var i = 0; i < buffer.PageCount; i++) { await using var p1 = UseAndReturn.That(await buffer.GetPageAsync(i).NoSync()); Console.WriteLine("Data: " + p1.Data[0].ToString(CultureInfo.CurrentCulture)); } }
public async Task Compile_response_with_multi_buffer_using_relative_paths_workspace() { #region bufferSources const string program = @"using System; using System.Linq; namespace FibonacciTest { public class Program { public static void Main() { foreach (var i in FibonacciGenerator.Fibonacci().Take(20)) { Console.WriteLine(i); } } } }"; const string generator = @"using System.Collections.Generic; namespace FibonacciTest { public static class FibonacciGenerator { public static IEnumerable<int> Fibonacci() { int current = 1, next = 1; while (true) { yield return current; next = current + (current = next); } } } }"; #endregion var server = GetCodeCompiler(); var workspace = new Workspace(workspaceType: "console", buffers: new[] { new Buffer("Program.cs", program, 0), new Buffer("generators/FibonacciGenerator.cs", generator, 0) }); var result = await server.Compile(new WorkspaceRequest(workspace, BufferId.Parse("Program.cs"))); result.Succeeded.Should().BeTrue(); }
public void Finish() { var prefixStr = Config.GeneratorName; for (var i = Config.GeneratorName.Length; i < 24; i += 1) { prefixStr += " "; } var prefix = Encoding.ASCII.GetBytes(prefixStr); var uri = name + ".bin"; var fp = Path.Combine(ExporterSettings.Export.folder, uri); var bufferId = new BufferId { Id = 0, Root = root }; var outputFile = new FileStream(fp, FileMode.Create); int offset = prefix.Length; using (var binWriter = new BinaryWriter(outputFile)) { binWriter.Write(prefix); foreach (var bufferView in _bufferViews) { int length = 0; if (bufferView.byteBuffer != null) { length = bufferView.byteBuffer.Length; binWriter.Write(bufferView.byteBuffer); } else if (bufferView.streamBuffer != null) { length = (int)bufferView.streamBuffer.Length; binWriter.Write(bufferView.streamBuffer.ToArray()); } bufferView.view.ByteLength = length; bufferView.view.ByteOffset = offset; bufferView.view.Buffer = bufferId; offset += length; } binWriter.Flush(); } var buffer = new GLTF.Schema.Buffer(); buffer.ByteLength = offset; buffer.Uri = uri; root.Buffers = new List<GLTF.Schema.Buffer> { buffer }; using (var writer = File.CreateText(path)) { root.Serialize(writer); } }
public void BufferIds_are_equal_only_if_they_have_the_same_file_and_region_names( string input1, string input2, bool expectedToBeEqual) { var bufferId1 = BufferId.Parse(input1); var bufferId2 = BufferId.Parse(input2); bufferId1.Equals(bufferId2).Should().Be(expectedToBeEqual); (bufferId1 == bufferId2).Should().Be(expectedToBeEqual); (bufferId2 == bufferId1).Should().Be(expectedToBeEqual); (bufferId1 != bufferId2).Should().Be(!expectedToBeEqual); (bufferId2 != bufferId1).Should().Be(!expectedToBeEqual); }
public static Buffer GetBufferAsync( this AnnotatedCodeBlock block, IDirectoryAccessor directoryAccessor, MarkdownFile markdownFile) { if (block.Annotations is LocalCodeBlockAnnotations localOptions) { var absolutePath = directoryAccessor.GetFullyQualifiedPath(localOptions.SourceFile).FullName; var bufferId = new BufferId(absolutePath, block.Annotations.Region); return(new Buffer(bufferId, block.SourceCode)); } return(null); }
private async Task <(IReadOnlyCollection <SerializableDiagnostic> DiagnosticsInActiveBuffer, IReadOnlyCollection <SerializableDiagnostic> AllDiagnostics)> ExtractDiagnostics( Workspace workspace, BufferId activeBufferId, ScriptOptions options) { workspace = await _transformer.TransformAsync(workspace); var sourceFile = workspace.GetSourceFiles().Single(); var code = sourceFile.Text.ToString(); var compilation = CSharpScript.Create(code, options).GetCompilation(); return(workspace.MapDiagnostics( activeBufferId, compilation.GetDiagnostics())); }
public void When_buffer_id_is_empty_and_there_is_a_file_with_empty_string_for_id_then_GetFileFromBufferId_returns_it() { var workspace = new Workspace( buffers: new[] { new Buffer(BufferId.Parse(""), "content", 123) }, files: new[] { new File("", "content") }); workspace.GetFileFromBufferId(BufferId.Empty).Should().NotBeNull(); }
public async Task TestPageCaching() { var options = new FileBufferOptions(10, 5); await using var buffers = new FileBuffers(options); var memStream = new MemoryStream(); var data = new byte[150]; for (byte i = 0; i < data.Length; i++) { data[i] = i; } memStream.Write(data, 0, data.Length); var id = new BufferId(Guid.NewGuid(), "*"); await using var buffer = await buffers.AddForMememoryStream(id, memStream).NoSync(); await using var page1 = await buffer.GetPageAsync(0).NoSync(); await using var page2 = await buffer.GetPageAsync(1).NoSync(); await using var page3 = await buffer.GetPageAsync(2).NoSync(); await using var page4 = await buffer.GetPageAsync(3).NoSync(); await using (var page5 = await buffer.GetPageAsync(4).NoSync()) { AssertEqual(0L, page1.Number); AssertEqual(1L, page2.Number); AssertEqual(2L, page3.Number); AssertEqual(3L, page4.Number); AssertEqual(4L, page5.Number); AssertEqual(5, buffer.NumberOfBufferedPages); await using var page6 = await buffer.GetPageAsync(5).ConfigureAwait(false); AssertEqual(5L, page6.Number); AssertEqual(6, buffer.NumberOfBufferedPages); await page6.UnPin().NoSync(); } AssertEqual(5, buffer.NumberOfBufferedPages); }
public void WorkspaceRequest_deserializes_from_JSON() { var(processed, position) = CodeManipulation.ProcessMarkup("Console.WriteLine($$)"); var original = new WorkspaceRequest( activeBufferId: BufferId.Parse("default.cs"), workspace: Workspace.FromSource( processed, "script", id: "default.cs", position: position), requestId: "TestRun"); var json = original.ToJson(); var deserialized = json.FromJsonTo <WorkspaceRequest>(); deserialized.Should().BeEquivalentTo(original); }
protected override void Init() { base.Init(); _root = new GLTFRoot { Accessors = new List <Accessor>(), Asset = new Asset { Version = "2.0", Generator = "paper", }, Buffers = new List <GLTF.Schema.Buffer>(), BufferViews = new List <BufferView>() { new BufferView { Buffer = new BufferId() { Id = 0, Root = _root, }, ByteOffset = 0, ByteLength = 0, } }, Nodes = new List <Node>(), Scenes = new List <Scene>() { new Scene() { Nodes = new List <NodeId>(), } }, Animations = new List <GLTF.Schema.Animation>(), }; _buffer = new GLTF.Schema.Buffer(); _bufferId = new BufferId { Id = _root.Buffers.Count, Root = _root }; _root.Buffers.Add(_buffer); }