@@ -1919,13 +1919,46 @@ define([
1919
1919
var p0Scratch = new Cartesian3 ( ) ;
1920
1920
var p1Scratch = new Cartesian3 ( ) ;
1921
1921
var p2Scratch = new Cartesian3 ( ) ;
1922
- var barycentricScratch = new Cartesian3 ( ) ;
1922
+ function interpolateAndPackCartesian3 ( i0 , i1 , i2 , coords , sourceValues , currentValues , insertedIndex , normalize ) {
1923
+ var p0 = Cartesian3 . fromArray ( sourceValues , i0 * 3 , p0Scratch ) ;
1924
+ var p1 = Cartesian3 . fromArray ( sourceValues , i1 * 3 , p1Scratch ) ;
1925
+ var p2 = Cartesian3 . fromArray ( sourceValues , i2 * 3 , p2Scratch ) ;
1926
+
1927
+ Cartesian3 . multiplyByScalar ( p0 , coords . x , p0 ) ;
1928
+ Cartesian3 . multiplyByScalar ( p1 , coords . y , p1 ) ;
1929
+ Cartesian3 . multiplyByScalar ( p2 , coords . z , p2 ) ;
1930
+
1931
+ var value = Cartesian3 . add ( p0 , p1 , p0 ) ;
1932
+ Cartesian3 . add ( value , p2 , value ) ;
1933
+
1934
+ if ( normalize ) {
1935
+ Cartesian3 . normalize ( value , value ) ;
1936
+ }
1937
+
1938
+ Cartesian3 . pack ( value , currentValues , insertedIndex * 3 ) ;
1939
+ }
1940
+
1923
1941
var s0Scratch = new Cartesian2 ( ) ;
1924
1942
var s1Scratch = new Cartesian2 ( ) ;
1925
1943
var s2Scratch = new Cartesian2 ( ) ;
1944
+ function interpolateAndPackCartesian2 ( i0 , i1 , i2 , coords , sourceValues , currentValues , insertedIndex ) {
1945
+ var s0 = Cartesian2 . fromArray ( sourceValues , i0 * 2 , s0Scratch ) ;
1946
+ var s1 = Cartesian2 . fromArray ( sourceValues , i1 * 2 , s1Scratch ) ;
1947
+ var s2 = Cartesian2 . fromArray ( sourceValues , i2 * 2 , s2Scratch ) ;
1948
+
1949
+ Cartesian2 . multiplyByScalar ( s0 , coords . x , s0 ) ;
1950
+ Cartesian2 . multiplyByScalar ( s1 , coords . y , s1 ) ;
1951
+ Cartesian2 . multiplyByScalar ( s2 , coords . z , s2 ) ;
1926
1952
1927
- function computeTriangleAttributes ( i0 , i1 , i2 , point , positions , normals , tangents , bitangents , texCoords , extrudeDirections , currentAttributes , insertedIndex ) {
1928
- if ( ! defined ( normals ) && ! defined ( tangents ) && ! defined ( bitangents ) && ! defined ( texCoords ) && ! defined ( extrudeDirections ) ) {
1953
+ var value = Cartesian2 . add ( s0 , s1 , s0 ) ;
1954
+ Cartesian2 . add ( value , s2 , value ) ;
1955
+
1956
+ Cartesian2 . pack ( value , currentValues , insertedIndex * 2 ) ;
1957
+ }
1958
+
1959
+ var barycentricScratch = new Cartesian3 ( ) ;
1960
+ function computeTriangleAttributes ( i0 , i1 , i2 , point , positions , normals , tangents , bitangents , texCoords , extrudeDirections , currentAttributes , customAttributeNames , customAttributesLength , allAttributes , insertedIndex ) {
1961
+ if ( ! defined ( normals ) && ! defined ( tangents ) && ! defined ( bitangents ) && ! defined ( texCoords ) && ! defined ( extrudeDirections ) && customAttributesLength === 0 ) {
1929
1962
return ;
1930
1963
}
1931
1964
@@ -1935,19 +1968,7 @@ define([
1935
1968
var coords = barycentricCoordinates ( point , p0 , p1 , p2 , barycentricScratch ) ;
1936
1969
1937
1970
if ( defined ( normals ) ) {
1938
- var n0 = Cartesian3 . fromArray ( normals , i0 * 3 , p0Scratch ) ;
1939
- var n1 = Cartesian3 . fromArray ( normals , i1 * 3 , p1Scratch ) ;
1940
- var n2 = Cartesian3 . fromArray ( normals , i2 * 3 , p2Scratch ) ;
1941
-
1942
- Cartesian3 . multiplyByScalar ( n0 , coords . x , n0 ) ;
1943
- Cartesian3 . multiplyByScalar ( n1 , coords . y , n1 ) ;
1944
- Cartesian3 . multiplyByScalar ( n2 , coords . z , n2 ) ;
1945
-
1946
- var normal = Cartesian3 . add ( n0 , n1 , n0 ) ;
1947
- Cartesian3 . add ( normal , n2 , normal ) ;
1948
- Cartesian3 . normalize ( normal , normal ) ;
1949
-
1950
- Cartesian3 . pack ( normal , currentAttributes . normal . values , insertedIndex * 3 ) ;
1971
+ interpolateAndPackCartesian3 ( i0 , i1 , i2 , coords , normals , currentAttributes . normal . values , insertedIndex , true ) ;
1951
1972
}
1952
1973
1953
1974
if ( defined ( extrudeDirections ) ) {
@@ -1974,50 +1995,55 @@ define([
1974
1995
}
1975
1996
1976
1997
if ( defined ( tangents ) ) {
1977
- var t0 = Cartesian3 . fromArray ( tangents , i0 * 3 , p0Scratch ) ;
1978
- var t1 = Cartesian3 . fromArray ( tangents , i1 * 3 , p1Scratch ) ;
1979
- var t2 = Cartesian3 . fromArray ( tangents , i2 * 3 , p2Scratch ) ;
1980
-
1981
- Cartesian3 . multiplyByScalar ( t0 , coords . x , t0 ) ;
1982
- Cartesian3 . multiplyByScalar ( t1 , coords . y , t1 ) ;
1983
- Cartesian3 . multiplyByScalar ( t2 , coords . z , t2 ) ;
1984
-
1985
- var tangent = Cartesian3 . add ( t0 , t1 , t0 ) ;
1986
- Cartesian3 . add ( tangent , t2 , tangent ) ;
1987
- Cartesian3 . normalize ( tangent , tangent ) ;
1988
-
1989
- Cartesian3 . pack ( tangent , currentAttributes . tangent . values , insertedIndex * 3 ) ;
1998
+ interpolateAndPackCartesian3 ( i0 , i1 , i2 , coords , tangents , currentAttributes . tangent . values , insertedIndex , true ) ;
1990
1999
}
1991
2000
1992
2001
if ( defined ( bitangents ) ) {
1993
- var b0 = Cartesian3 . fromArray ( bitangents , i0 * 3 , p0Scratch ) ;
1994
- var b1 = Cartesian3 . fromArray ( bitangents , i1 * 3 , p1Scratch ) ;
1995
- var b2 = Cartesian3 . fromArray ( bitangents , i2 * 3 , p2Scratch ) ;
1996
-
1997
- Cartesian3 . multiplyByScalar ( b0 , coords . x , b0 ) ;
1998
- Cartesian3 . multiplyByScalar ( b1 , coords . y , b1 ) ;
1999
- Cartesian3 . multiplyByScalar ( b2 , coords . z , b2 ) ;
2000
-
2001
- var bitangent = Cartesian3 . add ( b0 , b1 , b0 ) ;
2002
- Cartesian3 . add ( bitangent , b2 , bitangent ) ;
2003
- Cartesian3 . normalize ( bitangent , bitangent ) ;
2004
-
2005
- Cartesian3 . pack ( bitangent , currentAttributes . bitangent . values , insertedIndex * 3 ) ;
2002
+ interpolateAndPackCartesian3 ( i0 , i1 , i2 , coords , bitangents , currentAttributes . bitangent . values , insertedIndex , true ) ;
2006
2003
}
2007
2004
2008
2005
if ( defined ( texCoords ) ) {
2009
- var s0 = Cartesian2 . fromArray ( texCoords , i0 * 2 , s0Scratch ) ;
2010
- var s1 = Cartesian2 . fromArray ( texCoords , i1 * 2 , s1Scratch ) ;
2011
- var s2 = Cartesian2 . fromArray ( texCoords , i2 * 2 , s2Scratch ) ;
2012
-
2013
- Cartesian2 . multiplyByScalar ( s0 , coords . x , s0 ) ;
2014
- Cartesian2 . multiplyByScalar ( s1 , coords . y , s1 ) ;
2015
- Cartesian2 . multiplyByScalar ( s2 , coords . z , s2 ) ;
2006
+ interpolateAndPackCartesian2 ( i0 , i1 , i2 , coords , texCoords , currentAttributes . st . values , insertedIndex ) ;
2007
+ }
2016
2008
2017
- var texCoord = Cartesian2 . add ( s0 , s1 , s0 ) ;
2018
- Cartesian2 . add ( texCoord , s2 , texCoord ) ;
2009
+ if ( customAttributesLength > 0 ) {
2010
+ for ( var i = 0 ; i < customAttributesLength ; i ++ ) {
2011
+ var attributeName = customAttributeNames [ i ] ;
2012
+ genericInterpolate ( i0 , i1 , i2 , coords , insertedIndex , allAttributes [ attributeName ] , currentAttributes [ attributeName ] ) ;
2013
+ }
2014
+ }
2015
+ }
2019
2016
2020
- Cartesian2 . pack ( texCoord , currentAttributes . st . values , insertedIndex * 2 ) ;
2017
+ var q0Scratch = new Cartesian4 ( ) ;
2018
+ var q1Scratch = new Cartesian4 ( ) ;
2019
+ var q2Scratch = new Cartesian4 ( ) ;
2020
+ function genericInterpolate ( i0 , i1 , i2 , coords , insertedIndex , sourceAttribute , currentAttribute ) {
2021
+ var componentsPerAttribute = sourceAttribute . componentsPerAttribute ;
2022
+ var sourceValues = sourceAttribute . values ;
2023
+ var currentValues = currentAttribute . values ;
2024
+ switch ( componentsPerAttribute ) {
2025
+ case 4 :
2026
+ var q0 = Cartesian4 . fromArray ( sourceValues , i0 * 4 , q0Scratch ) ;
2027
+ var q1 = Cartesian4 . fromArray ( sourceValues , i1 * 4 , q1Scratch ) ;
2028
+ var q2 = Cartesian4 . fromArray ( sourceValues , i2 * 4 , q2Scratch ) ;
2029
+
2030
+ Cartesian4 . multiplyByScalar ( q0 , coords . x , q0 ) ;
2031
+ Cartesian4 . multiplyByScalar ( q1 , coords . y , q1 ) ;
2032
+ Cartesian4 . multiplyByScalar ( q2 , coords . z , q2 ) ;
2033
+
2034
+ var value = Cartesian4 . add ( q0 , q1 , q0 ) ;
2035
+ Cartesian4 . add ( value , q2 , value ) ;
2036
+
2037
+ Cartesian4 . pack ( value , currentValues , insertedIndex * 4 ) ;
2038
+ break ;
2039
+ case 3 :
2040
+ interpolateAndPackCartesian3 ( i0 , i1 , i2 , coords , sourceValues , currentValues , insertedIndex , false ) ;
2041
+ break ;
2042
+ case 2 :
2043
+ interpolateAndPackCartesian2 ( i0 , i1 , i2 , coords , sourceValues , currentValues , insertedIndex ) ;
2044
+ break ;
2045
+ default :
2046
+ currentValues [ insertedIndex ] = sourceValues [ i0 ] * coords . x + sourceValues [ i1 ] * coords . y + sourceValues [ i2 ] * coords . z ;
2021
2047
}
2022
2048
}
2023
2049
@@ -2044,6 +2070,14 @@ define([
2044
2070
return insertIndex ;
2045
2071
}
2046
2072
2073
+ var NAMED_ATTRIBUTES = {
2074
+ position : true ,
2075
+ normal : true ,
2076
+ bitangent : true ,
2077
+ tangent : true ,
2078
+ st : true ,
2079
+ extrudeDirection : true
2080
+ } ;
2047
2081
function splitLongitudeTriangles ( instance ) {
2048
2082
var geometry = instance . geometry ;
2049
2083
var attributes = geometry . attributes ;
@@ -2055,6 +2089,16 @@ define([
2055
2089
var extrudeDirections = ( defined ( attributes . extrudeDirection ) ) ? attributes . extrudeDirection . values : undefined ;
2056
2090
var indices = geometry . indices ;
2057
2091
2092
+ var customAttributeNames = [ ] ;
2093
+ for ( var attributeName in attributes ) {
2094
+ if ( attributes . hasOwnProperty ( attributeName ) ) {
2095
+ if ( ! NAMED_ATTRIBUTES [ attributeName ] && defined ( attributes [ attributeName ] ) ) {
2096
+ customAttributeNames . push ( attributeName ) ;
2097
+ }
2098
+ }
2099
+ }
2100
+ var customAttributesLength = customAttributeNames . length ;
2101
+
2058
2102
var eastGeometry = copyGeometryForSplit ( geometry ) ;
2059
2103
var westGeometry = copyGeometryForSplit ( geometry ) ;
2060
2104
@@ -2106,7 +2150,7 @@ define([
2106
2150
}
2107
2151
2108
2152
insertedIndex = insertSplitPoint ( currentAttributes , currentIndices , currentIndexMap , indices , resultIndex < 3 ? i + resultIndex : - 1 , point ) ;
2109
- computeTriangleAttributes ( i0 , i1 , i2 , point , positions , normals , tangents , bitangents , texCoords , extrudeDirections , currentAttributes , insertedIndex ) ;
2153
+ computeTriangleAttributes ( i0 , i1 , i2 , point , positions , normals , tangents , bitangents , texCoords , extrudeDirections , currentAttributes , customAttributeNames , customAttributesLength , attributes , insertedIndex ) ;
2110
2154
}
2111
2155
} else {
2112
2156
if ( defined ( result ) ) {
@@ -2126,13 +2170,13 @@ define([
2126
2170
}
2127
2171
2128
2172
insertedIndex = insertSplitPoint ( currentAttributes , currentIndices , currentIndexMap , indices , i , p0 ) ;
2129
- computeTriangleAttributes ( i0 , i1 , i2 , p0 , positions , normals , tangents , bitangents , texCoords , extrudeDirections , currentAttributes , insertedIndex ) ;
2173
+ computeTriangleAttributes ( i0 , i1 , i2 , p0 , positions , normals , tangents , bitangents , texCoords , extrudeDirections , currentAttributes , customAttributeNames , customAttributesLength , attributes , insertedIndex ) ;
2130
2174
2131
2175
insertedIndex = insertSplitPoint ( currentAttributes , currentIndices , currentIndexMap , indices , i + 1 , p1 ) ;
2132
- computeTriangleAttributes ( i0 , i1 , i2 , p1 , positions , normals , tangents , bitangents , texCoords , extrudeDirections , currentAttributes , insertedIndex ) ;
2176
+ computeTriangleAttributes ( i0 , i1 , i2 , p1 , positions , normals , tangents , bitangents , texCoords , extrudeDirections , currentAttributes , customAttributeNames , customAttributesLength , attributes , insertedIndex ) ;
2133
2177
2134
2178
insertedIndex = insertSplitPoint ( currentAttributes , currentIndices , currentIndexMap , indices , i + 2 , p2 ) ;
2135
- computeTriangleAttributes ( i0 , i1 , i2 , p2 , positions , normals , tangents , bitangents , texCoords , extrudeDirections , currentAttributes , insertedIndex ) ;
2179
+ computeTriangleAttributes ( i0 , i1 , i2 , p2 , positions , normals , tangents , bitangents , texCoords , extrudeDirections , currentAttributes , customAttributeNames , customAttributesLength , attributes , insertedIndex ) ;
2136
2180
}
2137
2181
}
2138
2182
0 commit comments