Hashtable AddJointsToScene(Scene scn, ElementOrder component) { if (!joints) { return(new Hashtable()); } IntArrayList js = new IntArrayList(); Hashtable relationmap = gmdc.LoadJointRelationMap(); foreach (int k in relationmap.Keys) { if ((int)relationmap[k] == -1) { js.Add(k); } } Quaternion r = Quaternion.FromRotationMatrix(component.TransformMatrix); Vector3f tmp = r.GetEulerAngles(); scn.RootJoint.Name = "SIMPE_ROOT_IGNORE"; //scn.RootJoint.Rotation.X = tmp.X; scn.RootJoint.Rotation.Y = tmp.Y; scn.RootJoint.Rotation.Z = tmp.Z; Hashtable jointmap = new Hashtable(); foreach (int index in js) { AddJoint(scn.RootJoint, index, jointmap, component); } return(jointmap); }
/// <summary> /// Evaluates the function on a vector argument. /// </summary> /// <param name="Arguments">Function arguments.</param> /// <param name="Variables">Variables collection.</param> /// <returns>Function result.</returns> public override IElement Evaluate(IElement[] Arguments, Variables Variables) { int c = Arguments.Length; if (!(Arguments[0] is IVector Vector)) { throw new ScriptRuntimeException("First argument muts be a vector.", this); } ICollection <IElement> Temp = Vector.VectorElements; IElement[] Elements; int i; if (Temp is IElement[] V) { Elements = (IElement[])V.Clone(); } else { Elements = new IElement[Temp.Count]; i = 0; foreach (IElement E in Temp) { Elements[i++] = E; } } if (c == 1) { Array.Sort <IElement>(Elements, new ElementOrder(this)); } else { IComparer <IElement>[] Comparers = new IComparer <IElement> [c]; IElement Element; for (i = 1; i < c; i++) { Element = Arguments[i]; if (Element is DoubleNumber N) { double d = N.Value; int Sign = 1; if (d < 0) { Sign = -1; d = -d; } if (d == 0 || d > int.MaxValue || d != Math.Truncate(d)) { throw new ScriptRuntimeException("Index values must be non-zero integers.", this); } Comparers[i - 1] = new IndexOrder(this, (int)(d - 1), Sign); } else if (Element is StringValue S) { string s = S.Value; int Sign = 1; if (s.StartsWith("-")) { s = s.Substring(1); Sign = -1; } Comparers[i - 1] = new PropertyOrder(this, s, Sign); } else if (Element is ILambdaExpression Lambda) { if (Lambda.NrArguments != 2) { throw new ScriptRuntimeException("Lambda expressions must take exactly two parameters.", this); } Comparers[i - 1] = new LambdaOrder(Lambda, Variables); } else { throw new ScriptRuntimeException("Order parameters must be either lambda expressions, " + "string values representing field names or numeric index values.", this); } } Comparers[c - 1] = new ElementOrder(this); Array.Sort(Elements, new CompoundOrder(Comparers)); } return(Vector.Encapsulate(Elements, this)); }
void AddJoint(Ambertation.Scenes.Joint parent, int index, Hashtable jointmap, ElementOrder component) { if (!joints) { return; } if (index < 0 || index >= gmdc.Joints.Count) { return; } GmdcJoint j = gmdc.Joints[index]; Ambertation.Scenes.Joint nj = parent.CreateChild(j.Name); jointmap[index] = nj; if (j.AssignedTransformNode != null) { Vector3f tmp = j.AssignedTransformNode.Transformation.Translation; tmp = component.TransformScaled(tmp); //tmp = component.ScaleMatrix * tmp; nj.Translation.X = tmp.X; nj.Translation.Y = tmp.Y; nj.Translation.Z = tmp.Z; Quaternion q = component.TransformRotation(j.AssignedTransformNode.Transformation.Rotation); tmp = q.GetEulerAngles(); //Console.WriteLine(" "+q.ToLinedString()); nj.Rotation.X = tmp.X; nj.Rotation.Y = tmp.Y; nj.Rotation.Z = tmp.Z; IntArrayList li = j.AssignedTransformNode.ChildBlocks; foreach (int i in li) { SimPe.Interfaces.Scenegraph.ICresChildren cld = j.AssignedTransformNode.GetBlock(i); if (cld is TransformNode) { TransformNode tn = cld as TransformNode; if (tn.JointReference != TransformNode.NO_JOINT) { AddJoint(nj, tn.JointReference, jointmap, component); } } } } }
public Ambertation.Scenes.Scene GetScene(ElementOrder component) { return(GetScene(gmdc.Groups, null, null, component)); }
public Ambertation.Scenes.Scene GetScene(string absimgpath, ElementOrder component) { return(GetScene(gmdc.Groups, absimgpath, null, component)); }
public Ambertation.Scenes.Scene GetScene(GmdcGroups groups, string absimgpath, string imgfolder, ElementOrder component) { if (absimgpath != null) { if (imgfolder == null) { imgfolder = absimgpath; } imgfolder = imgfolder.Trim(); if (imgfolder.Length > 0 && !imgfolder.EndsWith(@"\")) { imgfolder += @"\"; } if (!System.IO.Directory.Exists(absimgpath)) { System.IO.Directory.CreateDirectory(absimgpath); } } Scene scn = new Scene(); Hashtable jointmap = new Hashtable(); try { jointmap = AddJointsToScene(scn, component); } catch (Exception ex) { Console.WriteLine(ex.Message + "\n" + ex.StackTrace); } TextureLocator tl = new TextureLocator(gmdc.Parent.Package); System.Collections.Hashtable txmts = tl.FindMaterials(gmdc.Parent); foreach (string key in txmtmap.Keys) { object o = txmtmap[key]; if (o != null) { txmts[key] = txmtmap[key]; } } Hashtable txtrs = tl.FindReferencedTXTR(txmts, null); foreach (string key in txtrmap.Keys) { object o = txtrmap[key]; if (o != null) { txtrs[key] = o; } } txtrs = tl.GetLargestImages(txtrs); txmts = tl.GetMaterials(txmts, scn); tl.Dispose(); foreach (GmdcGroup g in groups) { Ambertation.Scenes.Material mat = txmts[g.Name] as Ambertation.Scenes.Material; if (mat == null) { mat = scn.CreateMaterial("mat_" + g.Name); } else { mat.Name = "mat_" + g.Name; } System.IO.MemoryStream s = txtrs[g.Name] as System.IO.MemoryStream; if (s != null) { try { System.Drawing.Image img = System.Drawing.Image.FromStream(s); if (absimgpath != null) { img.Save(System.IO.Path.Combine(absimgpath, g.Name + ".png"), System.Drawing.Imaging.ImageFormat.Png); } mat.Texture.FileName = imgfolder + g.Name + ".png"; mat.Texture.Size = img.Size; mat.Texture.TextureImage = img; } catch {} } Ambertation.Scenes.Mesh m = scn.CreateMesh(g.Name, mat); GmdcElement vertexe = g.Link.FindElementType(ElementIdentity.Vertex); // GmdcElement vertexme = g.Link.FindElementType(ElementIdentity.MorphVertexDelta); GmdcElement normale = g.Link.FindElementType(ElementIdentity.Normal); GmdcElement texte = g.Link.FindElementType(ElementIdentity.UVCoordinate); GmdcElement bonee = g.Link.FindElementType(ElementIdentity.BoneAssignment); GmdcElement bonewighte = g.Link.FindElementType(ElementIdentity.BoneWeights); GmdcElement bumpnormal = g.Link.FindElementType(ElementIdentity.BumpMapNormal); int nr = g.Link.GetElementNr(vertexe); // int mnr = g.Link.GetElementNr(vertexme); for (int i = 0; i < g.Link.ReferencedSize; i++) { Vector3f v = new Vector3f(g.Link.GetValue(nr, i).Data[0], g.Link.GetValue(nr, i).Data[1], g.Link.GetValue(nr, i).Data[2]); /*Vector3f vm = new Vector3f(g.Link.GetValue(mnr, i).Data[0], g.Link.GetValue(mnr, i).Data[1], g.Link.GetValue(mnr, i).Data[2]); * v += vm;*/ v = component.TransformScaled(v); m.Vertices.Add(v.X, v.Y, v.Z); } if (normale != null) { nr = g.Link.GetElementNr(normale); for (int i = 0; i < g.Link.ReferencedSize; i++) { Vector3f v = new Vector3f(g.Link.GetValue(nr, i).Data[0], g.Link.GetValue(nr, i).Data[1], g.Link.GetValue(nr, i).Data[2]); v = component.TransformNormal(v); m.Normals.Add(v.X, v.Y, v.Z); } } if (bumpnormal != null) { nr = g.Link.GetElementNr(bumpnormal); for (int i = 0; i < g.Link.ReferencedSize; i++) { Vector3f v = new Vector3f(g.Link.GetValue(nr, i).Data[0], g.Link.GetValue(nr, i).Data[1], g.Link.GetValue(nr, i).Data[2]); v = component.TransformNormal(v); m.BumpMapNormalDelta.Add(v.X, v.Y, v.Z); } } if (texte != null) { nr = g.Link.GetElementNr(texte); for (int i = 0; i < g.Link.ReferencedSize; i++) { Vector2f v = new Vector2f(g.Link.GetValue(nr, i).Data[0], g.Link.GetValue(nr, i).Data[1]); m.TextureCoordinates.Add(v.X, 1 - v.Y); } } for (int i = 0; i < g.Faces.Count - 2; i += 3) { m.FaceIndices.Add(g.Faces[i], g.Faces[i + 1], g.Faces[i + 2]); } AddEnvelopes(g, m, bonee, bonewighte, jointmap); } return(scn); }