public Texture(string name, BinaryTextureImage compressedData) { Name = name; CompressedData = compressedData; m_glTextureIndex = GL.GenTexture(); GL.BindTexture(TextureTarget.Texture2D, m_glTextureIndex); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (int)GXToOpenGL.GetWrapMode(compressedData.WrapS)); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (int)GXToOpenGL.GetWrapMode(compressedData.WrapT)); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)GXToOpenGL.GetMinFilter(compressedData.MinFilter)); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)GXToOpenGL.GetMagFilter(compressedData.MagFilter)); // Border Color WLinearColor borderColor = compressedData.BorderColor; GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureBorderColor, new[] { borderColor.R, borderColor.G, borderColor.B, borderColor.A }); // ToDo: Min/Mag LOD & Biases // Upload Image Data GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, compressedData.Width, compressedData.Height, 0, PixelFormat.Bgra, PixelType.UnsignedByte, compressedData.GetData()); // Generate Mip Maps if (compressedData.MipMapCount > 0) { GL.GenerateMipmap(GenerateMipmapTarget.Texture2D); } }
// headerStart seems to be chunkStart + 0x20 and I don't know why. /// <summary> /// Load a BinaryTextureImage from a stream. /// </summary> /// <param name="stream"></param> /// <param name="headerStart"></param> /// <param name="imageIndex">Optional additional offset used by J3D models. Multiplied by 0x20.</param> public void Load(EndianBinaryReader stream, long headerStart, int imageIndex = 0) { Format = (TextureFormats)stream.ReadByte(); AlphaSetting = stream.ReadByte(); Width = stream.ReadUInt16(); Height = stream.ReadUInt16(); WrapS = (WrapModes)stream.ReadByte(); WrapT = (WrapModes)stream.ReadByte(); PalettesEnabled = Convert.ToBoolean(stream.ReadByte()); PaletteFormat = (PaletteFormats)stream.ReadByte(); PaletteCount = stream.ReadUInt16(); int paletteDataOffset = stream.ReadInt32(); BorderColor = new WLinearColor(stream.ReadByte() / 255f, stream.ReadByte() / 255f, stream.ReadByte() / 255f, stream.ReadByte() / 255f); MinFilter = (FilterMode)stream.ReadByte(); MagFilter = (FilterMode)stream.ReadByte(); unknown2 = stream.ReadInt16(); MipMapCount = stream.ReadByte(); unknown3 = stream.ReadByte(); LodBias = stream.ReadInt16(); int imageDataOffset = stream.ReadInt32(); // Load the Palette data stream.BaseStream.Position = headerStart + paletteDataOffset + (0x20 * imageIndex); m_imagePalette = new Palette(); m_imagePalette.Load(stream, PaletteCount); // Now load and decode image data into an ARGB array. stream.BaseStream.Position = headerStart + imageDataOffset + (0x20 * imageIndex); m_rgbaImageData = DecodeData(stream, Width, Height, Format, m_imagePalette, PaletteFormat); }
public void DrawBones(IDebugLineDrawer lineDrawer) { Matrix4[] boneTransforms = new Matrix4[JNT1Tag.BindJoints.Count]; Vector3 lastPos = Vector3.Zero; for (int i = 0; i < JNT1Tag.BindJoints.Count; i++) { SkeletonJoint curJoint, origJoint; curJoint = origJoint = JNT1Tag.BindJoints[i]; Matrix4 cumulativeTransform = Matrix4.Identity; while (true) { Matrix4 jointMatrix = Matrix4.CreateScale(curJoint.Scale) * Matrix4.CreateFromQuaternion(curJoint.Rotation) * Matrix4.CreateTranslation(curJoint.Translation); cumulativeTransform *= jointMatrix; if (curJoint.Parent == null) { break; } curJoint = curJoint.Parent; } boneTransforms[i] = cumulativeTransform; Vector3 curPos = cumulativeTransform.ExtractTranslation(); Quaternion curRot = cumulativeTransform.ExtractRotation(); WLinearColor jointColor = origJoint.Unknown1 == 0 ? WLinearColor.Yellow : WLinearColor.Blue; lineDrawer.DrawLine(lastPos, curPos, jointColor, 0f, 0f); lastPos = curPos; } }
public CollisionTriangle(Vector3 v1, Vector3 v2, Vector3 v3, CollisionGroupNode parent) { Vertices = new Vector3[] { v1, v2, v3 }; VertexColor = WLinearColor.FromHexString("0xB0E0C0FF"); Properties = new CollisionProperty(); ParentGroup = parent; CalculateCenter(); }
public void SetTevkColorOverride(int index, WLinearColor overrideColor) { if (index < 0 || index >= 4) { throw new ArgumentOutOfRangeException("index", "index must be between 0 and 3"); } m_kColors[index] = overrideColor; m_kColorsEnabled[index] = true; }
public void DrawBoundsForJoints(bool boundingBox, bool boundingSphere, IDebugLineDrawer lineDrawer) { IList <SkeletonJoint> boneList = (m_currentBoneAnimation != null) ? JNT1Tag.AnimatedJoints : JNT1Tag.BindJoints; Matrix4[] boneTransforms = new Matrix4[boneList.Count]; ApplyBonePositionsToAnimationTransforms(boneList, boneTransforms); for (int i = 0; i < boneTransforms.Length; i++) { SkeletonJoint curJoint, origJoint; curJoint = origJoint = JNT1Tag.BindJoints[i]; //Matrix4 cumulativeTransform = Matrix4.Identity; //while (true) //{ // Matrix4 jointMatrix = Matrix4.CreateScale(curJoint.Scale) * Matrix4.CreateFromQuaternion(curJoint.Rotation) * Matrix4.CreateTranslation(curJoint.Translation); // cumulativeTransform *= jointMatrix; // if (curJoint.Parent == null) // break; // curJoint = curJoint.Parent; //} //boneTransforms[i] = cumulativeTransform; boneTransforms[i].Transpose(); Vector3 curPos = boneTransforms[i].ExtractTranslation(); Quaternion curRot = boneTransforms[i].ExtractRotation(); WLinearColor jointColor = origJoint.Unknown1 == 0 ? WLinearColor.Yellow : WLinearColor.Blue; if (boundingSphere) { // Many bones have no radius, simply skip them to avoid adding them to the line renderer. if (origJoint.BoundingSphereDiameter == 0f) { continue; } lineDrawer.DrawSphere(curPos, origJoint.BoundingSphereDiameter / 2, 12, jointColor, 0f, 0f); } if (boundingBox) { Vector3 extents = (origJoint.BoundingBox.Max - origJoint.BoundingBox.Min) / 2; // Many bones have no extents, simply skip them to avoid adding them to the line renderer. if (extents.LengthSquared == 0f) { continue; } lineDrawer.DrawBox(curPos, extents, curRot, jointColor, 0f, 0f); } } }
private void DrawFixedGrid() { int numCellsToDraw = 64; int rangeInCells = numCellsToDraw / 2; int majorLineInterval = numCellsToDraw / 8; int numLines = numCellsToDraw + 1; int axesIndex = numCellsToDraw / 2; float perspectiveGridSize = 400000; for (int lineIndex = 0; lineIndex < numLines; lineIndex++) { bool isMajorLine = ((lineIndex - rangeInCells) % majorLineInterval) == 0; Vector3 a = new Vector3(), b = new Vector3(); a.X = (perspectiveGridSize / 4f) * (-1f + 2f * lineIndex / numCellsToDraw); b.X = a.X; a.Y = b.Y = 0; a.Z = (perspectiveGridSize / 4f); b.Z = -(perspectiveGridSize / 4f); WLinearColor lineColor; float lineThickness = 0; if (lineIndex == axesIndex) { lineColor = new WLinearColor(70 / 255f, 70 / 255f, 70 / 255f); lineThickness = 0f; } else if (isMajorLine) { lineColor = new WLinearColor(40 / 255f, 40 / 255f, 40 / 255f); } else { lineColor = new WLinearColor(20 / 255f, 20 / 255f, 20 / 255f); } m_lineBatcher.DrawLine(a, b, lineColor, lineThickness, 0f); a.Z = a.X; b.Z = b.X; a.X = (perspectiveGridSize / 4f); b.X = -(perspectiveGridSize / 4f); m_lineBatcher.DrawLine(a, b, lineColor, lineThickness, 0f); } }
public void DrawBones(IDebugLineDrawer lineDrawer) { IList <SkeletonJoint> boneList = (m_currentBoneAnimation != null) ? JNT1Tag.AnimatedJoints : JNT1Tag.BindJoints; Matrix4[] boneTransforms = new Matrix4[boneList.Count]; Vector3 lastPos = Vector3.Zero; for (int i = 0; i < boneList.Count; i++) { SkeletonJoint curJoint, origJoint; curJoint = origJoint = boneList[i]; Matrix4 cumulativeTransform = Matrix4.Identity; SkeletonJoint prevJoint = null; while (true) { Vector3 scale = curJoint.Scale; if (prevJoint != null && prevJoint.DoNotInheritParentScale) { scale = Vector3.One; } Matrix4 jointMatrix = Matrix4.CreateScale(scale) * Matrix4.CreateFromQuaternion(curJoint.Rotation) * Matrix4.CreateTranslation(curJoint.Translation); cumulativeTransform *= jointMatrix; if (curJoint.Parent == null) { break; } prevJoint = curJoint; curJoint = curJoint.Parent; } boneTransforms[i] = cumulativeTransform; Vector3 curPos = cumulativeTransform.ExtractTranslation(); WLinearColor jointColor = origJoint.Unknown1 == 0 ? WLinearColor.Yellow : WLinearColor.Blue; if (origJoint.DoNotInheritParentScale) { jointColor = WLinearColor.Red; } if (origJoint.Parent != null) { int parentIndex = boneList.IndexOf(origJoint.Parent); Vector3 parentPos = boneTransforms[parentIndex].ExtractTranslation(); lineDrawer.DrawLine(parentPos, curPos, jointColor, 0f, 0f); } lineDrawer.DrawSphere(curPos, 1f, 5, jointColor, 0f, 0f); lastPos = curPos; } }
public CollisionTriangle(EndianBinaryReader reader, List <Vector3> positions, List <CollisionGroupNode> nodes, CollisionProperty[] properties) { Vertices = new Vector3[3]; Vertices[0] = positions[reader.ReadInt16()]; Vertices[1] = positions[reader.ReadInt16()]; Vertices[2] = positions[reader.ReadInt16()]; VertexColor = WLinearColor.FromHexString("0xB0E0C0FF"); Properties = properties[reader.ReadInt16()].Clone(); ParentGroup = nodes[reader.ReadInt16()]; ParentGroup.Triangles.Add(this); CalculateCenter(); }
public Material(EndianBinaryReader reader) { Textures = new List <Texture>(); textureIndexes = new List <short>(); Unknown1 = reader.ReadByte(); Unknown2 = reader.ReadByte(); Unknown3 = reader.ReadByte(); AmbientColor = WLinearColor.FromHexString(string.Format("{0:X}{1:X}{2:X}{3:X}", reader.ReadByte(), reader.ReadByte(), reader.ReadByte(), reader.ReadByte())); Unknown4 = reader.ReadByte(); for (int i = 0; i < 8; i++) { textureIndexes.Add(reader.ReadInt16()); } // I don't know what the rest of the data does reader.Skip(16); }
public void Select() { VertexColor = WLinearColor.FromHexString("0xFF0000FF"); IsSelected = true; }
public void SetTevkColorOverride(int index, WLinearColor overrideColor) { m_tevColorOverrides.SetTevkColorOverride(index, overrideColor); }
public void FilterSceneForRenderer(WSceneView view, WWorld world) { if (m_bOverrideSceneCamera) { view.OverrideSceneCamera(m_SceneCameraOverride); } foreach (WScene scene in world.Map.SceneList) { foreach (var renderable in scene.GetChildrenOfType <IRenderable>()) { renderable.AddToRenderer(view); } } Staff camera = (Staff)SelectedEvent.Actors.ToList().Find(x => x.StaffType == StaffType.Camera); if (camera != null) { Cut c = camera.FirstCut; while (c != null) { OpenTK.Vector3 eye_pos = new OpenTK.Vector3(); OpenTK.Vector3 target_pos = new OpenTK.Vector3(); Substance eye = c.Properties.Find(x => x.Name.ToLower() == "eye"); if (eye != null) { Substance <ObservableCollection <BindingVector3> > eye_vec = eye as Substance <ObservableCollection <BindingVector3> >; eye_pos = eye_vec.Data[0].BackingVector; WLinearColor draw_color = WLinearColor.White; if (EditorSelection.SelectedObjects.Contains(eye_vec.Data[0])) { draw_color = WLinearColor.FromHexString("0xFF4F00FF"); } world.DebugDrawBillboard("eye.png", eye_pos, new OpenTK.Vector3(100, 100, 100), draw_color, 0.025f); } Substance target = c.Properties.Find(x => x.Name.ToLower() == "center"); if (target != null) { Substance <ObservableCollection <BindingVector3> > target_vec = target as Substance <ObservableCollection <BindingVector3> >; target_pos = target_vec.Data[0].BackingVector; WLinearColor draw_color = WLinearColor.White; if (EditorSelection.SelectedObjects.Contains(target_vec.Data[0])) { draw_color = WLinearColor.FromHexString("0xFF4F00FF"); } world.DebugDrawBillboard("target.png", target_pos, new OpenTK.Vector3(100, 100, 100), draw_color, 0.025f); } if (eye != null && target != null) { world.DebugDrawLine(eye_pos, target_pos, WLinearColor.Black, 100000.0f, 0.025f); } c = c.NextCut; } } }
public static void Export(J3D.J3D file, string toFilePath) { Obj outputObj = new Obj(); List <Obj.Object> objObjects = new List <Obj.Object>(); foreach (var shape in file.SHP1Tag.Shapes) { // We can read the Position/UV/Normal data off of the shapes here, but we don't know which // material they belong to yet unless we iterate through the J3D's scene graph. Obj.Object objShape = new Obj.Object(); objShape.Positions.AddRange(shape.VertexData.Position); objShape.Normals.AddRange(shape.VertexData.Normal); objShape.TexCoords.AddRange(shape.VertexData.Tex0); for (int i = 0; i < shape.VertexData.Color0.Count; i++) { WLinearColor col = shape.VertexData.Color0[i]; objShape.Colors.Add(new Vector4(col.R, col.G, col.B, col.A)); } objShape.BuildFacesFromData(); objObjects.Add(objShape); } // Create a material for each material in the J3D file. Obj.MaterialLibrary objMaterialLibrary = new Obj.MaterialLibrary(file.Name); foreach (var mat in file.MAT3Tag.MaterialList) { Obj.ObjMaterial objMaterial = new Obj.ObjMaterial(mat.Name); // Because of the complexity of TEV Materials and their multi-inputs, we don't assign // anything to the Ambient/Diffuse/Specular colors of the material. Instead we leave them // at their defaults and just assign a Diffuse texture since it is also the only one we can // reliably determine from a TEV material. We also are forced to use the first TextureIndex, // even though there can be up to 8. int textureIndex = mat.TextureIndexes[0]; if (textureIndex < 0) { continue; } Texture texture = file.TEX1Tag.Textures[textureIndex]; var textureBitmap = texture.CompressedData.CreateBitmap(); objMaterial.AmbientTexture = objMaterial.DiffuseTexture = textureBitmap; // Add it to our Obj Material Library objMaterialLibrary.Materials.Add(objMaterial); } // Now we have to do a custom iteration through the SceneGraph of the J3D file to assign Materials to Objects. Obj.ObjMaterial dummyMat = null; AssignMaterialsToMeshBatchesRecursive(file, objMaterialLibrary, objObjects, file.INF1Tag.HierarchyRoot, ref dummyMat); // Write the created OBJ file out to disk. // Free the bitmaps we allocated as part of creating the materials. foreach (var mat in objMaterialLibrary.Materials) { mat.AmbientTexture.Dispose(); } }
private Vector4 LinearColorToVec4(WLinearColor color) { return(new Vector4(color.R, color.G, color.B, color.A).Normalized()); }
private void ApplyLightOverrides(WLinearColor tev_override, WLinearColor tev_k_override) { m_Model.SetTevColorOverride(0, tev_override); m_Model.SetTevkColorOverride(0, tev_k_override); }
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { WLinearColor color = (WLinearColor)value; return(Color.FromArgb((byte)(color.A * 255f), (byte)(color.R * 255f), (byte)(color.G * 255f), (byte)(color.B * 255f))); }
public void Deselect() { VertexColor = WLinearColor.FromHexString("0xB0E0C0FF"); IsSelected = false; }