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 IOccluder Load(IArchiveDirectory occlusionDirectory)
    {
        bool isMainFigure = channelSystem.Parent == null;

        if (isMainFigure)
        {
            IArchiveFile occluderParametersFile = occlusionDirectory.File("occluder-parameters.dat");
            if (occluderParametersFile == null)
            {
                throw new InvalidOperationException("expected main figure to have occlusion system");
            }

            var             occluderParameters      = Persistance.Load <OccluderParameters>(occluderParametersFile);
            OcclusionInfo[] unmorphedOcclusionInfos = OcclusionInfo.UnpackArray(unmorphedOcclusionDirectory.File("occlusion-infos.array").ReadArray <uint>());
            var             occluder = new DeformableOccluder(device, shaderCache, channelSystem, unmorphedOcclusionInfos, occluderParameters);
            return(occluder);
        }
        else
        {
            OcclusionInfo[] figureOcclusionInfos = OcclusionInfo.UnpackArray(occlusionDirectory.File("occlusion-infos.array").ReadArray <uint>());
            OcclusionInfo[] parentOcclusionInfos = OcclusionInfo.UnpackArray(occlusionDirectory.File("parent-occlusion-infos.array").ReadArray <uint>());
            var             occluder             = new StaticOccluder(device, figureOcclusionInfos, parentOcclusionInfos);
            return(occluder);
        }
    }
예제 #3
0
    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));
    }
예제 #4
0
    public static Shape Load(ChannelSystem channelSystem, IArchiveDirectory shapeDirectory)
    {
        var channelInputsFile = shapeDirectory.File("channel-inputs.dat");
        var channelInputs     = LoadChannelInputs(channelSystem, channelInputsFile);

        var parentOverridesFile = shapeDirectory.File("parent-overrides.dat");
        var parentOverrides     = LoadParentOverrides(channelSystem, parentOverridesFile);

        return(new Shape(shapeDirectory.Name, shapeDirectory, channelInputs, parentOverrides));
    }
예제 #5
0
    public static Shape LoadDefault(ChannelSystem channelSystem, IArchiveDirectory figureDirectory)
    {
        var channelInputsFile = figureDirectory.File("channel-inputs.dat");
        var channelInputs     = channelInputsFile != null?
                                LoadChannelInputs(channelSystem, channelInputsFile) :
                                    channelSystem.MakeDefaultChannelInputs();

        var parentOverridesFile = figureDirectory.File("parent-overrides.dat");
        var parentOverrides     = LoadParentOverrides(channelSystem, parentOverridesFile);

        return(new Shape(DefaultLabel, null, channelInputs, parentOverrides));
    }
    public static SubdivisionMesh Load(IArchiveDirectory directory)
    {
        var stencilSegments = directory.File(StencilSegmentsFilename).ReadArray <ArraySegment>();
        var stencilElements = directory.File(StencilElementsFilename).ReadArray <WeightedIndexWithDerivatives>();
        var faces           = directory.File(StencilFacesFilename).ReadArray <Quad>();

        var stencils = new PackedLists <WeightedIndexWithDerivatives>(stencilSegments, stencilElements);

        int vertexCount = stencils.Count;
        var topology    = new QuadTopology(vertexCount, faces);

        return(new SubdivisionMesh(0, topology, stencils));
    }
    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));
    }
예제 #8
0
 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]));
 }
예제 #9
0
    public ShaderResourceView Load(string name, DefaultMode defaultMode)
    {
        if (name == null)
        {
            if (defaultMode == DefaultMode.Bump)
            {
                return(defaultBumpTexture);
            }
            else
            {
                return(defaultStandardTexture);
            }
        }

        if (!cache.TryGetValue(name, out var textureView))
        {
            var imageFile = texturesDirectory.File(name + ".dds");
            textureView = textureCache.Get(imageFile);
            cache.Add(name, textureView);
        }

        return(textureView);
    }
 public static bool IsOcclusionDirectory(IArchiveDirectory dir)
 {
     return(dir.File("occluder-parameters.dat") != null ||
            dir.File("occlusion-infos.array") != null);
 }
    public static MaterialSetOption Load(IArchiveDirectory materialSetDirectory)
    {
        var settings = Persistance.Load <MultiMaterialSettings>(materialSetDirectory.File("material-settings.dat"));

        return(new MaterialSetOption(materialSetDirectory.Name, materialSetDirectory, settings));
    }
예제 #12
0
    public static ActorBehavior Load(ControllerManager controllerManager, IArchiveDirectory figureDir, ActorModel model)
    {
        InverterParameters inverterParameters = Persistance.Load <InverterParameters>(figureDir.File("inverter-parameters.dat"));

        return(new ActorBehavior(controllerManager, model, inverterParameters));
    }