public FigureRenderer Load(IArchiveDirectory figureDir, MaterialSetAndVariantOption materialSetOption) { SurfaceProperties surfaceProperties = Persistance.Load <SurfaceProperties>(figureDir.File("surface-properties.dat")); var refinementDirectory = figureDir.Subdirectory("refinement"); var controlMeshDirectory = refinementDirectory.Subdirectory("control"); int[] surfaceMap = controlMeshDirectory.File("surface-map.array").ReadArray <int>(); var refinedMeshDirectory = refinementDirectory.Subdirectory("level-" + surfaceProperties.SubdivisionLevel); SubdivisionMesh mesh = SubdivisionMeshPersistance.Load(refinedMeshDirectory); int[] controlFaceMap = refinedMeshDirectory.File("control-face-map.array").ReadArray <int>(); var materialSet = MaterialSet.LoadActive(device, shaderCache, textureCache, dataDir, figureDir, materialSetOption, surfaceProperties); var materials = materialSet.Materials; Scatterer scatterer = surfaceProperties.PrecomputeScattering ? Scatterer.Load(device, shaderCache, figureDir, materialSetOption.MaterialSet.Label) : null; var uvSetName = materials[0].UvSet; IArchiveDirectory uvSetDirectory = figureDir.Subdirectory("uv-sets").Subdirectory(uvSetName); var texturedVertexInfos = uvSetDirectory.File("textured-vertex-infos.array").ReadArray <TexturedVertexInfo>(); Quad[] texturedFaces = uvSetDirectory.File("textured-faces.array").ReadArray <Quad>(); var vertexRefiner = new VertexRefiner(device, shaderCache, mesh, texturedVertexInfos); FigureSurface[] surfaces = FigureSurface.MakeSurfaces(device, materials.Length, texturedFaces, controlFaceMap, surfaceMap, materialSet.FaceTransparencies); HashSet <int> visitedSurfaceIndices = new HashSet <int>(); List <int> surfaceOrder = new List <int>(surfaces.Length); bool[] areUnorderedTransparent = new bool[surfaces.Length]; //first add surfaces with an explicity-set render order foreach (int surfaceIdx in surfaceProperties.RenderOrder) { visitedSurfaceIndices.Add(surfaceIdx); surfaceOrder.Add(surfaceIdx); areUnorderedTransparent[surfaceIdx] = false; } //then add any remaining surfaces for (int surfaceIdx = 0; surfaceIdx < surfaces.Length; ++surfaceIdx) { if (visitedSurfaceIndices.Contains(surfaceIdx)) { continue; } surfaceOrder.Add(surfaceIdx); areUnorderedTransparent[surfaceIdx] = true; } var isOneSided = figureDir.Name == "genesis-3-female"; //hack return(new FigureRenderer(device, shaderCache, scatterer, vertexRefiner, materialSet, surfaces, isOneSided, surfaceOrder.ToArray(), areUnorderedTransparent)); }
public static Scatterer Load(Device device, ShaderCache shaderCache, IArchiveDirectory figureDir, String materialSetName) { var l0GeometryDir = figureDir.Subdirectory("refinement").Subdirectory("level-0"); SubdivisionMesh level0Mesh = SubdivisionMeshPersistance.Load(l0GeometryDir); var scatteringDir = figureDir.Subdirectory("scattering").Subdirectory(materialSetName); var formFactorSegments = scatteringDir.File(FormFactorSegmentsFilename).ReadArray <ArraySegment>(); var formFactorElements = scatteringDir.File(FormFactoryElementsFilename).ReadArray <Vector3WeightedIndex>(); var formFactors = new PackedLists <Vector3WeightedIndex>(formFactorSegments, formFactorElements); return(new Scatterer(device, shaderCache, level0Mesh, formFactors)); }
public ShapeNormals Load(IArchiveDirectory figureDir, Shape shape) { var file = shape.Directory?.File("shape-normals.dat"); if (file == null) { return(null); } var recipe = Persistance.Load <ShapeNormalsRecipe>(file); var uvSetName = recipe.UvSetName; IArchiveDirectory uvSetsDirectory = figureDir.Subdirectory("uv-sets"); IArchiveDirectory uvSetDirectory = uvSetsDirectory.Subdirectory(uvSetName); var texturedVertexInfos = uvSetDirectory.File("textured-vertex-infos.array").ReadArray <TexturedVertexInfo>(); var texturesDirectory = dataDir.Subdirectory("textures"); var textureLoader = new TextureLoader(device, textureCache, texturesDirectory); var normalMapsBySurface = recipe.TextureNamesBySurface .Select(name => name != ShapeNormalsRecipe.DefaultTextureName ? name : null) .Select(name => textureLoader.Load(name, TextureLoader.DefaultMode.Bump)) .ToArray(); return(new ShapeNormals(textureLoader, texturedVertexInfos, normalMapsBySurface)); }
public static FigureDefinition Load(IArchiveDirectory dataDir, string name, FigureDefinition parent) { IArchiveDirectory figureDir = dataDir.Subdirectory("figures").Subdirectory(name); var channelSystemRecipe = Persistance.Load <ChannelSystemRecipe>(figureDir.File("channel-system-recipe.dat")); var channelSystem = channelSystemRecipe.Bake(parent?.ChannelSystem); BoneSystem boneSystem; RigidTransform[] childToParentBindPoseTransforms; if (parent != null) { boneSystem = parent.BoneSystem; childToParentBindPoseTransforms = Persistance.Load <RigidTransform[]>(figureDir.File("child-to-parent-bind-pose-transforms.dat")); } else { var boneSystemRecipe = Persistance.Load <BoneSystemRecipe>(figureDir.File("bone-system-recipe.dat")); boneSystem = boneSystemRecipe.Bake(channelSystem.ChannelsByName); childToParentBindPoseTransforms = null; } var shapeOptions = Shape.LoadAllForFigure(figureDir, channelSystem); var materialSetOptions = MaterialSetOption.LoadAllForFigure(figureDir); return(new FigureDefinition(name, figureDir, channelSystem, boneSystem, childToParentBindPoseTransforms, shapeOptions, materialSetOptions)); }
public static IArchiveFile File(this IArchiveDirectory dir, string[] path) { for (int i = 0; i < path.Length - 1; ++i) { dir = dir.Subdirectory(path[i]); } return(dir.File(path[path.Length - 1])); }
public static List <Character> LoadList(IArchiveDirectory dataDir) { var dir = dataDir.Subdirectory("characters"); var characters = dir.GetFiles() .Select(file => Persistance.Load <Character>(file)) .ToList(); return(characters); }
public static List <Outfit> LoadList(IArchiveDirectory dataDir) { var outfitsDir = dataDir.Subdirectory("outfits"); var outfits = outfitsDir.GetFiles() .Select(outfitFile => Persistance.Load <Outfit>(outfitFile)) .Concat(new List <Outfit> { Naked }) .ToList(); return(outfits); }
public static IMenuLevel MakeMenuLevel(IArchiveDirectory dataDir, ImageBasedLightingEnvironment environment) { var environmentsDir = dataDir.Subdirectory("environments"); List <IMenuItem> items = new List <IMenuItem>() { MakeRotationItem(environment) }; items.AddRange(MakeEnvironmentsMenuItems(environmentsDir, environment)); return(new StaticMenuLevel(items.ToArray())); }
public static List <MaterialSetOption> LoadAllForFigure(IArchiveDirectory figureDir) { List <MaterialSetOption> materialSets = new List <MaterialSetOption>(); IArchiveDirectory materialSetsDirectory = figureDir.Subdirectory("material-sets"); foreach (var materialSetDirectory in materialSetsDirectory.Subdirectories) { var materialSet = MaterialSetOption.Load(materialSetDirectory); materialSets.Add(materialSet); } return(materialSets); }
public static MaterialSet LoadActive(Device device, ShaderCache shaderCache, TextureCache textureCache, IArchiveDirectory dataDir, IArchiveDirectory figureDir, MaterialSetAndVariantOption materialSetOption, SurfaceProperties surfaceProperties) { var materialSetDirectory = materialSetOption.MaterialSet.Directory; var texturesDirectory = dataDir.Subdirectory("textures"); var textureLoader = new TextureLoader(device, textureCache, texturesDirectory); var materialSettingsBySurface = materialSetOption.PerSurfaceSettings; var materials = materialSettingsBySurface.Select(settings => settings.Load(device, shaderCache, textureLoader)).ToArray(); float[] faceTransparencies = materialSetDirectory.File("face-transparencies.array").ReadArray <float>(); return(new MaterialSet(textureLoader, materials, faceTransparencies)); }
public CompanionWindow(Device device, ShaderCache shaderCache, StandardSamplers standardSamplers, string title, IArchiveDirectory dataDir) { this.device = device; this.standardSamplers = standardSamplers; form = new RenderForm(title); // SwapChain description var desc = new SwapChainDescription() { BufferCount = 1, ModeDescription = new ModeDescription(form.ClientSize.Width, form.ClientSize.Height, default(Rational), Format.R8G8B8A8_UNorm_SRgb), IsWindowed = true, OutputHandle = form.Handle, SampleDescription = new SampleDescription(1, 0), SwapEffect = SwapEffect.Discard, //TODO: consider using flip Usage = Usage.RenderTargetOutput }; using (var factory = new Factory1()) { factory.MakeWindowAssociation(form.Handle, WindowAssociationFlags.IgnoreAll); swapChain = new SwapChain(factory, device, desc); } form.UserResized += OnUserResized; SetupBackbufferAndViewport(); copyFromSourceVertexShader = shaderCache.GetVertexShader <CompanionWindow>("viewer/companion-window/CopyFromSource"); copyFromSourcePixelShader = shaderCache.GetPixelShader <CompanionWindow>("viewer/companion-window/CopyFromSource"); uiBlendState = MakeUiBlendState(device); aspectRatiosBufferManager = new ConstantBufferManager <AspectRatios>(device); overlay = Overlay.Load(device, shaderCache, dataDir.Subdirectory("ui").File("put-on-headset-overlay.dds")); form.KeyPress += OnKeyPress; form.MouseDown += OnMouseDown; form.MouseUp += OnMouseUp; form.MouseMove += OnMouseMove; DebugInitialize(); }
public static MaterialSet LoadActive(Device device, ShaderCache shaderCache, TextureCache textureCache, IArchiveDirectory dataDir, IArchiveDirectory figureDir, string materialSetName, SurfaceProperties surfaceProperties) { var materialsDirectory = figureDir .Subdirectory("material-sets") .Subdirectory(materialSetName); var texturesDirectory = surfaceProperties.ShareTextures != null? dataDir.Subdirectory("textures").Subdirectory(surfaceProperties.ShareTextures) : materialsDirectory; var textureLoader = new TextureLoader(device, textureCache, texturesDirectory); var multiMaterialSettings = Persistance.Load <MultiMaterialSettings>(materialsDirectory.File("material-settings.dat")); var materials = multiMaterialSettings.PerMaterialSettings.Select(settings => settings.Load(device, shaderCache, textureLoader)).ToArray(); float[] faceTransparencies = materialsDirectory.File("face-transparencies.array").ReadArray <float>(); return(new MaterialSet(textureLoader, materials, faceTransparencies)); }
public static List <Shape> LoadAllForFigure(IArchiveDirectory figureDir, ChannelSystem channelSystem) { List <Shape> shapes = new List <Shape>(); IArchiveDirectory shapesDirectory = figureDir.Subdirectory("shapes"); if (shapesDirectory != null) { foreach (var shapeDirectory in shapesDirectory.Subdirectories) { var shape = Shape.Load(channelSystem, shapeDirectory); shapes.Add(shape); } } else { var defaultShape = Shape.LoadDefault(channelSystem, figureDir); shapes.Add(defaultShape); } return(shapes); }