Beispiel #1
0
            public Model(ITagContainer diContainer, zzio.scn.Model sceneModel, Behavior?sceneBehavior)
            {
                this.diContainer = diContainer;
                var textureLoader    = diContainer.GetTag <IAssetLoader <Texture> >();
                var textureBasePaths = new[]
                {
                    new FilePath("resources/textures/models"),
                    new FilePath("resources/textures/worlds")
                };
                var camera = diContainer.GetTag <Camera>();

                SceneModel             = sceneModel;
                SceneBehaviour         = sceneBehavior;
                locationRange          = diContainer.GetTag <LocationBuffer>().Add(Location);
                Location.LocalPosition = sceneModel.pos;
                Location.LocalRotation = sceneModel.rot.ToZZRotation();

                var clumpLoader = diContainer.GetTag <IAssetLoader <ClumpBuffers> >();

                clumpBuffers = clumpLoader.Load(new FilePath("resources/models/models").Combine(sceneModel.filename + ".dff"));
                materials    = clumpBuffers.SubMeshes.Select(subMesh =>
                {
                    var rwMaterial = subMesh.Material;
                    var material   = new ModelStandardMaterial(diContainer);
                    (material.MainTexture.Texture, material.Sampler.Sampler) = textureLoader.LoadTexture(textureBasePaths, rwMaterial);
                    material.LinkTransformsTo(camera);
                    material.World.BufferRange = locationRange;
                    material.Uniforms.Ref      = ModelStandardMaterialUniforms.Default;
                    material.Uniforms.Ref.vertexColorFactor = 0.0f;
                    material.Uniforms.Ref.tint = rwMaterial.color.ToFColor() * sceneModel.color;
                    return(material);
                }).ToArray();
            }
Beispiel #2
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()}";
        }