private static void CreateUniqueName(this ShaderGroup group) { if (!group.HasUniqueName) { group.UniqueName = CreateUniqueName(group.Name, MainWindowPageViewModel.ShaderBoxResourcesFolderLocation, ""); } }
//private void SaveAs(ShaderGroup group, string name) //{ //} private void RaiseSaveShaderGroup(ShaderGroup group) { foreach (Shader shader in group.Shaders) { shader.Save(Workspace); } }
void AddGroup(GroupData groupData) { ShaderGroup graphGroup = new ShaderGroup(); graphGroup.userData = groupData; graphGroup.title = groupData.title; m_GraphView.AddElement(graphGroup); }
private void RaiseCloseShaderGroup(ShaderGroup group) { SetValue(group, false, () => { group.Save(Workspace); Workspace.Shaders.FirstOrDefault((s) => s.Path == group.GetProjectPath()).IsOpen = group.IsOpen; ShaderGroupsView.Refresh(); }, "IsOpen"); }
void AddGroup(GroupData groupData) { ShaderGroup graphGroup = new ShaderGroup(m_Graph); graphGroup.userData = groupData; graphGroup.title = groupData.title; graphGroup.SetPosition(new Rect(graphGroup.userData.position, Vector2.zero)); m_GraphView.AddElement(graphGroup); }
private void RefreshExplorerEvent(ShaderGroup shaderGroup) { if (shaderGroup != null) { foreach (Shader shader in shaderGroup.Shaders) { ShadersFlattened.Remove(shader); } } ShaderGroupsView.Refresh(); }
private void RaiseEditShaderGroup(ShaderGroup group) { ShaderGroupNotification notification = new ShaderGroupNotification(); notification.ShaderGroup = group.Copy(); notification.Title = "Edit Shader"; notification.Content = true; bool selectionNeedsUpdate = false; int selectedIndex = ShaderGroupsView.CurrentPosition; List <Shader> openItems = ShaderGroupsView.Cast <Shader>().ToList(); int originalCount = group.Shaders.Count; int startIndex = 0; if (openItems[selectedIndex].Group == group) { selectionNeedsUpdate = true; startIndex = openItems.IndexOf(group.Shaders[0]); } ShaderGroupRequest.Raise(notification, (returned) => { if (returned.Confirmed) { int flattenedIndex = ShadersFlattened.IndexOf(group.Shaders[0]); int index = _shaderStorage.ShaderGroups.IndexOf(group); _shaderStorage.ShaderGroups.Remove(group); _shaderStorage.ShaderGroups.Insert(index, notification.ShaderGroup); group.AnnotationShaderGroups.Clear(); group.IsBuilded = false; group.Shaders.ToList().ForEach((s) => ShadersFlattened.Remove(s)); for (int i = 0; i < notification.ShaderGroup.Shaders.Count; ++i) { ShadersFlattened.Insert(flattenedIndex + i, notification.ShaderGroup.Shaders[i]); } if (selectionNeedsUpdate) { selectedIndex = Math.Min(openItems.Count - 1, selectedIndex); if (startIndex + notification.ShaderGroup.Shaders.Count <= selectedIndex) { selectedIndex = startIndex + notification.ShaderGroup.Shaders.Count - 1; } ShaderGroupsView.MoveCurrentToPosition(selectedIndex); } } }); }
public static string GetProjectPath(this ShaderGroup shadergroup) { string path; if (shadergroup.ShaderGroupType == ShaderGroupType.SharedHeaders) { path = MainWindowPageViewModel.ShaderBoxSharedProject; } else { path = $"{MainWindowPageViewModel.ShaderBoxResourcesFolderLocation}{shadergroup.UniqueName}/{shadergroup.Name}.sbproj"; } return(path); }
private void UpdateShaderViewport() { if (ViewportHost != null) { if (SelectedShaderGroup != null && SelectedShaderGroup.IsBuilded) { string[] shaderLocations = new string[5]; foreach (Shader s in SelectedShaderGroup.Shaders) { if (s.ShaderType != ShaderType.Header) { shaderLocations[(int)s.ShaderType] = $"{MainWindowPageViewModel.ShaderBoxResourcesFolderLocation}{SelectedShaderGroup.UniqueName}/.cso/{s.GetShaderTarget().Substring(0, 2)}.cso"; } } bool isStandard = SelectedShaderGroup.ShaderGroupType == ShaderGroupType.Standard; if (isStandard) { ViewportHost.SetShaders(shaderLocations[0] ?? "", shaderLocations[1] ?? "", shaderLocations[2] ?? "", shaderLocations[3] ?? "", shaderLocations[4] ?? ""); ViewportHost.SetTopology((int)SelectedShaderGroup.Topology); ViewportHost.SetRasterizerState((int)SelectedShaderGroup.CullMode, (int)SelectedShaderGroup.FillMode); } else { ViewportHost.SetPPShader(shaderLocations[4] ?? ""); } _settedGroup = SelectedShaderGroup; foreach (AnnotationShaderGroup annotationShaderGroup in SelectedShaderGroup.AnnotationShaderGroups) { foreach (AnnotationGroup annotationGroup in annotationShaderGroup.Buffers) { foreach (AnnotationVariable annotationVariable in annotationGroup.AnnotationVariables) { annotationVariable.UpdateBuffer(false); } annotationGroup.MarshalBuffer(ViewportHost, isStandard); } } } ViewportHost.SetModel(SelectedModel?.Path ?? Workspace.Models[0].Path); ViewportHost.SetCameraOffset(CameraOffset); RaisePropertyChanged("SelectedModel"); } }
public static ShaderGroup Copy(this ShaderGroup group) { return(new ShaderGroup() { Name = group.Name, ShaderGroupType = group.ShaderGroupType, Topology = group.Topology, Description = group.Description, UniqueName = group.UniqueName, IsOpen = group.IsOpen, HasHullDomainShader = group.HasHullDomainShader, HasGeometryShader = group.HasGeometryShader, CullMode = group.CullMode, FillMode = group.FillMode, Shaders = new ObservableCollection <Shader>(group.Shaders) }); }
private void RaiseAddHeader(ShaderGroup group) { string name = "Header"; IEnumerable <string> headers = group.Shaders.Where((s) => s.ShaderType == ShaderType.Header).Select((s) => s.Name); int counter = 0; while (headers.Contains(name + ".hlsli")) { ++counter; name = "Header_" + counter.ToString("D3"); } Shader shader = new Shader(name + ".hlsli", ShaderType.Header); group.AddShader(shader); group.Save(Workspace); ShadersFlattened.Add(shader); }
private void RaiseMakeSharedHeader(Shader shader) { ShaderGroup originalGroup = shader.Group; shader.Group.Shaders.Remove(shader); string name = shader.Name.TrimEnd(".hlsli".ToArray()); string newName = shader.Name; IEnumerable <string> headers = _shaderStorage.ShaderGroups[0].Shaders.Select((s) => s.Name); int counter = 0; while (headers.Contains(newName)) { ++counter; newName = name + "_" + counter.ToString("D3") + ".hlsli"; } shader.Name = newName; if (!string.IsNullOrEmpty(shader.FileLocation)) { try { File.Copy(shader.FileLocation, PATH_TO_SHARED_FOLDER + name); File.Delete(shader.FileLocation); shader.FileLocation = PATH_TO_SHARED_FOLDER + name; } catch (Exception) { } } _shaderStorage.ShaderGroups[0].AddShader(shader); originalGroup.Save(Workspace); _shaderStorage.ShaderGroups[0].Save(Workspace); ShaderGroupsView.Refresh(); }
public static void Save(this ShaderGroup shadergroup, Workspace workspace) { shadergroup.CreateUniqueName(); string path = shadergroup.GetProjectPath(); if (workspace.Shaders.FirstOrDefault((s) => s.Path == path) == null) { workspace.Shaders.Add(new ShaderPath() { Path = path, IsOpen = true }); } path.EnsureFolder(); XmlSerializer serializer = new XmlSerializer(typeof(ShaderGroup)); using (Stream stream = File.Create(path)) { serializer.Serialize(stream, shadergroup); } }
public ShaderGroupWrapper_GTA5_pc(ShaderGroup shaderGroup) { this.shaderGroup = shaderGroup; }
public new void Read(BinaryReader br) { base.Read(br); // rage::rmcDrawableBase // rage::rmcDrawable // gtaDrawable var shaderGroupOffset = ResourceUtil.ReadOffset(br); var skeletonOffset = ResourceUtil.ReadOffset(br); Center = new Vector4(br); BoundsMin = new Vector4(br); BoundsMax = new Vector4(br); int levelOfDetailCount = 0; var modelOffsets = new uint[4]; for (int i = 0; i < 4; i++) { modelOffsets[i] = ResourceUtil.ReadOffset(br); if (modelOffsets[i] != 0) { levelOfDetailCount++; } } AbsoluteMax = new Vector4(br); Unk1 = br.ReadUInt32(); Neg1 = br.ReadUInt32(); Neg2 = br.ReadUInt32(); Neg3 = br.ReadUInt32(); Unk2 = br.ReadSingle(); Unk3 = br.ReadUInt32(); Unk4 = br.ReadUInt32(); Unk5 = br.ReadUInt32(); // Collection<LightAttrs> Unk6 = br.ReadUInt32(); Unk7 = br.ReadUInt32(); // The data follows: if (shaderGroupOffset != 0) { br.BaseStream.Seek(shaderGroupOffset, SeekOrigin.Begin); ShaderGroup = new ShaderGroup(br); } if (skeletonOffset != 0) { br.BaseStream.Seek(skeletonOffset, SeekOrigin.Begin); Skeleton = new Skeleton(br); } ModelCollection = new PtrCollection <Model> [levelOfDetailCount]; for (int i = 0; i < levelOfDetailCount; i++) { br.BaseStream.Seek(modelOffsets[i], SeekOrigin.Begin); ModelCollection[i] = new PtrCollection <Model>(br); } }
//finds all properties and headers and stores them in correct order private void CollectAllProperties() { //load display names from file if it exists MaterialProperty[] props = current.properties; Dictionary <string, string> labels = LoadDisplayNamesFromFile(); LoadLocales(); current.propertyDictionary = new Dictionary <string, ShaderProperty>(); shaderparts = new ShaderHeader(); //init top object that all Shader Objects are childs of Stack <ShaderGroup> headerStack = new Stack <ShaderGroup>(); //header stack. used to keep track if current header to parent new objects to headerStack.Push(shaderparts); //add top object as top object to stack headerStack.Push(shaderparts); //add top object a second time, because it get's popped with first actual header item footer = new List <ButtonData>(); //init footer list int headerCount = 0; Type materialPropertyDrawerType = typeof(UnityEditor.Editor).Assembly.GetType("UnityEditor.MaterialPropertyHandler"); MethodInfo getPropertyHandlerMethod = materialPropertyDrawerType.GetMethod("GetShaderPropertyHandler", BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static | BindingFlags.FlattenHierarchy); PropertyInfo drawerProperty = materialPropertyDrawerType.GetProperty("propertyDrawer"); Type materialToggleDrawerType = typeof(UnityEditor.Editor).Assembly.GetType("UnityEditor.MaterialToggleDrawer"); FieldInfo keyWordField = materialToggleDrawerType.GetField("keyword", BindingFlags.Instance | BindingFlags.NonPublic); for (int i = 0; i < props.Length; i++) { string displayName = props[i].displayName; if (locale != null) { foreach (string key in locale.GetAllKeys()) { if (displayName.Contains("locale::" + key)) { displayName = displayName.Replace("locale::" + key, locale.Get(key)); } } } displayName = Regex.Replace(displayName, @"''", "\""); if (labels.ContainsKey(props[i].name)) { displayName = labels[props[i].name]; } PropertyOptions options = ExtractExtraOptionsFromDisplayName(ref displayName); int offset = options.offset + headerCount; //Handle keywords object propertyHandler = getPropertyHandlerMethod.Invoke(null, new object[] { current.shader, props[i].name }); //if has custom drawer if (propertyHandler != null) { object propertyDrawer = drawerProperty.GetValue(propertyHandler, null); //if custom drawer exists if (propertyDrawer != null) { if (propertyDrawer.GetType().ToString() == "UnityEditor.MaterialToggleDrawer") { object keyword = keyWordField.GetValue(propertyDrawer); if (keyword != null) { foreach (Material m in current.materials) { if (m.GetFloat(props[i].name) == 1) { m.EnableKeyword((string)keyword); } else { m.DisableKeyword((string)keyword); } } } } } } ThryPropertyType type = GetPropertyType(props[i], options); switch (type) { case ThryPropertyType.header: headerStack.Pop(); break; case ThryPropertyType.header_start: offset = options.offset + ++headerCount; break; case ThryPropertyType.header_end: headerStack.Pop(); headerCount--; break; case ThryPropertyType.on_swap_to: on_swap_to_actions = options.actions; break; } ShaderProperty newPorperty = null; switch (type) { case ThryPropertyType.master_label: masterLabelText = displayName; break; case ThryPropertyType.footer: footer.Add(Parser.ParseToObject <ButtonData>(displayName)); break; case ThryPropertyType.header: case ThryPropertyType.header_start: ShaderHeader newHeader = new ShaderHeader(props[i], current.editor, displayName, offset, options); headerStack.Peek().addPart(newHeader); headerStack.Push(newHeader); break; case ThryPropertyType.group_start: ShaderGroup new_group = new ShaderGroup(options); headerStack.Peek().addPart(new_group); headerStack.Push(new_group); break; case ThryPropertyType.group_end: headerStack.Pop(); break; case ThryPropertyType.none: case ThryPropertyType.property: DrawingData.lastPropertyUsedCustomDrawer = false; current.editor.GetPropertyHeight(props[i]); bool forceOneLine = props[i].type == MaterialProperty.PropType.Vector && !DrawingData.lastPropertyUsedCustomDrawer; if (props[i].type == MaterialProperty.PropType.Texture) { newPorperty = new TextureProperty(props[i], displayName, offset, options, props[i].flags != MaterialProperty.PropFlags.NoScaleOffset, !DrawingData.lastPropertyUsedCustomDrawer); } else { newPorperty = new ShaderProperty(props[i], displayName, offset, options, forceOneLine); } break; case ThryPropertyType.lightmap_flags: newPorperty = new GIProperty(props[i], displayName, offset, options, false); break; case ThryPropertyType.dsgi: newPorperty = new DSGIProperty(props[i], displayName, offset, options, false); break; case ThryPropertyType.instancing: newPorperty = new InstancingProperty(props[i], displayName, offset, options, false); break; case ThryPropertyType.locale: newPorperty = new LocaleProperty(props[i], displayName, offset, options, false); break; } if (newPorperty != null) { if (current.propertyDictionary.ContainsKey(props[i].name)) { continue; } current.propertyDictionary.Add(props[i].name, newPorperty); if (type != ThryPropertyType.none) { headerStack.Peek().addPart(newPorperty); } } } }
public MainWindowPageViewModel() { Workspace workspace = null; try { if (File.Exists(ShaderBoxRootFileLocation)) { XmlSerializer serializer = new XmlSerializer(typeof(Workspace)); using (Stream stream = File.OpenRead(ShaderBoxRootFileLocation)) { workspace = ((Workspace)serializer.Deserialize(stream)); } } } catch (Exception) { } finally { if (workspace == null) { workspace = new Workspace(); } if (workspace.Shaders.Count == 0 || workspace.Shaders.FirstOrDefault((s) => s.Path == ShaderBoxSharedProject) == null) { workspace.Shaders.Insert(0, new ShaderPath() { Path = ShaderBoxSharedProject, IsOpen = true }); } if (workspace.Models.Count == 0 || workspace.Models.FirstOrDefault((s) => s.Path == ShaderBoxBuiltInModel) == null) { workspace.Models.Insert(0, new Model3DData() { Hash = 0, ImagePath = ShaderBoxBuiltInModelImage, IsBuiltIn = true, Name = "Cube.obj", Path = ShaderBoxBuiltInModel }); } if (!File.Exists(ShaderBoxSharedProject)) { ShaderGroup group = new ShaderGroup("Shared headers [../.Shared/]", ShaderGroupType.SharedHeaders) { UniqueName = ShaderBoxSharedFolderName, IsOpen = true }; Shader shader = new Shader("SB_Header.hlsli", ShaderType.Header, ShaderBoxBaseShaderLocation); shader.IsBuiltIn = true; group.AddShader(shader); group.Save(workspace); } ShaderStorageLinker shaderStorage = new ShaderStorageLinker(); XmlSerializer serializer = new XmlSerializer(typeof(ShaderGroup)); List <ShaderPath> toDelete = new List <ShaderPath>(); foreach (ShaderPath sPath in workspace.Shaders) { try { using (Stream stream = File.OpenRead(sPath.Path)) { ShaderGroup group = (ShaderGroup)serializer.Deserialize(stream); group.IsOpen = sPath.IsOpen; shaderStorage.ShaderGroups.Add(group); } } catch (Exception e) { MessageBox.Show($"Failed to load project: {sPath.Path}\nError: {e}", "Load error", MessageBoxButton.OK, MessageBoxImage.Error); toDelete.Add(sPath); } } workspace.Shaders = workspace.Shaders.Except(toDelete).ToList(); if (!File.Exists(ShaderBoxBaseShaderLocation)) { ShaderBoxSharedFolderLocation.EnsureFolder(); using (StreamWriter stream = new StreamWriter(ShaderBoxBaseShaderLocation)) { stream.Write(ShaderBoxBaseShaderContent); } } _workspace = workspace; _workspace.PropertyChanged += new PropertyChangedEventHandler(OnResourcePropertyChanged); App.Container.RegisterInstance(workspace); App.Container.RegisterInstance(shaderStorage); // Resolve cyclic dependency foreach (ShaderGroup shaderGroup in shaderStorage.ShaderGroups) { foreach (Shader shader in shaderGroup.Shaders) { shader.Group = shaderGroup; } foreach (AnnotationShaderGroup annotationShaderGroup in shaderGroup.AnnotationShaderGroups) { annotationShaderGroup.CreateUI(); } } } }
void SetGroupPosition(ShaderGroup groupNode) { var pos = groupNode.GetPosition(); groupNode.userData.position = new Vector2(pos.x, pos.y); }
//finds all properties and headers and stores them in correct order private void CollectAllProperties() { //load display names from file if it exists MaterialProperty[] props = current.properties; Dictionary <string, string> labels = LoadDisplayNamesFromFile(); LoadLocales(); current.propertyDictionary = new Dictionary <string, ShaderProperty>(); shaderparts = new ShaderHeader(); //init top object that all Shader Objects are childs of Stack <ShaderGroup> headerStack = new Stack <ShaderGroup>(); //header stack. used to keep track if current header to parent new objects to headerStack.Push(shaderparts); //add top object as top object to stack headerStack.Push(shaderparts); //add top object a second time, because it get's popped with first actual header item footer = new List <ButtonData>(); //init footer list int headerCount = 0; for (int i = 0; i < props.Length; i++) { string displayName = props[i].displayName; if (locale != null) { foreach (string key in locale.GetAllKeys()) { displayName = displayName.Replace("locale::" + key, locale.Get(key)); } } displayName = Regex.Replace(displayName, @"''", "\""); if (labels.ContainsKey(props[i].name)) { displayName = labels[props[i].name]; } PropertyOptions options = ExtractExtraOptionsFromDisplayName(ref displayName); int offset = options.offset + headerCount; ThryPropertyType type = GetPropertyType(props[i]); switch (type) { case ThryPropertyType.header: headerStack.Pop(); break; case ThryPropertyType.header_start: offset = options.offset + ++headerCount; break; case ThryPropertyType.header_end: headerStack.Pop(); headerCount--; break; } ShaderProperty newPorperty = null; switch (type) { case ThryPropertyType.master_label: masterLabelText = displayName; break; case ThryPropertyType.footer: footer.Add(Parser.ParseToObject <ButtonData>(displayName)); break; case ThryPropertyType.header: case ThryPropertyType.header_start: ShaderHeader newHeader = new ShaderHeader(props[i], current.editor, displayName, offset, options); headerStack.Peek().addPart(newHeader); headerStack.Push(newHeader); break; case ThryPropertyType.group_start: ShaderGroup new_group = new ShaderGroup(options); headerStack.Peek().addPart(new_group); headerStack.Push(new_group); break; case ThryPropertyType.group_end: headerStack.Pop(); break; case ThryPropertyType.none: case ThryPropertyType.property: DrawingData.lastPropertyUsedCustomDrawer = false; current.editor.GetPropertyHeight(props[i]); bool forceOneLine = props[i].type == MaterialProperty.PropType.Vector && !DrawingData.lastPropertyUsedCustomDrawer; if (props[i].type == MaterialProperty.PropType.Texture) { newPorperty = new TextureProperty(props[i], displayName, offset, options, props[i].flags != MaterialProperty.PropFlags.NoScaleOffset, !DrawingData.lastPropertyUsedCustomDrawer); } else { newPorperty = new ShaderProperty(props[i], displayName, offset, options, forceOneLine); } break; case ThryPropertyType.lightmap_flags: newPorperty = new GIProperty(props[i], displayName, offset, options, false); break; case ThryPropertyType.dsgi: newPorperty = new DSGIProperty(props[i], displayName, offset, options, false); break; case ThryPropertyType.instancing: newPorperty = new InstancingProperty(props[i], displayName, offset, options, false); break; case ThryPropertyType.locale: newPorperty = new LocaleProperty(props[i], displayName, offset, options, false); break; } if (newPorperty != null) { current.propertyDictionary.Add(props[i].name, newPorperty); if (type != ThryPropertyType.none) { headerStack.Peek().addPart(newPorperty); } } } }
private Drawable TryConvertDrawable(FbxDocument fdoc, string name) { var rootnodes = fdoc.GetSceneNodes(); var mlists = new List <List <FbxModel> >(); var mlistall = new List <FbxModel>(); foreach (var node in rootnodes) { if (node.Name == "Model") { var mlist = TryConvertModels(node); //flatten any models structure with depth >2 if (mlist != null) { mlists.Add(mlist); mlistall.AddRange(mlist); } } } var mlHigh = new List <DrawableModel>(); var mlMed = new List <DrawableModel>(); var mlLow = new List <DrawableModel>(); var mlVlow = new List <DrawableModel>(); var mlUnks = new List <DrawableModel>(); var mlAll = new List <DrawableModel>(); foreach (var m in mlistall) { var mnl = m.Name.ToLowerInvariant(); if (mnl.EndsWith("_vlow")) { mlVlow.Add(m.Model); } else if (mnl.EndsWith("_low")) { mlLow.Add(m.Model); } else if (mnl.EndsWith("_med")) { mlMed.Add(m.Model); } else if (mnl.EndsWith("_high")) { mlHigh.Add(m.Model); } else { mlUnks.Add(m.Model); } } if (mlHigh.Count == 0)//mlUnks could be embedded collisions... ignore for now { mlHigh.AddRange(mlUnks); } mlAll.AddRange(mlHigh); mlAll.AddRange(mlMed); mlAll.AddRange(mlLow); mlAll.AddRange(mlVlow); var allVerts = new List <Vector3>(); var bbMin = new Vector3(float.MaxValue); var bbMax = new Vector3(float.MinValue); var bsCen = Vector3.Zero; var bsRad = 0.0f; foreach (var m in mlistall) { if (m?.Model?.Geometries == null) { continue; } foreach (var g in m.Model.Geometries) { var vb = g.VertexData.VertexBytes; var vs = g.VertexData.VertexStride; var vc = g.VertexData.VertexCount; for (int i = 0; i < vc; i++) { var vp = MetaTypes.ConvertData <Vector3>(vb, i * vs);//position offset should always be 0! allVerts.Add(vp); bbMin = Vector3.Min(bbMin, vp); bbMax = Vector3.Max(bbMax, vp); //bsCen += vp; } } } if (allVerts.Count > 0) { //bsCen = bsCen / allVerts.Count; bsCen = (bbMin + bbMax) * 0.5f; foreach (var vp in allVerts) { bsRad = Math.Max(bsRad, (vp - bsCen).Length()); } } var sgrp = new ShaderGroup(); var slist = new List <ShaderFX>(); var smapp = new List <ushort>(); foreach (var m in mlAll) { if (m?.Geometries == null) { continue; } smapp.Clear(); foreach (var g in m.Geometries) { smapp.Add((ushort)slist.Count); slist.Add(g.Shader); } m.ShaderMapping = smapp.ToArray();//TODO: re-use shaders!! } sgrp.Shaders = new ResourcePointerArray64 <ShaderFX>(); sgrp.Shaders.data_items = slist.ToArray(); sgrp.ShadersCount1 = (ushort)slist.Count; sgrp.ShadersCount2 = (ushort)slist.Count; sgrp.VFT = 1080113376; //is this needed? sgrp.Unknown_4h = 1; sgrp.Unknown_30h = (uint)(8 + slist.Count * 3); //WTF is this? var d = new Drawable(); d.Name = name + ".#dr"; d.ShaderGroup = sgrp; d.BoundingCenter = bsCen; d.BoundingSphereRadius = bsRad; d.BoundingBoxMin = bbMin; d.BoundingBoxMax = bbMax; d.LodDistHigh = 9998;//lod dist defaults d.LodDistMed = 9998; d.LodDistLow = 9998; d.LodDistVlow = 9998; d.Unknown_9Ah = 33;//WTF is this??? d.FileVFT = 1079446584; d.FileUnknown = 1; d.DrawableModels = new DrawableModelsBlock(); if (mlHigh.Count > 0) { d.DrawableModels.High = mlHigh.ToArray(); d.FlagsHigh = 1;//what flags should be used?? } if (mlMed.Count > 0) { d.DrawableModels.Med = mlMed.ToArray(); d.LodDistHigh = bsRad * 2.0f; //when med models present, generate a high lod dist.. d.FlagsMed = 1; } if (mlLow.Count > 0) { d.DrawableModels.Low = mlLow.ToArray(); d.LodDistMed = bsRad * 8.0f; //when low models present, generate a med lod dist.. d.FlagsLow = 1; } if (mlVlow.Count > 0) { d.DrawableModels.VLow = mlVlow.ToArray(); d.LodDistLow = bsRad * 32.0f; //when vlow models present, generate a low lod dist.. d.FlagsVlow = 1; } d.BuildRenderMasks(); d.LightAttributes = new ResourceSimpleList64_s <LightAttributes_s>(); //todo: light attributes? return(d); }
private void RaiseNewShader() { if (IsValid) { if (_isInEditMode) { if ((_originalHasHullDomain && HasHullDomainShader == false) ||// Hull and domain will get deleted (_originalHasGeometry && HasGeometryShader == false)) // Geometry will get deleted { MessageBoxResult result = MessageBox.Show("The new settings will result in permanently losing shaders\n\nDo you want to continue", "Warning", MessageBoxButton.YesNo, MessageBoxImage.Warning); if (result != MessageBoxResult.Yes) { return; } } } ShaderGroup sg = _notification.ShaderGroup; Shader shader; if (sg.ShaderGroupType == ShaderGroupType.Standard) { if (HasHullDomainShader) { shader = sg.Shaders.FirstOrDefault((s) => s.ShaderType == ShaderType.Hull); if (shader == null) { sg.AddShader(new Shader("hs.hlsl", ShaderType.Hull)); sg.AddShader(new Shader("ds.hlsl", ShaderType.Domain)); } } else if (_isInEditMode) { shader = sg.Shaders.FirstOrDefault((s) => s.ShaderType == ShaderType.Hull); shader?.Delete(); sg.Shaders.Remove(shader); shader = sg.Shaders.FirstOrDefault((s) => s.ShaderType == ShaderType.Domain); shader?.Delete(); sg.Shaders.Remove(shader); } if (HasGeometryShader) { shader = sg.Shaders.FirstOrDefault((s) => s.ShaderType == ShaderType.Geometry); if (shader == null) { sg.AddShader(new Shader("gs.hlsl", ShaderType.Geometry)); } } else if (_isInEditMode) { shader = sg.Shaders.FirstOrDefault((s) => s.ShaderType == ShaderType.Geometry); shader?.Delete(); sg.Shaders.Remove(shader); } shader = sg.Shaders.FirstOrDefault((s) => s.ShaderType == ShaderType.Vertex); if (shader == null) { sg.AddShader(new Shader("vs.hlsl", ShaderType.Vertex)); } } else if (_isInEditMode) { shader = sg.Shaders.FirstOrDefault((s) => s.ShaderType == ShaderType.Vertex); shader?.Delete(); sg.Shaders.Remove(shader); shader = sg.Shaders.FirstOrDefault((s) => s.ShaderType == ShaderType.Hull); shader?.Delete(); sg.Shaders.Remove(shader); shader = sg.Shaders.FirstOrDefault((s) => s.ShaderType == ShaderType.Domain); shader?.Delete(); sg.Shaders.Remove(shader); shader = sg.Shaders.FirstOrDefault((s) => s.ShaderType == ShaderType.Geometry); shader?.Delete(); sg.Shaders.Remove(shader); } shader = sg.Shaders.FirstOrDefault((s) => s.ShaderType == ShaderType.Pixel); if (shader == null) { sg.AddShader(new Shader("ps.hlsl", ShaderType.Pixel)); } if (_isInEditMode) { foreach (Shader s in sg.Shaders) { s.Group = sg; } } _notification.Confirmed = true; FinishInteraction(); } }