示例#1
0
        private void LoadModelNow(IResource resource)
        {
            if (resource.Equals(CurrentResource))
            {
                return;
            }
            CurrentResource = null;
            var texturePaths = new[]
            {
                textureLoader.GetTexturePathFromModel(resource.Path),
                new FilePath("resources/textures/models"),
                new FilePath("resources/textures/worlds"),
            };

            geometryBuffers = new ClumpBuffers(diContainer, resource);
            AddDisposable(geometryBuffers);

            foreach (var oldTexture in materials.Select(m => m.MainTexture.Texture))
            {
                imGuiRenderer.RemoveImGuiBinding(oldTexture);
            }

            materials = new ModelStandardMaterial[geometryBuffers.SubMeshes.Count];
            foreach (var(rwMaterial, index) in geometryBuffers.SubMeshes.Select(s => s.Material).Indexed())
            {
                var material = materials[index] = new ModelStandardMaterial(diContainer);
                (material.MainTexture.Texture, material.Sampler.Sampler) = textureLoader.LoadTexture(texturePaths, rwMaterial);
                material.LinkTransformsTo(camera);
                material.World.Ref    = Matrix4x4.Identity;
                material.Uniforms.Ref = ModelStandardMaterialUniforms.Default;
                material.Uniforms.Ref.vertexColorFactor = 0.0f; // they seem to be set to some gray for models?
                material.Uniforms.Ref.tint = rwMaterial.color.ToFColor();
                AddDisposable(material);
            }
            modelMaterialEdit.Materials = materials;

            skeletonRenderer = null;
            if (geometryBuffers.Skin != null)
            {
                var skeleton = new Skeleton(geometryBuffers.Skin);
                skeletonRenderer = new DebugSkeletonRenderer(diContainer.ExtendedWith(camera, locationBuffer), geometryBuffers, skeleton);
                AddDisposable(skeletonRenderer);
            }

            collider = geometryBuffers.RWGeometry.FindChildById(zzio.rwbs.SectionId.CollisionPLG, true) == null
                ? null
                : new GeometryTreeCollider(geometryBuffers.RWGeometry, location: null);

            controls.ResetView();
            HighlightSplit(-1);
            fbArea.IsDirty  = true;
            CurrentResource = resource;
            Window.Title    = $"Model Viewer - {resource.Path.ToPOSIXString()}";
        }