private void buttonImportExcel_Click(object sender, EventArgs e) { var ofd = new OpenFileDialog(); ofd.Filter = "Excel Workbook|*.xlsx"; if (ofd.ShowDialog() != DialogResult.OK) { return; } var fileName = new FileInfo(ofd.FileName); using (var excelDoc = new ExcelPackage(fileName)) { var dialogs = ImportWorkSheet(excelDoc, "Dialogs").ToArray(); //Clear all actions from the asset LoadedAsset.RemoveDialogueActions(LoadedAsset.GetAllDialogueActions()); foreach (var d in dialogs) { LoadedAsset.AddDialogAction(d); } } RefreshDialogs(); }
private void buttonImportTxt_Click(object sender, EventArgs e) { var ofd = new OpenFileDialog(); ofd.Filter = "Text File|*.txt"; if (ofd.ShowDialog() != DialogResult.OK) { return; } var fileName = new FileInfo(ofd.FileName); File.SetAttributes(fileName.DirectoryName, FileAttributes.Normal); LoadedAsset.RemoveDialogueActions(LoadedAsset.GetAllDialogueActions()); int stateCounter = 0; var lines = File.ReadAllLines(fileName.FullName); var totalSize = lines.Length; foreach (var line in lines) { var add = GenerateDialogueActionFromLine(line, totalSize, ref stateCounter); LoadedAsset.AddDialogAction(add); } RefreshDialogs(); }
private void dataGridViewReactiveActions_RowEnter(object sender, DataGridViewCellEventArgs e) { var reaction = ((ObjectView <ActionRuleDTO>)dataGridViewReactiveActions.Rows[e.RowIndex].DataBoundItem).Object; selectedActionId = reaction.Id; var ra = LoadedAsset.GetActionRule(selectedActionId); UpdateConditions(ra); }
private void buttonEditGoal_Click(object sender, EventArgs e) { var selectedGoal = EditorTools.GetSelectedDtoFromTable <GoalDTO>(dataGridViewGoals); if (selectedGoal != null) { new AddOrEditGoalForm(LoadedAsset, selectedGoal).ShowDialog(); dataGridViewGoals.DataSource = new BindingListView <GoalDTO>(LoadedAsset.GetAllGoals().ToList()); } }
private void influenceRules_Click(object sender, EventArgs e) { var selectedRule = EditorTools.GetSelectedDtoFromTable <SocialExchangeDTO>(gridSocialExchanges); var newSE = new SocialExchange(selectedRule); var diag = new InfluenceRuleInspector(LoadedAsset, newSE); diag.ShowDialog(this); LoadedAsset.UpdateSocialExchange(newSE.ToDTO); _socialExchangeList.DataSource = LoadedAsset.GetAllSocialExchanges().ToList(); SetModified(); }
private void buttonRemoveAttRule_Click(object sender, EventArgs e) { var index = dataGridViewEventTemplates.SelectedRows[0].Index; var actionTemp = LoadedAsset.GetAllActions().ElementAt(index).Item1; LoadedAsset.RemoveAction(actionTemp); SetModified(); RefreshEventList(); }
private void buttonDuplicateAttRule_Click(object sender, EventArgs e) { var r = EditorTools.GetSelectedDtoFromTable <AttributionRuleDTO>(this.dataGridViewAttributionRules); if (r != null) { var newRule = LoadedAsset.AddAttributionRule(r); attributionRules.DataSource = LoadedAsset.GetAttributionRules().ToList(); EditorTools.HighlightItemInGrid <AttributionRuleDTO>(dataGridViewAttributionRules, newRule.Id); SetModified(); } }
private void auxAddOrUpdateItem(AttributionRuleDTO item) { var diag = new AddOrEditAttributionRuleForm(LoadedAsset, item); diag.ShowDialog(this); if (diag.UpdatedGuid != Guid.Empty) { attributionRules.DataSource = LoadedAsset.GetAttributionRules().ToList(); EditorTools.HighlightItemInGrid <AttributionRuleDTO>(dataGridViewAttributionRules, diag.UpdatedGuid); } SetModified(); }
private void buttonDuplicateReaction_Click(object sender, EventArgs e) { if (dataGridViewReactiveActions.SelectedRows.Count == 1) { var a = ((ObjectView <ActionRuleDTO>)dataGridViewReactiveActions.SelectedRows[0].DataBoundItem).Object; var duplicateAction = CloneHelper.Clone(a); LoadedAsset.AddActionRule(duplicateAction); actionRules.DataSource = LoadedAsset.GetAllActionRules().ToList(); actionRules.Refresh(); SetModified(); } }
private void buttonRemove_Click(object sender, EventArgs e) { IList <GoalDTO> goalsToRemove = new List <GoalDTO>(); for (int i = 0; i < dataGridViewGoals.SelectedRows.Count; i++) { var goal = ((ObjectView <GoalDTO>)dataGridViewGoals.SelectedRows[i].DataBoundItem).Object; goalsToRemove.Add(goal); } LoadedAsset.RemoveGoals(goalsToRemove); dataGridViewGoals.DataSource = new BindingListView <GoalDTO>(LoadedAsset.GetAllGoals().ToList()); }
private void addEffectDTO_Click(object sender, EventArgs e) { var index = dataGridViewEventTemplates.SelectedRows[0].Index; var eventTemp = LoadedAsset.GetAllActions().ElementAt(index); var ef = new AddorEditEffect(LoadedAsset, eventTemp.Item1, -1, new EffectDTO()); ef.ShowDialog(this); SetModified(); dataGridViewEventTemplates_SelectionChanged(sender, e); RefreshEventList(); }
private void displayGraph_Click(object sender, EventArgs e) { Dictionary <string, List <string> > states = new Dictionary <string, List <string> >(); foreach (var d in LoadedAsset.GetAllDialogueActions()) { if (states.ContainsKey(d.CurrentState)) { states[d.CurrentState].Add(d.NextState); } else { states.Add(d.CurrentState, new List <string>() { d.NextState }); } } string writer = ""; writer += "digraph { \n"; writer += "node[fontsize=10, labelloc = \"t\", labeljust = \"l\"]; \n"; foreach (var s in states.Keys) { foreach (var ns in states[s]) { if (s != "-") { writer += s + "->" + ns + "\n"; } else if (ns != "-") { writer += "Any" + "->" + ns + "\n"; } else { writer += "Any" + "->" + "Any" + "\n"; } } } writer += "}"; Bitmap bit = Run(writer); var image = new ImageForm(bit); image.Show(); // Graphics.DrawImage(bit, 60, 10); }
private void buttonDuplicateSE_Click(object sender, EventArgs e) { var r = EditorTools.GetSelectedDtoFromTable <SocialExchangeDTO>( this.gridSocialExchanges); if (r != null) { r.Id = Guid.Empty; var newRuleId = LoadedAsset.AddOrUpdateExchange(r); _socialExchangeList.DataSource = LoadedAsset.GetAllSocialExchanges().ToList(); EditorTools.HighlightItemInGrid <SocialExchangeDTO>(gridSocialExchanges, newRuleId); } }
private void ConditionSetView_OnDataChanged() { var selectedRule = EditorTools.GetSelectedDtoFromTable <AttributionRuleDTO>(dataGridViewAttributionRules); if (selectedRule == null) { return; } selectedRule.Conditions = conditions.GetData(); LoadedAsset.UpdateAttributionRule(selectedRule); SetModified(); }
private void ConditionSetView_OnDataChanged() { var selectedRule = EditorTools.GetSelectedDtoFromTable <SocialExchangeDTO>(gridSocialExchanges); if (selectedRule == null) { return; } selectedRule.StartingConditions = conditions.GetData(); LoadedAsset.AddOrUpdateExchange(selectedRule); SetModified(); }
private void buttonEditAttRule_Click(object sender, EventArgs e) { var index = dataGridViewEventTemplates.SelectedRows[0].Index; var actionTemp = LoadedAsset.GetAllActions().ElementAt(index).Item1; var priority = LoadedAsset.GetAllActions().ElementAt(index).Item2; var ev = new AddOrEditActionTemplateForm(LoadedAsset, actionTemp, priority); ev.ShowDialog(this); SetModified(); RefreshEventList(); }
/// <summary> /// 加载到缓存 /// </summary> void AddToCache(string assetName, UnityEngine.Object obj) { //TODO: image.sprite = AssetBundleManager.Instance.LoadAsset<Sprite>("assets/test/3/3.png"); //像这种不依赖GameObject的还不能做到自己清除内存,因为挂不上BundleGameObject脚本 if (loadedAssetBundleDic.ContainsKey(assetName)) { loadedAssetBundleDic[assetName].referenceCount++; } else { LoadedAsset asset = new LoadedAsset(obj); loadedAssetBundleDic.Add(assetName, asset); } }
private void auxAddOrUpdateItem(DialogueStateActionDTO item) { var diag = new AddOrEditDialogueActionForm(LoadedAsset, item); diag.ShowDialog(this); if (diag.UpdatedGuid != Guid.Empty) { _dialogs.DataSource = LoadedAsset.GetAllDialogueActions().ToList(); EditorTools.HighlightItemInGrid <DialogueStateActionDTO> (dataGridViewDialogueActions, diag.UpdatedGuid); } SetModified(); }
/// <inheritdoc /> protected override void SetThumbnailParameters() { if (LoadedAsset.ViewDimension == TextureDimension.TextureCube) { BackgroundTexture = LoadedAsset.ToTextureView(new TextureViewDescription { ArraySlice = 0, Type = ViewType.ArrayBand }); } // TODO also handle Texture1D and Texture3D else { BackgroundTexture = LoadedAsset; } }
private void buttonEditReaction_Click(object sender, EventArgs e) { if (dataGridViewReactiveActions.SelectedRows.Count == 1) { var selectedReaction = ((ObjectView <ActionRuleDTO>)dataGridViewReactiveActions. SelectedRows[0].DataBoundItem).Object; new AddOrEditReactionForm(LoadedAsset, selectedReaction).ShowDialog(); actionRules.DataSource = LoadedAsset.GetAllActionRules().ToList(); actionRules.Refresh(); SetModified(); } }
private void button1_Click(object sender, EventArgs e) // Duplicate Effect { var index = dataGridViewEventTemplates.SelectedRows[0].Index; var eventTemp = LoadedAsset.GetAllActions().ElementAt(index).Item1; var index2 = dataGridViewEffects.SelectedRows[0].Index; var effect = LoadedAsset.GetAllEventEffects()[eventTemp].ElementAt(index2); LoadedAsset.AddActionEffect(eventTemp, effect.ToDTO()); SetModified(); dataGridViewEventTemplates_SelectionChanged(sender, e); }
private void buttonRemoveDialogueAction_Click(object sender, EventArgs e) { IList <Guid> itemsToRemove = new List <Guid>(); for (int i = 0; i < dataGridViewDialogueActions.SelectedRows.Count; i++) { var item = ((ObjectView <DialogueStateActionDTO>)dataGridViewDialogueActions.SelectedRows[i] .DataBoundItem).Object; itemsToRemove.Add(item.Id); } LoadedAsset.RemoveDialogueActions(itemsToRemove); RefreshDialogs(); this.SetModified(); }
private void RefreshDialogs() { _dialogs.DataSource = LoadedAsset.GetAllDialogueActions().ToList(); EditorTools.HideColumns(dataGridViewDialogueActions, new[] { PropertyUtil.GetPropertyName <DialogueStateActionDTO>(d => d.Id), PropertyUtil.GetPropertyName <DialogueStateActionDTO>(d => d.UtteranceId), } ); EditorTools.HideColumns(dataGridViewCharacters, new[] { PropertyUtil.GetPropertyName <CharacterSourceDTO>(s => s.Source), } ); }
private void buttonValidate_Click(object sender, EventArgs e) { var dfsearch = new DFSearch <string>(state => LoadedAsset.GetDialogueActionsByState(state).Select(dto => dto.NextState)); dfsearch.InitializeSearch(IATConsts.INITIAL_DIALOGUE_STATE); dfsearch.FullSearch(); int unreachableStatesCount = 0; int totalStates = 0; string unreachableStatesDescription = "The following Dialogue States are not reachable: \n["; foreach (var dAction in LoadedAsset.GetAllDialogueActions().GroupBy(da => da.CurrentState) .Select(group => group.First())) { totalStates++; if (dfsearch.Closed.SearchInClosed(new NodeRecord <string>() { node = dAction.CurrentState.ToString() }) == null) { unreachableStatesCount++; unreachableStatesDescription += dAction.CurrentState + ", "; } } unreachableStatesDescription = unreachableStatesDescription.Remove(unreachableStatesDescription.Length - 2); unreachableStatesDescription += "]"; string validationMessage; if (unreachableStatesCount > 0) { validationMessage = "Reachability: " + (totalStates - unreachableStatesCount) * 100 / totalStates + "%\n" + unreachableStatesDescription; } else { validationMessage = "All Dialogue States are reachable!"; } //get the dead ends validationMessage += "\n\nEnd States:\n[" + string.Join(",", dfsearch.End.ToArray()) + "]"; MessageBox.Show(validationMessage); }
private void buttonRemoveReaction_Click(object sender, EventArgs e) { var ids = dataGridViewReactiveActions.SelectedRows.Cast <DataGridViewRow>() .Select(r => ((ObjectView <ActionRuleDTO>)r.DataBoundItem).Object.Id).ToList(); LoadedAsset.RemoveActionRules(ids); var rules = LoadedAsset.GetAllActionRules().ToList(); actionRules.DataSource = rules; actionRules.Refresh(); SetModified(); if (rules == null || rules.Count == 0) { UpdateConditions(null); } }
private void buttonRemoveAttRule_Click(object sender, EventArgs e) { var selRows = dataGridViewAttributionRules.SelectedRows; if (selRows.Count == 0) { return; } foreach (var r in selRows.Cast <DataGridViewRow>()) { var dto = ((ObjectView <AttributionRuleDTO>)r.DataBoundItem).Object; LoadedAsset.RemoveAttributionRuleById(dto.Id); } attributionRules.DataSource = LoadedAsset.GetAttributionRules().ToList(); EditorTools.HighlightItemInGrid <AttributionRuleDTO>(dataGridViewAttributionRules, Guid.Empty); SetModified(); }
private void buttonRemoveSE_Click(object sender, EventArgs e) { var selRows = gridSocialExchanges.SelectedRows; if (selRows.Count == 0) { return; } foreach (var r in selRows.Cast <DataGridViewRow>()) { var dto = ((ObjectView <SocialExchangeDTO>)r.DataBoundItem).Object; LoadedAsset.RemoveSocialExchange(dto.Id); } _socialExchangeList.DataSource = LoadedAsset.GetAllSocialExchanges().ToList(); EditorTools.HighlightItemInGrid <SocialExchangeDTO>(gridSocialExchanges, Guid.Empty); SetModified(); }
private void buttonExportExcel_Click(object sender, EventArgs e) { var sfd = new SaveFileDialog(); sfd.Filter = "Excel Workbook|*.xlsx"; if (sfd.ShowDialog() != DialogResult.OK) { return; } var fileName = new FileInfo(sfd.FileName); using (var excelDoc = new ExcelPackage()) { ExportWorkSheet(excelDoc, "Dialogs", LoadedAsset.GetAllDialogueActions()); excelDoc.SaveAs(fileName); } }
protected override void OnAssetDataLoaded(SocialImportanceAsset asset) { attributionRules = new BindingListView <AttributionRuleDTO>((IList)null); dataGridViewAttributionRules.DataSource = this.attributionRules; _attRuleConditionSetEditor.View = conditions; conditions = new ConditionSetView(); _attRuleConditionSetEditor.View = conditions; conditions.OnDataChanged += ConditionSetView_OnDataChanged; attributionRules.DataSource = LoadedAsset.GetAttributionRules().ToList(); EditorTools.HideColumns(dataGridViewAttributionRules, new[] { PropertyUtil.GetPropertyName <AttributionRuleDTO>(o => o.Id), PropertyUtil.GetPropertyName <AttributionRuleDTO>(o => o.Conditions) }); _wasModified = false; }
private void auxAddOrUpdateItem(SocialExchangeDTO item) { var diag = new AddSocialExchange(LoadedAsset, item); diag.ShowDialog(this); if (diag.UpdatedGuid != Guid.Empty) { // _socialExchangeList.DataSource = LoadedAsset.GetAllSocialExchanges().ToList(); this._socialExchangeList.DataSource = LoadedAsset.GetAllSocialExchanges().ToList(); EditorTools.HighlightItemInGrid <SocialExchangeDTO> (gridSocialExchanges, diag.UpdatedGuid); } SetModified(); }
public override object Load(LoadedAsset asset) { if (!File.Exists(asset.FilePath)) { return materials; } StreamReader reader = new StreamReader(asset.Data); string line; while ((line = reader.ReadLine()) != null) { string[] tokens = line.Split(' '); tokens = RemoveEmptyStrings(tokens); if (tokens.Length == 0 || tokens[0] == "#") { } else if (tokens[0] == "newmtl") { string name = tokens[1]; materials.Add(new Material()); materials[materials.Count - 1].SetName(name); } else if (tokens[0] == "Ka") // ambient color { string x_str = tokens[1]; string y_str = tokens[2]; string z_str = tokens[3]; float x, y, z; x = float.Parse(x_str); y = float.Parse(y_str); z = float.Parse(z_str); Vector4f color = new Vector4f(x, y, z, 1.0f); // materials[materials.Count - 1].SetValue(Material.COLOR_AMBIENT, color); } else if (tokens[0] == "Kd") // ambient color { string x_str = tokens[1]; string y_str = tokens[2]; string z_str = tokens[3]; float x, y, z; x = float.Parse(x_str); y = float.Parse(y_str); z = float.Parse(z_str); Vector4f color = new Vector4f(x, y, z, 1.0f); materials[materials.Count - 1].SetValue(Material.COLOR_DIFFUSE, color); } else if (tokens[0] == "Ks") // ambient color { string x_str = tokens[1]; string y_str = tokens[2]; string z_str = tokens[3]; float x, y, z; x = float.Parse(x_str); y = float.Parse(y_str); z = float.Parse(z_str); Vector4f color = new Vector4f(x, y, z, 1.0f); materials[materials.Count - 1].SetValue(Material.COLOR_SPECULAR, color); } else if (tokens[0] == "Ns") // ambient color { string spec = tokens[1]; float spec_f = float.Parse(spec); materials[materials.Count - 1].SetValue(Material.SHININESS, spec_f / 1000.0f); } else if (tokens[0].ToLower() == "map_kd") // diffuse map { string texName = tokens[tokens.Length - 1]; string parentPath = System.IO.Directory.GetParent(asset.FilePath).ToString(); string texPath = parentPath + "\\" + texName; if (File.Exists(texPath)) { Texture tex = AssetManager.LoadTexture(texPath); materials[materials.Count - 1].SetValue(Material.TEXTURE_DIFFUSE, tex); } else if (File.Exists(texName)) { Texture tex = AssetManager.LoadTexture(texName); materials[materials.Count - 1].SetValue(Material.TEXTURE_DIFFUSE, tex); } } else if (tokens[0].ToLower() == "map_bump") // normal map { string texName = tokens[tokens.Length - 1]; string parentPath = System.IO.Directory.GetParent(asset.FilePath).ToString(); string texPath = parentPath + "\\" + texName; if (File.Exists(texPath)) { Texture tex = AssetManager.LoadTexture(texPath); materials[materials.Count - 1].SetValue(Material.TEXTURE_NORMAL, tex); } else if (File.Exists(texName)) { Texture tex = AssetManager.LoadTexture(texName); materials[materials.Count - 1].SetValue(Material.TEXTURE_NORMAL, tex); } } } reader.Close(); return materials; }
public override object Load(LoadedAsset asset) { XmlReader xmlReader = XmlReader.Create(asset.Data); while (xmlReader.Read()) { if (xmlReader.NodeType == XmlNodeType.Element) { if (xmlReader.Name == "bone") { string name = xmlReader.GetAttribute("name"); boneIdx = int.Parse(xmlReader.GetAttribute("id")); skeleton.AddBone(new Bone(name)); } else if (xmlReader.Name == "position") { float x = float.Parse(xmlReader.GetAttribute("x")); float y = float.Parse(xmlReader.GetAttribute("y")); float z = float.Parse(xmlReader.GetAttribute("z")); Vector3f vec = new Vector3f(x, y, z); skeleton.GetBone(boneIdx).SetBindTranslation(vec); } else if (xmlReader.Name == "rotation") { float angle = float.Parse(xmlReader.GetAttribute("angle")); bindAngle = angle; } else if (xmlReader.Name == "boneparent") { string parent = xmlReader.GetAttribute("parent"); string child = xmlReader.GetAttribute("bone"); Bone parentBone = null; for (int i = 0; i < skeleton.GetNumBones(); i++) if (skeleton.GetBone(i).Name == parent) parentBone = skeleton.GetBone(i); for (int i = 0; i < skeleton.GetNumBones(); i++) { if (skeleton.GetBone(i).Name == child) { Bone b = skeleton.GetBone(i); parentBone.AddChild(b); } } } else if (xmlReader.Name == "track") { string bone = xmlReader.GetAttribute("bone"); keyframeBoneName = bone; Bone b = skeleton.GetBone(keyframeBoneName); if (b != null) skeleton.GetAnimations()[skeleton.GetAnimations().Count - 1].AddTrack(new AnimationTrack(b)); } else if (xmlReader.Name == "translate") { float x = float.Parse(xmlReader.GetAttribute("x")); float y = float.Parse(xmlReader.GetAttribute("y")); float z = float.Parse(xmlReader.GetAttribute("z")); Vector3f vec = new Vector3f(x, y, z); keyframeBoneTrans = vec; } else if (xmlReader.Name == "rotate") { float angle = float.Parse(xmlReader.GetAttribute("angle")); keyframeBoneAngle = angle; } else if (xmlReader.Name == "axis") { float x = float.Parse(xmlReader.GetAttribute("x")); float y = float.Parse(xmlReader.GetAttribute("y")); float z = float.Parse(xmlReader.GetAttribute("z")); Vector3f vec = new Vector3f(x, y, z); string peek = lastElement; if (peek == "rotate") // it is a keyframe { keyframeBoneAxis = vec; } else if (peek == "rotation") // it is a bone bind pose { bindAxis = vec; skeleton.GetBone(boneIdx).SetBindAxisAngle(bindAxis.Normalize(), bindAngle); } } else if (xmlReader.Name == "keyframe") { keyframeBoneTime = float.Parse(xmlReader.GetAttribute("time")); } else if (xmlReader.Name == "animation") { skeleton.GetAnimations().Add(new Animation(xmlReader.GetAttribute("name"))); } lastElement = xmlReader.Name; } else if (xmlReader.NodeType == XmlNodeType.EndElement) { if (xmlReader.Name == "keyframe") { Bone b = skeleton.GetBone(keyframeBoneName); if (b != null) { Keyframe keyf = null; skeleton.GetAnimations()[skeleton.GetAnimations().Count - 1] .GetTrack(skeleton.GetAnimations()[skeleton.GetAnimations().Count - 1] .GetTracks().Count - 1) .AddKeyframe(keyf = new Keyframe(keyframeBoneTime, keyframeBoneTrans, keyframeBoneAxis, keyframeBoneAngle)); } keyframeBoneAngle = 0f; keyframeBoneAxis = new Vector3f(Vector3f.Zero); keyframeBoneTime = 0f; keyframeBoneTrans = new Vector3f(Vector3f.Zero); } else if (xmlReader.Name == "track") { keyframeBoneName = ""; } } } xmlReader.Close(); return skeleton; }
public override object Load(LoadedAsset asset) { XmlReader xmlReader = XmlReader.Create(asset.Data); while (xmlReader.Read()) { if (xmlReader.NodeType == XmlNodeType.Element) { if (xmlReader.Name == ApxExporter.TOKEN_NODE) { node = true; geom = false; string name = xmlReader.GetAttribute(ApxExporter.TOKEN_NAME); Node n = new Node(name); if (lastNode != null) lastNode.AddChild(n); lastNode = n; nodes.Add(n); } else if (xmlReader.Name == ApxExporter.TOKEN_GEOMETRY) { node = false; geom = true; string name = xmlReader.GetAttribute(ApxExporter.TOKEN_NAME); Geometry g = new Geometry(); g.Name = name; if (lastNode != null) lastNode.AddChild(g); geoms.Add(g); } else if (xmlReader.Name == ApxExporter.TOKEN_MATERIAL) { Material mat = new Material(); mats.Add(mat); string bucketStr = xmlReader.GetAttribute(ApxExporter.TOKEN_MATERIAL_BUCKET); RenderManager.Bucket bucket; if (bucketStr != null) Enum.TryParse<RenderManager.Bucket>(bucketStr, out bucket); else bucket = RenderManager.Bucket.Opaque; Console.WriteLine("Bucket: " + bucket.ToString()); mat.Bucket = bucket; } else if (xmlReader.Name == ApxExporter.TOKEN_MATERIAL_PROPERTY) { Material lastMaterial = mats[mats.Count - 1]; string name = xmlReader.GetAttribute(ApxExporter.TOKEN_NAME); string type = xmlReader.GetAttribute(ApxExporter.TOKEN_TYPE); string val = xmlReader.GetAttribute(ApxExporter.TOKEN_VALUE); object value = null; if (type == ApxExporter.TOKEN_TYPE_STRING) value = val; else if (type == ApxExporter.TOKEN_TYPE_INT) value = int.Parse(val); else if (type == ApxExporter.TOKEN_TYPE_BOOLEAN) value = bool.Parse(val); else if (type == ApxExporter.TOKEN_TYPE_FLOAT) value = float.Parse(val); else if (type == ApxExporter.TOKEN_TYPE_VECTOR2) value = ParseVector2(val); else if (type == ApxExporter.TOKEN_TYPE_VECTOR3) value = ParseVector3(val); else if (type == ApxExporter.TOKEN_TYPE_VECTOR4) value = ParseVector4(val); else if (type == ApxExporter.TOKEN_TYPE_TEXTURE) { string texPath = val; string parentPath = System.IO.Directory.GetParent(asset.FilePath).ToString(); string finalTexPath = parentPath + "\\" + texPath; if (System.IO.File.Exists(finalTexPath)) { value = AssetManager.LoadTexture(finalTexPath); } else if (System.IO.File.Exists(texPath)) // absolute path { value = AssetManager.LoadTexture(texPath); } else value = null; } lastMaterial.SetValue(name, value); } else if (xmlReader.Name == ApxExporter.TOKEN_TRANSLATION) { float x = float.Parse(xmlReader.GetAttribute("x")); float y = float.Parse(xmlReader.GetAttribute("y")); float z = float.Parse(xmlReader.GetAttribute("z")); Vector3f vec = new Vector3f(x, y, z); GameObject go = null; if (node) go = nodes[nodes.Count - 1]; else if (geom) go = geoms[geoms.Count - 1]; go.SetLocalTranslation(vec); } else if (xmlReader.Name == ApxExporter.TOKEN_ROTATION) { float x = float.Parse(xmlReader.GetAttribute("x")); float y = float.Parse(xmlReader.GetAttribute("y")); float z = float.Parse(xmlReader.GetAttribute("z")); float w = float.Parse(xmlReader.GetAttribute("w")); Quaternion quat = new Quaternion(x, y, z, w); GameObject go = null; if (node) go = nodes[nodes.Count - 1]; else if (geom) go = geoms[geoms.Count - 1]; go.SetLocalRotation(quat); } else if (xmlReader.Name == ApxExporter.TOKEN_SCALE) { float x = float.Parse(xmlReader.GetAttribute("x")); float y = float.Parse(xmlReader.GetAttribute("y")); float z = float.Parse(xmlReader.GetAttribute("z")); Vector3f vec = new Vector3f(x, y, z); GameObject go = null; if (node) go = nodes[nodes.Count - 1]; else if (geom) go = geoms[geoms.Count - 1]; go.SetLocalScale(vec); } else if (xmlReader.Name == ApxExporter.TOKEN_MESH) { meshes.Add(new Mesh()); } else if (xmlReader.Name == ApxExporter.TOKEN_VERTICES) { List<Vertex> newVList = new List<Vertex>(); vertices.Add(newVList); List<Vector3f> newPList = new List<Vector3f>(); positions.Add(newPList); List<Vector3f> newNList = new List<Vector3f>(); normals.Add(newNList); List<Vector2f> newT0List = new List<Vector2f>(); texcoords0.Add(newT0List); List<Vector2f> newT1List = new List<Vector2f>(); texcoords1.Add(newT1List); } else if (xmlReader.Name == ApxExporter.TOKEN_POSITION) { List<Vector3f> pos = positions[positions.Count - 1]; float x = float.Parse(xmlReader.GetAttribute("x")); float y = float.Parse(xmlReader.GetAttribute("y")); float z = float.Parse(xmlReader.GetAttribute("z")); Vector3f position = new Vector3f(x, y, z); pos.Add(position); } else if (xmlReader.Name == ApxExporter.TOKEN_NORMAL) { List<Vector3f> nor = normals[normals.Count - 1]; float x = float.Parse(xmlReader.GetAttribute("x")); float y = float.Parse(xmlReader.GetAttribute("y")); float z = float.Parse(xmlReader.GetAttribute("z")); Vector3f normal = new Vector3f(x, y, z); nor.Add(normal); } else if (xmlReader.Name == ApxExporter.TOKEN_TEXCOORD0) { List<Vector2f> tc0 = texcoords0[texcoords0.Count - 1]; float x = float.Parse(xmlReader.GetAttribute("x")); float y = float.Parse(xmlReader.GetAttribute("y")); Vector2f tc = new Vector2f(x, y); tc0.Add(tc); } else if (xmlReader.Name == ApxExporter.TOKEN_TEXCOORD1) { List<Vector2f> tc1 = texcoords1[texcoords1.Count - 1]; float x = float.Parse(xmlReader.GetAttribute("x")); float y = float.Parse(xmlReader.GetAttribute("y")); Vector2f tc = new Vector2f(x, y); tc1.Add(tc); } else if (xmlReader.Name == ApxExporter.TOKEN_FACES) { faces.Add(new List<int>()); } else if (xmlReader.Name == ApxExporter.TOKEN_FACE) { List<int> fList = faces[faces.Count - 1]; for (int i = 0; i < 3; i++) { string val = xmlReader.GetAttribute("i" + i.ToString()); if (val != "") { string[] tokens = val.Split('/'); for (int j = 0; j < tokens.Length; j++) { fList.Add(int.Parse(tokens[j])); } } } } else if (xmlReader.Name == ApxExporter.TOKEN_SKELETON) { skeletons.Add(new Skeleton()); bones.Add(new List<Bone>()); } else if (xmlReader.Name == ApxExporter.TOKEN_SKELETON_ASSIGN) { string assign = xmlReader.GetAttribute(ApxExporter.TOKEN_ID); skeletonAssigns.Add(int.Parse(assign)); } else if (xmlReader.Name == ApxExporter.TOKEN_BONE) { string name = xmlReader.GetAttribute(ApxExporter.TOKEN_NAME); string parent = xmlReader.GetAttribute(ApxExporter.TOKEN_PARENT); Bone bone = new Bone(name); List<Bone> lastBL = bones[bones.Count - 1]; if (!string.IsNullOrEmpty(parent)) { foreach (Bone b in lastBL) { if (b.Name == parent) { b.AddChild(bone); } } } List<Bone> skel = bones[bones.Count - 1]; skel.Add(bone); Skeleton lastSkeleton = skeletons[skeletons.Count - 1]; lastSkeleton.AddBone(bone); } else if (xmlReader.Name == ApxExporter.TOKEN_BONE_BINDPOSITION) { float x = float.Parse(xmlReader.GetAttribute("x")); float y = float.Parse(xmlReader.GetAttribute("y")); float z = float.Parse(xmlReader.GetAttribute("z")); Vector3f vec = new Vector3f(x, y, z); List<Bone> skel = bones[bones.Count - 1]; if (skel.Count > 0) { Bone lastBone = skel[skel.Count - 1]; lastBone.SetBindTranslation(vec); } } else if (xmlReader.Name == ApxExporter.TOKEN_BONE_BINDROTATION) { float x = float.Parse(xmlReader.GetAttribute("x")); float y = float.Parse(xmlReader.GetAttribute("y")); float z = float.Parse(xmlReader.GetAttribute("z")); float w = float.Parse(xmlReader.GetAttribute("w")); List<Bone> skel = bones[bones.Count - 1]; if (skel.Count > 0) { Bone lastBone = skel[skel.Count - 1]; // lastBone.SetBindAxisAngle(new Vector3f(x, y, z), w); lastBone.SetBindRotation(new Quaternion(x, y, z, w)); } } else if (xmlReader.Name == ApxExporter.TOKEN_BONE_ASSIGNS) { boneAssigns.Add(new List<BoneAssign>()); } else if (xmlReader.Name == ApxExporter.TOKEN_BONE_ASSIGN) { int vertIdx = int.Parse(xmlReader.GetAttribute(ApxExporter.TOKEN_VERTEXINDEX)); int boneIdx = int.Parse(xmlReader.GetAttribute(ApxExporter.TOKEN_BONEINDEX)); float boneWeight = float.Parse(xmlReader.GetAttribute(ApxExporter.TOKEN_BONEWEIGHT)); List<BoneAssign> ba = boneAssigns[boneAssigns.Count - 1]; ba.Add(new BoneAssign(vertIdx, boneWeight, boneIdx)); } else if (xmlReader.Name == ApxExporter.TOKEN_ANIMATIONS) { hasAnimations = true; } else if (xmlReader.Name == ApxExporter.TOKEN_ANIMATION) { string name = xmlReader.GetAttribute(ApxExporter.TOKEN_NAME); Animation anim = new Animation(name); animations.Add(anim); } else if (xmlReader.Name == ApxExporter.TOKEN_ANIMATION_TRACK) { string bone = xmlReader.GetAttribute(ApxExporter.TOKEN_BONE); Bone b = skeletons[skeletons.Count - 1].GetBone(bone); if (b != null) { AnimationTrack track = new AnimationTrack(b); animations[animations.Count - 1].AddTrack(track); } } else if (xmlReader.Name == ApxExporter.TOKEN_KEYFRAME) { float time = float.Parse(xmlReader.GetAttribute(ApxExporter.TOKEN_TIME)); Keyframe frame = new Keyframe(time, null, null); Animation canim = animations[animations.Count - 1]; AnimationTrack ctrack = canim.GetTrack(canim.GetTracks().Count - 1); ctrack.AddKeyframe(frame); } else if (xmlReader.Name == ApxExporter.TOKEN_KEYFRAME_TRANSLATION) { Animation canim = animations[animations.Count - 1]; AnimationTrack ctrack = canim.GetTrack(canim.GetTracks().Count - 1); Keyframe lastFrame = ctrack.frames[ctrack.frames.Count - 1]; float x = float.Parse(xmlReader.GetAttribute("x")); float y = float.Parse(xmlReader.GetAttribute("y")); float z = float.Parse(xmlReader.GetAttribute("z")); Vector3f vec = new Vector3f(x, y, z); lastFrame.SetTranslation(vec); } else if (xmlReader.Name == ApxExporter.TOKEN_KEYFRAME_ROTATION) { Animation canim = animations[animations.Count - 1]; AnimationTrack ctrack = canim.GetTrack(canim.GetTracks().Count - 1); Keyframe lastFrame = ctrack.frames[ctrack.frames.Count - 1]; float x = float.Parse(xmlReader.GetAttribute("x")); float y = float.Parse(xmlReader.GetAttribute("y")); float z = float.Parse(xmlReader.GetAttribute("z")); float w = float.Parse(xmlReader.GetAttribute("w")); Quaternion rot = new Quaternion(x, y, z, w); lastFrame.SetRotation(rot); } } // start element else if (xmlReader.NodeType == XmlNodeType.EndElement) { if (xmlReader.Name == ApxExporter.TOKEN_NODE) { if (lastNode != null) { if (lastNode.GetParent() != null) { lastNode = lastNode.GetParent(); } else { lastNode = null; } } node = false; } else if (xmlReader.Name == ApxExporter.TOKEN_GEOMETRY) { geom = false; } else if (xmlReader.Name == ApxExporter.TOKEN_MATERIAL) { if (geoms.Count > 0) { int lastGeomIndex = geoms.Count - 1; Geometry parent = geoms[lastGeomIndex]; int lastMatIndex = mats.Count - 1; Material m = mats[lastMatIndex]; geomMats.Add(parent, m); } } else if (xmlReader.Name == ApxExporter.TOKEN_SKELETON) { } else if (xmlReader.Name == ApxExporter.TOKEN_MODEL) { // end of model, load in meshes EndModel(); } } // end element } xmlReader.Close(); Node finalNode = new Node(); foreach (Node n in nodes) if (n.GetParent() == null) finalNode.AddChild(n); this.ResetLoader(); return finalNode; }
public override object Load(LoadedAsset asset) { XmlReader xmlReader = XmlReader.Create(asset.Data); while (xmlReader.Read()) { if (xmlReader.NodeType == XmlNodeType.Element) { if (xmlReader.Name == "position") { float x = float.Parse(xmlReader.GetAttribute("x")); float y = float.Parse(xmlReader.GetAttribute("y")); float z = float.Parse(xmlReader.GetAttribute("z")); Vector3f vec = new Vector3f(x, y, z); positions.Add(vec); } else if (xmlReader.Name == "normal") { float x = float.Parse(xmlReader.GetAttribute("x")); float y = float.Parse(xmlReader.GetAttribute("y")); float z = float.Parse(xmlReader.GetAttribute("z")); Vector3f vec = new Vector3f(x, y, z); normals.Add(vec); } else if (xmlReader.Name == "texcoord") { float x = float.Parse(xmlReader.GetAttribute(0)); float y = float.Parse(xmlReader.GetAttribute(1)); Vector2f tc = new Vector2f(x, -y); texCoords.Add(tc); } else if (xmlReader.Name == "face") { if (!useSubmeshes) { faces.Add(int.Parse(xmlReader.GetAttribute(0))); faces.Add(int.Parse(xmlReader.GetAttribute(1))); faces.Add(int.Parse(xmlReader.GetAttribute(2))); } else if (useSubmeshes) { CurrentSubmesh().faces.Add(int.Parse(xmlReader.GetAttribute(0))); CurrentSubmesh().faces.Add(int.Parse(xmlReader.GetAttribute(1))); CurrentSubmesh().faces.Add(int.Parse(xmlReader.GetAttribute(2))); } } else if (xmlReader.Name == "skeletonlink") { string parentPath = System.IO.Directory.GetParent(asset.FilePath).ToString(); string skeletonPath = parentPath + "\\" + xmlReader.GetAttribute(0) + ".xml"; skeleton = (Skeleton)AssetManager.Load(skeletonPath, OgreXmlSkeletonLoader.GetInstance()); } else if (xmlReader.Name == "vertexboneassignment" || xmlReader.Name == "boneassignment") { int vidx = int.Parse(xmlReader.GetAttribute("vertexindex")); float boneWeight = float.Parse(xmlReader.GetAttribute("weight")); int boneIndex = int.Parse(xmlReader.GetAttribute("boneindex")); AddToBoneAssigns(vidx, new BoneAssign(vidx, boneWeight, boneIndex)); } else if (xmlReader.Name == "submesh") { useSubmeshes = true; if (xmlReader.GetAttribute("operationtype") != null) { // material Submesh sm = new Submesh(); subMeshes.Add(sm); } } } } xmlReader.Close(); List<Vertex> vertices = new List<Vertex>(); if (!useSubmeshes) { LoopThrough(faces, ref vertices); } else { for (int i = subMeshes.Count - 1; i > -1; i--) { Submesh s = subMeshes[i]; if (s.faces.Count > 0) LoopThrough(s.faces, ref s.vertices); else subMeshes.Remove(s); } } if (skeleton.GetNumBones() > 0) { for (int i = 0; i < skeleton.GetNumBones(); i++) skeleton.GetBone(i).SetToBindingPose(); skeleton.GetBone(0).CalculateBindingRotation(); skeleton.GetBone(0).CalculateBindingTranslation(); for (int i = 0; i < skeleton.GetNumBones(); i++) { skeleton.GetBone(i).StoreBindingPose(); skeleton.GetBone(i).ClearPose(); } skeleton.GetBone(0).UpdateTransform(); } bool hasAnimations = skeleton.GetAnimations().Count > 0; AnimationController animControl = new AnimationController(skeleton); Node res = new Node(); if (!useSubmeshes) { Mesh mesh = new Mesh(); mesh.SetSkeleton(skeleton); mesh.SetVertices(vertices); Geometry geom = new Geometry(); geom.Mesh = mesh; res.AddChild(geom); } else { for (int i = 0; i < subMeshes.Count; i++) { Submesh sm = subMeshes[i]; Mesh mesh = new Mesh(); mesh.SetSkeleton(skeleton); mesh.SetVertices(sm.vertices); Geometry geom = new Geometry(); geom.Mesh = mesh; res.AddChild(geom); } } if (hasAnimations) { res.AddController(animControl); } ResetLoader(); return res; }