private void CreateLODNodes(NiFile file, NiNode rootNode, QuadDesc quad, List<ShapeDesc> shapes) { foreach (ShapeDesc shapeDesc in shapes) { BSMultiBoundNode node = new BSMultiBoundNode(); rootNode.AddChild(file.AddBlock((NiObject)node)); BSSegmentedTriShape segmentedTriShape = new BSSegmentedTriShape((NiGeometry)shapeDesc.shape); node.AddChild(file.AddBlock((NiObject)segmentedTriShape)); node.SetCullMode(1U); string str = "obj"; // use material name from list file, Snow/Ash if (!this.ignoreMaterial && shapeDesc.material != "") { str = str + shapeDesc.material; } // only level 4 should have HD if (shapeDesc.isHighDetail && (this.quadLevel == 4 || this.useHDFlag)) { str = str + "HD"; } segmentedTriShape.SetNameIndex(file.AddString(str)); segmentedTriShape.SetFlags((ushort)14); segmentedTriShape.SetFlags2((ushort)8320); segmentedTriShape.SetData(file.AddBlock((NiObject)shapeDesc.data)); segmentedTriShape.SetBSProperty(1, -1); segmentedTriShape.SetScale((float)this.quadLevel); segmentedTriShape.SetRotation(new Matrix33(true)); segmentedTriShape.SetTranslation(new Vector3((float)quad.x * 4096f, (float)quad.y * 4096f, 0.0f)); for (int index = 0; index < 16; ++index) { segmentedTriShape.AddSegment(new BSSegment(0U, (ushort)0)); } for (int index = 0; index < shapeDesc.segments.Count; ++index) { BSSegment segmentAtIndex = segmentedTriShape.GetSegmentAtIndex(shapeDesc.segments[index].id); segmentAtIndex.startTriangle = shapeDesc.segments[index].startTriangle; segmentAtIndex.numTriangles = shapeDesc.segments[index].numTriangles; segmentedTriShape.SetSegment(shapeDesc.segments[index].id, segmentAtIndex); } for (int index = 15; index >= 0 && (int)segmentedTriShape.GetSegmentAtIndex(index).numTriangles == 0; --index) { segmentedTriShape.RemoveSegment(index); } BSShaderTextureSet shaderTextureSet = new BSShaderTextureSet(); BSLightingShaderProperty lightingShaderProperty = new BSLightingShaderProperty(); segmentedTriShape.SetBSProperty(0, file.AddBlock((NiObject)lightingShaderProperty)); lightingShaderProperty.SetTextureSet(file.AddBlock((NiObject)shaderTextureSet)); lightingShaderProperty.SetLightingEffect1(0.0f); lightingShaderProperty.SetLightingEffect2(0.0f); lightingShaderProperty.SetGlossiness(1f); lightingShaderProperty.SetTextureClampMode(shapeDesc.TextureClampMode); uint num1 = 2151677952U; /*if (this.quadLevel == 4) { num1 = 2151678720U; // Recieve/Cast Shadows - no worky :( }*/ uint num3 = 1U; // ZBuffer_Write if (shapeDesc.isHighDetail && (this.quadLevel == 4 || this.useHDFlag)) { num3 |= 2147483648U; //HD_LOD_Objects } else { num3 |= 4U; //LOD_Objects } if (shapeDesc.data.HasVertexColors()) num3 |= 32U; // set double-sided flag if (shapeDesc.isDoubleSided) num3 |= 16; lightingShaderProperty.SetShaderFlags1(num1); lightingShaderProperty.SetShaderFlags2(num3); shaderTextureSet.SetNumTextures(9); shaderTextureSet.SetTexture(0, shapeDesc.textures[0]); shaderTextureSet.SetTexture(1, shapeDesc.textures[1]); this.GenerateMultibound(file, node, quad, shapeDesc.boundingBox); } }
private void CreateLODNodesFNV(NiFile file, BSMultiBoundNode node, QuadDesc quad, List<ShapeDesc> shapes) { foreach (ShapeDesc shapeDesc in shapes) { BSSegmentedTriShape segmentedTriShape = new BSSegmentedTriShape((NiGeometry)shapeDesc.shape); node.AddChild(file.AddBlock((NiObject)segmentedTriShape)); node.SetCullMode(1U); string str = "obj"; // use material name from list file, Snow/Ash if (!this.ignoreMaterial && shapeDesc.material != "") str = str + shapeDesc.material; // only level 4 should have HD if (shapeDesc.isHighDetail && (this.quadLevel == 4 || useHDFlag)) { str = str + "HD"; } //segmentedTriShape.SetNameIndex(file.AddString(str)); segmentedTriShape.SetFlags((ushort)14); segmentedTriShape.SetFlags2((ushort)8); //segmentedTriShape.SetBSProperty(1, -1); segmentedTriShape.SetTranslation(new Vector3((float)quad.x * 4096f, (float)quad.y * 4096f, 0.0f)); segmentedTriShape.SetRotation(new Matrix33(true)); segmentedTriShape.SetScale((float)this.quadLevel); BSShaderTextureSet shaderTextureSet = new BSShaderTextureSet(); BSShaderPPLightingProperty lightingShaderProperty = new BSShaderPPLightingProperty(); segmentedTriShape.SetProperties(file.AddBlock((NiObject)lightingShaderProperty)); lightingShaderProperty.SetTextureSet(file.AddBlock((NiObject)shaderTextureSet)); shaderTextureSet.SetNumTextures(6); shaderTextureSet.SetTexture(0, shapeDesc.textures[0]); shaderTextureSet.SetTexture(1, shapeDesc.textures[1]); segmentedTriShape.SetData(file.AddBlock((NiObject)shapeDesc.data)); for (int index = 0; index < 16; ++index) segmentedTriShape.AddSegment(new BSSegment(0U, (ushort)0)); for (int index = 0; index < shapeDesc.segments.Count; ++index) { BSSegment segmentAtIndex = segmentedTriShape.GetSegmentAtIndex(shapeDesc.segments[index].id); segmentAtIndex.startTriangle = shapeDesc.segments[index].startTriangle; segmentAtIndex.numTriangles = shapeDesc.segments[index].numTriangles; segmentedTriShape.SetSegment(shapeDesc.segments[index].id, segmentAtIndex); } for (int index = 15; index >= 0 && (int)segmentedTriShape.GetSegmentAtIndex(index).numTriangles == 0; --index) { segmentedTriShape.RemoveSegment(index); } this.GenerateMultibound(file, node, quad, shapeDesc.boundingBox); } }
public void GenerateTest(string strfile, LogFile logFile) { NiFile file = new NiFile(); NiNode rootNode = new NiNode(); file.AddBlock((NiObject)rootNode); this.quadLevel = 4; this.quadOffset = 16384f; QuadDesc quad = new QuadDesc(); quad.x = 0; quad.y = 0; quad.statics = new List<StaticDesc>(); StaticDesc curStat = new StaticDesc(); curStat.refID = "0"; curStat.rotX = 0.0f; curStat.rotY = 0.0f; curStat.rotZ = 0.0f; curStat.scale = 1f; curStat.x = 0.0f; curStat.y = 0.0f; curStat.z = 0.0f; curStat.staticName = "Test"; curStat.staticFullModel = strfile; curStat.staticModels = new string[3]; curStat.staticModels[0] = strfile; curStat.staticModels[1] = strfile; curStat.staticModels[2] = strfile; quad.statics.Add(curStat); List<ShapeDesc> shapes = this.ParseNif(quad, curStat, 0, file, rootNode); this.MergeNodes(shapes); for (int index = 0; index < shapes.Count; ++index) { BSSegmentedTriShape segmentedTriShape = new BSSegmentedTriShape((NiGeometry)shapes[index].shape); segmentedTriShape.SetRotation(new Matrix33(true)); segmentedTriShape.SetTranslation(new Vector3(0.0f, 0.0f, 0.0f)); rootNode.AddChild(file.AddBlock((NiObject)segmentedTriShape)); segmentedTriShape.SetData(file.AddBlock((NiObject)shapes[index].data)); } file.Write(this.outputDir + "\\" + this.worldspaceName + ".test.nif", logFile); }