public new static UVWTag Alloc(int count) { global::System.IntPtr cPtr = C4dApiPINVOKE.UVWTag_Alloc(count); UVWTag ret = (cPtr == global::System.IntPtr.Zero) ? null : new UVWTag(cPtr, false); return(ret); }
/// <summary> /// This method tries to make the best out of C4Ds seldom relationship between objects with /// multiple materials which can or can not be restricted to polygon selections and one or more UV sets. /// But there are unhandled cases: /// Multple UV tags are not supported. Overlapping polygon selections are probably handled differently. /// The awkward side effects when changing the tags' order in C4D are not reproduced. /// </summary> /// <param name="ob"></param> /// <param name="snc"></param> private void VisitObject(BaseObject ob, SceneNodeContainer snc) { Collection <TextureTag> textureTags = new Collection <TextureTag>(); Dictionary <string, SelectionTag> selectionTags = new Dictionary <string, SelectionTag>(); UVWTag uvwTag = null; CAWeightTag weightTag = null; // SCRATCH // var targetComponent = new TargetComponent {ExtraInfo = aStr, Radius = anInt}; // snc.AddComponent(targetComponent); // Iterate over the object's tags for (BaseTag tag = ob.GetFirstTag(); tag != null; tag = tag.GetNext()) { // GeneralTag if (1036156 == tag.GetTypeC4D()) { var di = tag.GetDataInstance(); int anInt = di.GetInt32(10000); string aStr = di.GetString(10001); Logger.Debug("Found a GeneralTag with TheInt=" + anInt + " and TheString = \"" + aStr + "\""); // var targetComponent = new TargetComponent {ExtraInfo = aStr, Radius = anInt}; // snc.AddComponent(targetComponent); } // CAWeightTag - Save data to create the weight list later CAWeightTag wTag = tag as CAWeightTag; if (wTag != null) { weightTag = wTag; continue; } // TextureTag (Material - there might be more than one) TextureTag tex = tag as TextureTag; if (tex != null) { textureTags.Add(tex); continue; } // UVWTag - the texutre coordinates. We handle only one UVWTag uvw = tag as UVWTag; if (uvw != null) { if (uvwTag == null) { uvwTag = uvw; } else { Logger.Error("Object " + ob.GetName() + " contains more than one uv-coordinates-tag. Cannot handle this. Only the first texture tag will be recognized."); } continue; } // Selection tag. Only recognize the polygon selections as they might be referenced in a TextureTag SelectionTag selection = tag as SelectionTag; string selTagName = tag.GetName(); if (selection != null && selection.GetTypeC4D() == C4dApi.Tpolygonselection && !string.IsNullOrEmpty(selTagName)) // One Type and three TypeIDs - You C4D programmer guys really suck { selectionTags[selTagName] = selection; } // XPresso Tags - TBD XPressoTag xPresso = tag as XPressoTag; if (xPresso != null) { // Handle XPresso tag continue; } } TextureTag lastUnselectedTag = null; Collection <KeyValuePair <SelectionTag, TextureTag> > texSelList = new Collection <KeyValuePair <SelectionTag, TextureTag> >(); // Abused KeyValuePair. Should have been Pair... // Now iterate over the textureTags foreach (TextureTag texture in textureTags) { string selRef = ""; using (BaseContainer texData = texture.GetData()) { selRef = texData.GetString(C4dApi.TEXTURETAG_RESTRICTION); } if (string.IsNullOrEmpty(selRef)) { // This material is not restricted to any polygon selection lastUnselectedTag = texture; } else { SelectionTag sel; if (selectionTags.TryGetValue(selRef, out sel)) { texSelList.Add(new KeyValuePair <SelectionTag, TextureTag>(sel, texture)); } } } // At this point we have the last texture tag not restricted to a seletion. This will become the Material of this FuseeObjectContainer // no matter if this object contains geometry or not if (lastUnselectedTag != null) { AddComponent(snc, GetMaterial(lastUnselectedTag)); } // Further processing only needs to take place if the object contains any geometry at all. PolygonObject polyOb = ob as PolygonObject; // Check whether the object contains an unpolygonized mesh if (polyOb == null) { polyOb = ob.GetCache(null) as PolygonObject; } if (polyOb != null) { float3[] normalOb = polyOb.CreatePhongNormals(); // Initialize the polygon index set int nPolys = polyOb.GetPolygonCount(); HashSet <int> polyInxs = new HashSet <int>(); for (int i = 0; i < nPolys; i++) { polyInxs.Add(i); } foreach (KeyValuePair <SelectionTag, TextureTag> texSelItem in texSelList) { HashSet <int> polyInxsSubset = new HashSet <int>(); BaseSelect bs = texSelItem.Key.GetBaseSelect(); int nSegments = bs.GetSegments(); for (int iSeg = 0; iSeg < nSegments; iSeg++) { int from = bs.GetRangeA(iSeg); int to = bs.GetRangeB(iSeg); for (int iSel = from; iSel <= to; iSel++) { polyInxs.Remove(iSel); polyInxsSubset.Add(iSel); } } // Now generate Polygons for this subset if (polyInxsSubset.Count > 0) { if (snc.Children == null) { snc.Children = new List <SceneNodeContainer>(); } SceneNodeContainer subSnc = new SceneNodeContainer(); AddComponent(subSnc, new TransformComponent() { Translation = new float3(0, 0, 0), Rotation = new float3(0, 0, 0), Scale = new float3(1, 1, 1) }); AddComponent(subSnc, GetMaterial(texSelItem.Value)); subSnc.Name = snc.Name + "_" + texSelItem.Key.GetName(); AddComponent(subSnc, GetMesh(polyOb, normalOb, uvwTag, polyInxsSubset)); _weightManager.AddWeightData(subSnc, polyOb, weightTag, polyInxsSubset); snc.Children.Add(subSnc); } } // The remaining polygons directly go into the original mesh AddComponent(snc, GetMesh(polyOb, normalOb, uvwTag, polyInxs)); _weightManager.AddWeightData(snc, polyOb, weightTag, polyInxs); } else if (ob.GetTypeC4D() == C4dApi.Olight) { using (BaseContainer lightData = ob.GetData()) // Just for debugging purposes for (int i = 0, id = 0; -1 != (id = lightData.GetIndexId(i)); i++) { if (lightData.GetTypeC4D(id) == C4dApi.DA_LONG) { int iii = lightData.GetInt32(id); } if (lightData.GetTypeC4D(id) == C4dApi.DA_REAL) { double d = lightData.GetFloat(id); } else if (lightData.GetTypeC4D(id) == C4dApi.DA_VECTOR) { double3 v = lightData.GetVector(id); } } ; } }
private static MeshComponent GetMesh(PolygonObject polyOb, float3[] normalsOb, UVWTag uvwTag, IEnumerable <int> range) { List <float3> normals = new List <float3>(); ushort nNewVerts = 0; VertexList verts = new VertexList(); List <float2> uvs = new List <float2>(); List <ushort> tris = new List <ushort>(); foreach (int i in range) { int iNorm = i * 4; double3 a, b, c, d; using (CPolygon poly = polyOb.GetPolygonAt(i)) { a = polyOb.GetPointAt(poly.a); b = polyOb.GetPointAt(poly.b); c = polyOb.GetPointAt(poly.c); d = polyOb.GetPointAt(poly.d); } float2 uvA = new float2(0, 0); float2 uvB = new float2(0, 1); float2 uvC = new float2(1, 1); float2 uvD = new float2(1, 0); if (uvwTag != null) { using (UVWStruct uvw = uvwTag.GetSlow(i)) { uvA = new float2((float)uvw.a.x, 1.0f - (float)uvw.a.y); uvB = new float2((float)uvw.b.x, 1.0f - (float)uvw.b.y); uvC = new float2((float)uvw.c.x, 1.0f - (float)uvw.c.y); uvD = new float2((float)uvw.d.x, 1.0f - (float)uvw.d.y); } } verts.Add((float3)a); verts.Add((float3)b); verts.Add((float3)c); uvs.Add(uvA); uvs.Add(uvB); uvs.Add(uvC); float3 faceNormal = CalcFaceNormal((float3)a, (float3)b, (float3)c); float3 normalD; if (normalsOb != null) { normals.Add(AdjustNormal(normalsOb[iNorm++], faceNormal)); normals.Add(AdjustNormal(normalsOb[iNorm++], faceNormal)); normals.Add(AdjustNormal(normalsOb[iNorm++], faceNormal)); normalD = AdjustNormal(normalsOb[iNorm++], faceNormal); } else { normals.Add(faceNormal); normals.Add(faceNormal); normals.Add(faceNormal); normalD = faceNormal; } tris.AddRange(new ushort[] { nNewVerts, (ushort)(nNewVerts + 2), (ushort)(nNewVerts + 1) }); if (c != d) { // The Polyogon is not a triangle, but a quad. Add the second triangle. verts.Add((float3)d); uvs.Add(uvD); normals.Add(normalD); tris.AddRange(new ushort[] { nNewVerts, (ushort)(nNewVerts + 3), (ushort)(nNewVerts + 2) }); nNewVerts += 1; } nNewVerts += 3; } Debug.WriteLine(verts.Count); return(new MeshComponent() { Normals = normals.ToArray(), Vertices = verts.ToArray(), Triangles = tris.ToArray(), UVs = uvs.ToArray(), BoundingBox = new AABBf(verts.Min, verts.Max) }); }
public void CpySlow(int dst, UVWTag srctag, int src) { C4dApiPINVOKE.UVWTag_CpySlow(swigCPtr, dst, UVWTag.getCPtr(srctag), src); }
internal static global::System.Runtime.InteropServices.HandleRef getCPtr(UVWTag obj) { return((obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr); }